Fixed major issues
[ede] / explorer / src / Structures / ArrayBasic.ec
1 public import "ecere"
2
3 import "ArrayUtilities"
4
5 private:
6
7 define array = ((BasicArrayImpl)this).a;
8
9 class BasicArrayImpl
10 {
11    uint _size;
12    Class type;
13    byte * a;
14 };
15
16 public class BasicArray
17 {
18    uint _size;
19
20    ~BasicArray()
21    {
22       delete array;
23    }
24
25 public:   
26    Class type;
27    property uint size
28    {
29       set
30       {
31          if(value != _size)
32          {
33             if(array)
34             {
35                if(value)
36                   array = renew array byte[value * sizeoftype];
37                else
38                   delete array;
39             }
40             else if(value)
41                array = new byte[value * sizeoftype];
42             _size = value;
43          }
44       }
45       get { return _size; }
46    }
47    property void * data
48    {
49       set
50       {
51          memcpy(array, value, _size * sizeoftype);
52       }
53    }
54    void Append(int n)
55    {
56       size += n;
57    }
58    void Insert(uint position, int n)
59    {
60       Append(n);
61       if(position < _size - 1)
62          MoveBytes(array + (position + n) * sizeoftype, array + position * sizeoftype, (_size - position - n) * sizeoftype);
63    }
64    void Trim(int n)
65    {
66       size -= n;
67    }
68    void Remove(uint position, int n)
69    {
70       if(position + n - 1 < _size - 1)
71          MoveBytes(array + position * sizeoftype, array + (position + n) * sizeoftype, (_size - position - n) * sizeoftype);
72       Trim(n);
73    }
74 };
75
76 public class IntBasicArray : BasicArray
77 {
78    type = class(int);
79 public:
80    int * const _;
81    uint * Add(int item)
82    {
83       uint pos = _size;
84       Append(1);
85       _[pos] = item;
86       return &_[pos];
87    }
88    uint * AddBefore(uint position, int item)
89    {
90       Insert(position, 1);
91       _[position] = item;
92       return &_[position];
93    }
94 }
95
96 public class UintBasicArray : BasicArray
97 {
98    type = class(uint);
99 public:
100    uint * const _;
101    uint * Add(uint item)
102    {
103       uint pos = _size;
104       Append(1);
105       _[pos] = item;
106       return &_[pos];
107    }
108    uint * AddBefore(uint position, uint item)
109    {
110       Insert(position, 1);
111       _[position] = item;
112       return &_[position];
113    }
114 }
115
116 public class StringBasicArray : BasicArray
117 {
118    type = class(String);
119 public:
120    String * const _;
121    String * Add(String item)
122    {
123       uint pos = _size;
124       Append(1);
125       _[pos] = item;
126       return &_[pos];
127    }
128    String * AddBefore(uint position, String item)
129    {
130       Insert(position, 1);
131       _[position] = item;
132       return &_[position];
133    }
134 }