Initial Git commit
[ede] / explorer / src / Structures / ArrayNotes.ec
1 //#define ARRAY ((IncrementArrayImpl)this).array
2 //
3 //public import "ecere"
4 //
5 //default:
6 //extern int __ecereVMethodID_class_OnFree;
7 //
8 //private:
9 //
10 //class IncrementArrayImpl
11 //{
12 //   uint count;
13 //   uint size;
14 //   uint increment;
15 //   uint divider;
16 //   Class type;
17 //   byte * array;
18 //};
19 //
20 //default:
21 //extern int __ecereVMethodID_class_OnFree;
22 //
23 //   ~Array()
24 //   {
25 //      // what's up with that?
26 //      //int c;
27 //      //void ** array = (void **)((ArrayImpl)this).array;
28 //      //if(type.type == normalClass || type.type == noHeadClass)
29 //      {
30 //         //for(c = 0; c<size; c++)
31 //            //type._vTbl[__ecereVMethodID_class_OnFree](type, array[c]);
32 //      }
33 //      // TODO: Call OnFree for structClass
34 //      delete ARRAY;
35 //   }
36 //
37 //            // the following after the renew in Array's size property
38 //            if(value > size)
39 //               memset(array + size * GetTypeSize(), 0, (value - size) * GetTypeSize());
40 //
41 //      // the following after the MoveBytes in Array's Remove function
42 //      FillBytes(incarray + count, 0, GetTypeSize()); // why set to 0   and is it even correct code
43 //
44
45 /*
46 class DerivedArray : Array
47 {
48    uint dummy;
49
50 }
51 class IntDerivedArray : DerivedArray
52 {
53    type = class(int);
54    offset = offsetof(_);
55 public:
56    int * const _;
57 }
58 */
59
60 /*
61 #define ARRAY ((IndexedIncrementArrayImpl)this).array
62
63 public import "ecere"
64
65 default:
66 extern int __ecereVMethodID_class_OnFree;
67
68 private:
69
70 public class IndexedIncrementArray : public IncrementArray
71 {
72    UintIncrementArray index { };
73
74 public:   
75    property uint count
76    {
77       set
78       {
79          if(value != _count)
80          {
81             if((value / _increment + 1) * _increment != _size)
82                size = value ? (value / _increment + 1) * _increment : 0;
83             index.count = _count;
84             _count = value;
85          }
86       }
87       get { return _count; }
88    }
89    property uint size
90    {
91       set
92       {
93          if(value != _size)
94          {
95             if(ARRAY)
96             {
97                ARRAY = renew ARRAY byte[value * GetTypeSize()];
98                if(value > _size)
99                   // this is initializing to 0, right?, do I want that? 
100                   // why memset instead of FillBytes? 
101                   memset(ARRAY + _size * GetTypeSize(), 0, (value - _size) * GetTypeSize());
102             }
103             else if(value)
104                ARRAY = new byte[value * GetTypeSize()];
105             index.size = _size;
106             _size = value;
107          }
108       }
109       get { return _size; }
110    }
111    property uint increment { set { _increment = value; } get { return _increment; } }
112    property void * data
113    {
114       set
115       {
116          memcpy(ARRAY, value, _size * GetTypeSize());
117       }
118    }
119    void Append(int n)
120    {
121       count += n;
122    }
123    void Insert(uint position, int n)
124    {
125       Append(n);
126       if(position < _count - 1)
127          MoveBytes(ARRAY + position + n, ARRAY + position, (_count - position - n) * GetTypeSize());
128    }
129    void Trim(int n)
130    {
131       count -= n;
132    }
133    void Remove(uint position, int n)
134    {
135       if(position + n - 1 < _count - 1)
136          MoveBytes(ARRAY + position, ARRAY + position + n, (_count - position - n) * GetTypeSize());
137       //FillBytes(ARRAY + _count, 0, GetTypeSize()); // why set to 0   and is it even correct code
138       Trim(n);
139    }
140 };
141
142 class IntIndexedIncrementArray : IndexedIncrementArray
143 {
144    type = class(int);
145 public:
146    int * const _;
147 }
148
149 class UintIndexedIncrementArray : IndexedIncrementArray
150 {
151    type = class(uint);
152 public:
153    uint * const _;
154    
155    uint * Add(int item)
156    {
157       uint pos = _count;
158       Append(1);
159       _[pos] = item;
160       return &_[pos];
161    }
162    uint * AddBefore(uint position, int item)
163    {
164       Insert(position, 1);
165       _[position] = item;
166       return &_[position];
167    }
168 }
169
170 class StringIndexedIncrementArray : IndexedIncrementArray
171 {
172    type = class(String);
173 public:
174    String * const _;
175
176    String * Add(String item)
177    {
178       uint pos = _count;
179       Append(1);
180       _[pos] = item;
181       return &_[pos];
182    }
183    String * AddBefore(uint position, String item)
184    {
185       Insert(position, 1);
186       _[position] = item;
187       return &_[position];
188    }
189
190 }
191 */
192
193 /*
194 class UIntBIArray : IncArray
195 {
196    type = class(uint);
197 public:
198    uint * const _;
199    uint * Add(uint item)
200    {
201       uint pos = _count;
202       Append(1);
203       _[pos] = item;
204       return &_[pos];
205    }
206    uint * AddBefore(uint position, uint item)
207    {
208       Insert(position, 1);
209       _[position] = item;
210       return &_[position];
211    }
212 }
213 */
214
215 /*
216 class UintSortArray : IncArray
217 {
218    type = class(uint);
219 public:
220    uint * const _;
221    uint * Add(uint item)
222    {
223       uint pos = _count;
224       Append(1);
225       _[pos] = item;
226       return &_[pos];
227    }
228    uint * AddBefore(uint position, uint item)
229    {
230       Insert(position, 1);
231       _[position] = item;
232       return &_[position];
233    }
234 }
235
236 public class SortArray : IncArray
237 {
238    UintIncArray index;
239    
240    
241 }
242
243 define array = ((SortArrayImpl)this).a;
244
245 class SortArrayImpl
246 {
247    uint _size;
248    uint _count;
249    uint _increment;
250    Class type;
251    byte * a;
252 };
253
254 public class SortArray
255 {
256    uint _size;
257    uint _count;
258    uint _increment;
259
260    ~SortArray()
261    {
262       delete array;
263    }
264
265 public:   
266    Class type;
267    property uint count
268    {
269       set
270       {
271          if(value != _count)
272          {
273             int newsize = (value / _increment + 1) * _increment;
274             if(newsize != _size)
275                size = value ? newsize : 0;
276             _count = value;
277          }
278       }
279       get { return _count; }
280    }
281    property uint size
282    {
283       set
284       {
285          if(value != _size)
286          {
287             if(array)
288             {
289                if(value)
290                   array = renew array byte[value * sizeoftype];
291                else
292                   delete array;
293             }
294             else if(value)
295                array = new byte[value * sizeoftype];
296             _size = value;
297          }
298       }
299       get { return _size; }
300    }
301    property uint increment { set { _increment = value; } get { return _increment; } }
302    property void * data
303    {
304       set
305       {
306          memcpy(array, value, _size * sizeoftype);
307       }
308    }
309    void Append(int n)
310    {
311       count += n;
312    }
313    void Insert(uint position, int n)
314    {
315       Append(n);
316       if(position < _count - 1)
317          MoveBytes(array + (position + n) * sizeoftype, array + position * sizeoftype, (_count - position - n) * sizeoftype);
318    }
319    void Trim(int n)
320    {
321       count -= n;
322    }
323    void Remove(uint position, int n)
324    {
325       if(position + n - 1 < _count - 1)
326          MoveBytes(array + position * sizeoftype, array + (position + n) * sizeoftype, (_count - position - n) * sizeoftype);
327       Trim(n);
328    }
329 };
330 */
331
332    /*int CompareInt(uint a, uint b)
333    {
334       return (a > b) ? 1 : ((a < b) ? - 1 : 0);
335    }*/
336
337    /*int CompareString(char * a, char * b)
338    {
339       return (a && b) ? Compare(a, b) : -1;
340    }*/
341
342    //void ::FreeString(char * string)
343