wip II
[sdk] / ecere / src / com / containers / BuiltInContainer.ec
1 namespace com;
2
3 import "instance"
4 import "Container"
5
6 public class IteratorPointer : struct;
7
8 default:
9 extern int __ecereVMethodID_class_OnCompare;
10 extern int __ecereVMethodID_class_OnFree;
11 private:
12
13 public struct BuiltInContainer
14 {
15 public:
16    void * _vTbl;
17    Class _class;
18    int _refCount;
19 public:
20    void * data;
21    int count;
22    Class type;
23
24    property Container { get { return this; } }
25
26    virtual IteratorPointer GetFirst() { return data; }
27    virtual IteratorPointer GetLast()  { return (IteratorPointer)(data ? ((byte *)data + (count * type.typeSize) - 1) : null); }
28    virtual IteratorPointer GetPrev(IteratorPointer pointer)
29    {
30       return (IteratorPointer)((pointer && (byte *)pointer > (byte *)data) ? 
31          ((byte *)pointer - ((type.type == noHeadClass || type.type == normalClass) ? sizeof(void *) : type.typeSize)) : null);
32    }
33    virtual IteratorPointer GetNext(IteratorPointer pointer)
34    {
35       return (IteratorPointer)((pointer && (byte *)pointer < (byte *)data + (count - 1) * 
36          ((type.type == noHeadClass || type.type == normalClass) ? sizeof(void *) : type.typeSize) ? 
37          ((byte *)pointer + ((type.type == noHeadClass || type.type == normalClass) ? sizeof(void *) : type.typeSize)) : null);
38    }
39    virtual uint64 GetData(IteratorPointer pointer)
40    {
41       uint64 * item = (uint64 *)pointer;
42       return ((((type.type == structClass) ? ((uint64)item) : 
43          (type.type == normalClass || type.type == noHeadClass) ? (uint64)*((void **)item) : 
44             ((type.typeSize == 1) ? *((unsigned char *)item) : 
45                ((type.typeSize == 2) ? *((unsigned short *)item) : 
46                   ((type.typeSize == 4) ? *((unsigned int *)item) : *((uint64 *)item)))))));
47    }
48    virtual bool SetData(IteratorPointer pointer, uint64 data)
49    {
50       return false;
51    }
52    virtual IteratorPointer GetAtPosition(uint64 pos, bool create)
53    {
54       return data ? (IteratorPointer)((byte *)data + 
55          ((type.type == noHeadClass || type.type == normalClass) ? sizeof(void *) : type.typeSize)) : null;
56    }
57    virtual IteratorPointer Insert(IteratorPointer after, uint64 value)
58    {
59       return null;
60    }
61    virtual IteratorPointer Add(uint64 value)
62    {
63       return null;
64    }
65    virtual void Remove(IteratorPointer it)
66    {
67    }
68    virtual void Move(IteratorPointer it, IteratorPointer after)
69    {
70    }
71    virtual void RemoveAll()
72    {
73       IteratorPointer i;
74       for(i = GetFirst(); i; i = GetNext(i))
75          Remove(i);
76    }
77
78    virtual void Copy(Container source)
79    {
80    }
81
82    virtual IteratorPointer Find(uint64 value)
83    {
84       IteratorPointer i;
85       for(i = GetFirst(); i; i = GetNext(i))
86       {
87          uint64 data = GetData(i);
88          Class Dclass = type;
89          int result = ((int (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnCompare])(Dclass, 
90             ((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &value : (void *)value,
91             ((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)data);
92          if(!result)
93             return i;
94       }
95       return null;
96    }
97    
98    virtual void FreeIterator(IteratorPointer it);
99    virtual int GetCount() { return count; }
100
101    virtual void Free()
102    {
103       IteratorPointer i;
104       for(i = GetFirst(); i; i = GetNext(i))
105          ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)GetData(i));
106    }
107
108    virtual void Delete(IteratorPointer it) { }
109 };