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;
161 *(void **)this = null;
165 virtual IteratorPointer Find(D value)
168 Class Dclass = class(D);
169 if((Dclass.type == systemClass || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass))
171 for(i = GetFirst(); i; i = GetNext(i))
174 int result = ((int (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnCompare])(Dclass, &value,&data);
181 for(i = GetFirst(); i; i = GetNext(i))
184 int result = ((int (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnCompare])(Dclass, (void *)value, (void *)data);
192 virtual void FreeIterator(IteratorPointer it);
194 virtual int GetCount()
198 for(i = GetFirst(); i; i = GetNext(i)) count++;
205 while(i = GetFirst())
209 virtual void Delete(IteratorPointer i)
216 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
220 char itemString[4096];//1024];
223 tempString[0] = '\0';
224 for(i = GetFirst(); i; i = GetNext(i))
226 Class Dclass = class(D);
230 itemString[0] = '\0';
232 result = ((char *(*)(void *, void *, char *, void *, bool *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnGetString])(Dclass,
233 (Dclass.type == systemClass || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)data, itemString, null, null);
234 if(!first) strcat(tempString, ", ");
236 strcat(tempString, result);
247 IteratorPointer i = Find(d);
256 void OnSerialize(IOChannel channel)
258 uint count = GetCount();
260 Class Dclass = class(D);
263 for(i = GetFirst(); i; i = GetNext(i))
266 Dclass._vTbl[__ecereVMethodID_class_OnSerialize](Dclass,
267 (Dclass.type == systemClass || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)data, channel);
271 void OnUnserialize(IOChannel channel)
273 Container container = eInstance_New(_class.fullName);
275 Class Dclass = class(D);
278 for(c = 0; c < count; c++)
281 Dclass._vTbl[__ecereVMethodID_class_OnUnserialize](Dclass, &data, channel);