ecere/gui/Window: Prevent uninitialized values if base Window methods not overridden...
[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 extern int __ecereVMethodID_class_OnGetString;
12 private:
13
14 public struct BuiltInContainer
15 {
16 public:
17    void * _vTbl;
18    Class _class;
19    int _refCount;
20 public:
21    void * data;
22    int count;
23    Class type;
24
25    property Container { get { return this; } }
26
27    virtual IteratorPointer GetFirst() { return data; }
28    virtual IteratorPointer GetLast()  { return (IteratorPointer)(data ? ((byte *)data + (count * type.typeSize) - 1) : null); }
29    virtual IteratorPointer GetPrev(IteratorPointer pointer)
30    {
31       return (IteratorPointer)((pointer && (byte *)pointer > (byte *)data) ?
32          ((byte *)pointer - type.typeSize) : null);
33    }
34    virtual IteratorPointer GetNext(IteratorPointer pointer)
35    {
36       return (IteratorPointer)((pointer && (byte *)pointer < (byte *)data + (count - 1) * type.typeSize) ?
37          ((byte *)pointer + type.typeSize) : null);
38    }
39    virtual uint64 GetData(IteratorPointer pointer)
40    {
41       uint64 * item = (uint64 *)pointer;
42       return ((((type.type == structClass) ? ((uint64)(uintptr)item) :
43             ((type.typeSize == 1) ? *((unsigned char *)item) :
44                ((type.typeSize == 2) ? *((unsigned short *)item) :
45                   ((type.typeSize == 4) ? *((unsigned int *)item) : *((uint64 *)item)))))));
46    }
47    virtual bool SetData(IteratorPointer pointer, uint64 data)
48    {
49       return false;
50    }
51    virtual IteratorPointer GetAtPosition(const uint64 pos, bool create)
52    {
53       return data ? (IteratorPointer)((byte *)data + type.typeSize) : null;
54    }
55    virtual IteratorPointer Insert(IteratorPointer after, uint64 value)
56    {
57       return null;
58    }
59    virtual IteratorPointer Add(uint64 value)
60    {
61       return null;
62    }
63    virtual void Remove(IteratorPointer it)
64    {
65    }
66    virtual void Move(IteratorPointer it, IteratorPointer after)
67    {
68    }
69    virtual void RemoveAll()
70    {
71       IteratorPointer i;
72       for(i = GetFirst(); i; i = GetNext(i))
73          Remove(i);
74    }
75
76    virtual void Copy(Container source)
77    {
78    }
79
80    virtual IteratorPointer Find(uint64 value)
81    {
82       IteratorPointer i;
83       for(i = GetFirst(); i; i = GetNext(i))
84       {
85          uint64 data = GetData(i);
86          Class Dclass = type;
87          int result = ((int (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnCompare])(Dclass,
88             ((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &value : (void *)(uintptr)value,
89             ((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)(uintptr)data);
90          if(!result)
91             return i;
92       }
93       return null;
94    }
95
96    virtual void FreeIterator(IteratorPointer it);
97    virtual int GetCount() { return count; }
98
99    virtual void Free()
100    {
101       IteratorPointer i;
102       for(i = GetFirst(); i; i = GetNext(i))
103          ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, (void *)(uintptr)GetData(i));
104    }
105
106    virtual void Delete(IteratorPointer it) { }
107
108    const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
109    {
110       if(this)
111       {
112          Class Dclass = type;
113          char itemString[4096];
114          bool first = true;
115          byte * data = this.data;
116          int i;
117          tempString[0] = '\0';
118          for(i = 0; i < count; i++)
119          {
120             const char * result;
121             itemString[0] = '\0';
122             result = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnGetString])(
123                Dclass, (type.type == normalClass || type.type == noHeadClass) ? *(void **)data : data, itemString, null, null);
124             if(!first) strcat(tempString, ", ");
125             strcat(tempString, result);
126             first = false;
127             data += Dclass.typeSize;
128          }
129       }
130       else
131          tempString[0] = 0;
132       return tempString;
133    }
134
135    virtual void Sort(bool ascending)
136    {
137
138    }
139 };