public import "ecere" import "ArrayUtilities" private: define array = ((ArrayImpl)this).a; class ArrayImpl { uint _size; uint _count; uint _factor; Class type; byte * a; }; public class RedjArray { uint _size; uint _count; uint _factor; ~RedjArray() { delete array; } //virtual void FreeItem(void *); public: Class type; property uint count { set { if(value != _count) { int newsize = (value / _factor + 1) * _factor; if(newsize != _size) size = value ? newsize : 0; _count = value; } } get { return _count; } } property uint size { set { if(value != _size) { if(array) { if(value) array = renew array byte[value * sizeoftype]; else delete array; } else if(value) array = new byte[value * sizeoftype]; _size = value; } } get { return _size; } } property uint growingFactor { set { _factor = value; } get { return _factor; } } property void * data { set { memcpy(array, value, _size * sizeoftype); } } void Append(int n) { count += n; } void Insert(uint position, int n) { Append(n); if(position < _count - 1) MoveBytes(array + (position + n) * sizeoftype, array + position * sizeoftype, (_count - position - n) * sizeoftype); } void Trim(int n) { count -= n; } void Remove(uint position, int n) { if(position + n - 1 < _count - 1) MoveBytes(array + position * sizeoftype, array + (position + n) * sizeoftype, (_count - position - n) * sizeoftype); Trim(n); } }; public class IntArray : RedjArray { type = class(int); public: int * const _; uint * Add(int item) { uint pos = _count; Append(1); _[pos] = item; return &_[pos]; } uint * AddBefore(uint position, int item) { Insert(position, 1); _[position] = item; return &_[position]; } } public class UintArray : RedjArray { type = class(uint); public: uint * const _; uint * Add(uint item) { uint pos = _count; Append(1); _[pos] = item; return &_[pos]; } uint * AddBefore(uint position, uint item) { Insert(position, 1); _[position] = item; return &_[position]; } } public class StringArray : RedjArray { type = class(String); public: String * const _; String * Add(String item) { uint pos = _count; Append(1); _[pos] = item; return &_[pos]; } String * AddBefore(uint position, String item) { Insert(position, 1); _[position] = item; return &_[position]; } void Clear() { int c; for(c = 0; c < _count; c++) delete _[c]; } }