3 import "BuiltInContainer"
7 static void UnusedFunction()
12 a.OnGetString(null, null, null);
14 a.OnUnserialize(null);
17 extern int __ecereVMethodID_class_OnCompare;
18 extern int __ecereVMethodID_class_OnGetString;
19 extern int __ecereVMethodID_class_OnSerialize;
20 extern int __ecereVMethodID_class_OnUnserialize;
23 // CAUSES PROBLEM WHEN AFTER
24 public struct Iterator<class T, class IT = int>
26 Container<T, IT> container;
28 IteratorPointer pointer;
33 get { return container.GetData(pointer); }
34 set { container.SetData(pointer, value); }
39 if(pointer && container)
40 pointer = container.GetPrev(pointer);
42 pointer = container.GetLast();
43 return pointer != null;
48 if(pointer && container)
49 pointer = container.GetNext(pointer);
51 pointer = container.GetFirst();
52 return pointer != null;
57 return container.GetData(pointer);
62 return container.SetData(pointer, value);
70 pointer = container.Find(value);
72 return pointer != null;
78 container.Remove(pointer);
85 container.FreeIterator(pointer);
88 bool Index(IT index, bool create)
93 pointer = container.GetAtPosition(index, create);
94 return pointer != null;
100 public class Container<class T, class I = int, class D = T>
104 public property Container<T> copySrc { set { Copy(value); } }
105 property Iterator<T> firstIterator { get { value = { (Container<T>)this, pointer = GetFirst() }; } }
106 property Iterator<T> lastIterator { get { value = { (Container<T>)this, pointer = GetLast() }; } }
108 virtual IteratorPointer GetFirst() { return null; }
109 virtual IteratorPointer GetLast() { return null; }
110 virtual IteratorPointer GetPrev(IteratorPointer pointer) { return null; }
111 virtual IteratorPointer GetNext(IteratorPointer pointer) { return null; }
112 virtual D GetData(IteratorPointer pointer) { return (D)0; }
113 virtual bool SetData(IteratorPointer pointer, D data);
114 virtual IteratorPointer GetAtPosition(I pos, bool create) { return null; }
116 virtual IteratorPointer Insert(IteratorPointer after, T value);
117 virtual IteratorPointer Add(T value);
118 virtual void Remove(IteratorPointer it);
119 virtual void Move(IteratorPointer it, IteratorPointer after);
121 virtual void RemoveAll()
123 IteratorPointer i, next;
124 for(i = GetFirst(), next = i ? GetNext(i) : null; i; i = next, next = i ? GetNext(i) : null)
128 virtual void Copy(Container<T> source)
132 for(i = source.GetFirst(); i; i = source.GetNext(i))
134 D data = source.GetData(i);
135 // WARNING: This doesn't make a new copy of the elements it adds
149 void OnCopy(Container<T> source)
153 // BUG IN this = SYNTAX
154 Container<T> container = eInstance_New(source._class);
155 // See WARNING in Copy()
156 container.Copy(source);
157 //*(void **)this = container;
166 virtual IteratorPointer Find(D value)
169 Class Dclass = class(D);
170 if(((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass))
172 for(i = GetFirst(); i; i = GetNext(i))
175 int result = ((int (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnCompare])(Dclass, &value,&data);
182 for(i = GetFirst(); i; i = GetNext(i))
185 int result = ((int (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnCompare])(Dclass, (void *)value, (void *)data);
193 virtual void FreeIterator(IteratorPointer it);
195 virtual int GetCount()
199 for(i = GetFirst(); i; i = GetNext(i)) count++;
206 while(i = GetFirst())
210 virtual void Delete(IteratorPointer i)
217 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
221 char itemString[4096];//1024];
224 tempString[0] = '\0';
225 for(i = GetFirst(); i; i = GetNext(i))
227 Class Dclass = class(D);
231 itemString[0] = '\0';
233 result = ((char *(*)(void *, void *, char *, void *, bool *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnGetString])(Dclass,
234 ((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)data, itemString, null, null);
235 if(!first) strcat(tempString, ", ");
237 strcat(tempString, result);
248 IteratorPointer i = Find(d);
257 void OnSerialize(IOChannel channel)
259 uint count = GetCount();
261 Class Dclass = class(D);
264 for(i = GetFirst(); i; i = GetNext(i))
267 ((void (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnSerialize])(Dclass,
268 ((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)data, channel);
272 void OnUnserialize(IOChannel channel)
274 Container container = eInstance_New(_class.fullName);
276 Class Dclass = class(D);
280 if(Dclass.type == structClass)
281 data = (D)(new byte[Dclass.structSize]);
282 for(c = 0; c < count; c++)
284 ((void (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnUnserialize])
285 (Dclass, (Dclass.type == structClass) ? (void *)data : &data, channel);
288 if(Dclass.type == structClass)