1 module skia.Common;
2 
3 import std.range;
4 
5 alias IEnumerable(T) = InputRange!(T);
6 
7 T[] ToList(T)(IEnumerable!(T) items) {
8     T[] v;
9 // TODO: Tasks pending completion -@putao at 2021-06-09T10:07:19+08:00
10 // 
11     return v;
12 }
13 
14 interface ICollection(T) :  IEnumerable!T 
15 {
16     // Number of items in the collections.        
17     int Count();
18 
19     bool IsReadOnly();
20 
21     void Add(T item);
22 
23     void Clear();
24 
25     bool Contains(T item);
26             
27     // CopyTo copies a collection into an Array, starting at a particular
28     // index into the array.
29     // 
30     void CopyTo(T[] array, int arrayIndex);
31             
32     //void CopyTo(int sourceIndex, T[] destinationArray, int destinationIndex, int count);
33 
34     bool Remove(T item);
35 }
36 
37 interface IList(T) : ICollection!T {
38     
39     // The Item property provides methods to read and edit entries in the List.
40     T opIndex(int index);
41     T opIndexAssign(T value, int index);
42 
43     // Returns the index of a particular item, if it is in the list.
44     // Returns -1 if the item isn't in the list.
45     int IndexOf(T item);
46 
47     // Inserts value into the list at position index.
48     // index must be non-negative and less than or equal to the 
49     // number of elements in the list.  If index equals the number
50     // of items in the list, then value is appended to the end.
51     void Insert(int index, T item);
52     
53     // Removes the item at position index.
54     T RemoveAt(int index);
55 
56     T[] ToList();
57 }
58 // struct KeyValuePair(TKey, TValue) {
59 //     private TKey key;
60 //     private TValue value;
61 
62 //     this(TKey key, TValue value) {
63 //         this.key = key;
64 //         this.value = value;
65 //     }
66 
67 //     TKey Key() => key;
68 
69 //     TValue Value() => value;
70 
71 //     string ToString() {
72 //         string s = "[";
73 //         if( Key != null) {
74 //             s ~= to!string(Key);
75 //         }
76 //         s ~= ", ";
77 //         if( Value != null) {
78 //             s ~= to!string(Value);
79 //         }
80 //         s ~= "]";
81 //         return s;
82 //     }
83 // }
84 
85 interface IDictionary(TKey, TValue)
86 {
87     // Interfaces are not serializable
88     // The Item property provides methods to read and edit entries 
89     // in the Dictionary.
90     TValue opIndex(TKey key);
91     TValue opIndexAssign(TValue value, TKey key);
92 
93     // Returns a collections of the keys in this dictionary.
94     TKey[] Keys();
95 
96     // Returns a collections of the values in this dictionary.
97     TValue[] Values();
98     // Returns whether this dictionary contains a particular key.
99     //
100     bool ContainsKey(TKey key);
101 
102     // Adds a key-value pair to the dictionary.
103     // 
104     void Add(TKey key, TValue value);
105 
106     // Removes a particular key from the dictionary.
107     //
108     bool Remove(TKey key);
109 
110     bool TryGetValue(TKey key, out TValue value);
111 }