3 import "BuiltInContainer"
7 static __attribute__((unused)) 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);
65 bool Find(const T value)
70 pointer = container.Find(value);
72 return pointer != null;
78 container.Remove(pointer);
85 container.FreeIterator(pointer);
88 bool Index(const IT index, bool create)
92 bool justAdded = false;
94 pointer = container.GetAtPosition(index, create, &justAdded);
95 return !justAdded && pointer != null;
101 public class Container<class T, class I = int, class D = T>
105 public property Container<T> copySrc { set { Copy(value); } }
106 property Iterator<T> firstIterator { get { value = { (Container<T>)this, pointer = GetFirst() }; } }
107 property Iterator<T> lastIterator { get { value = { (Container<T>)this, pointer = GetLast() }; } }
109 virtual IteratorPointer GetFirst() { return null; }
110 virtual IteratorPointer GetLast() { return null; }
111 virtual IteratorPointer GetPrev(IteratorPointer pointer) { return null; }
112 virtual IteratorPointer GetNext(IteratorPointer pointer) { return null; }
113 virtual D GetData(IteratorPointer pointer) { return (D)0; }
114 virtual bool SetData(IteratorPointer pointer, D data);
115 virtual IteratorPointer GetAtPosition(const I pos, bool create, bool * justAdded) { return null; }
117 virtual IteratorPointer Insert(IteratorPointer after, T value);
118 virtual IteratorPointer Add(T value);
119 virtual void Remove(IteratorPointer it);
120 virtual void Move(IteratorPointer it, IteratorPointer after);
122 virtual void RemoveAll()
124 IteratorPointer i, next;
125 for(i = GetFirst(), next = i ? GetNext(i) : null; i; i = next, next = i ? GetNext(i) : null)
129 virtual void Copy(Container<T> source)
133 for(i = source.GetFirst(); i; i = source.GetNext(i))
135 D data = source.GetData(i);
136 // WARNING: This doesn't make a new copy of the elements it adds
150 void OnCopy(Container<T> source)
154 // BUG IN this = SYNTAX
155 Container<T> container = eInstance_New(source._class);
156 // See WARNING in Copy()
157 container.Copy(source);
158 //*(void **)this = container;
167 virtual IteratorPointer Find(const D value)
170 Class Dclass = class(D);
171 if(((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass))
173 for(i = GetFirst(); i; i = GetNext(i))
176 int result = ((int (*)(void *, const void *, const void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnCompare])(Dclass, &value, &data);
183 for(i = GetFirst(); i; i = GetNext(i))
186 int result = ((int (*)(void *, const void *, const void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnCompare])(Dclass, (const void *)(uintptr) value, (const void *)(uintptr) data);
194 virtual void FreeIterator(IteratorPointer it);
196 virtual int GetCount()
200 for(i = GetFirst(); i; i = GetNext(i)) count++;
207 while((i = GetFirst()))
211 virtual void Delete(IteratorPointer i)
218 const char * OnGetString(char * tempString, void * fieldData, bool * needClass)
222 char itemString[4096];//1024];
225 tempString[0] = '\0';
226 for(i = GetFirst(); i; i = GetNext(i))
228 Class Dclass = class(D);
232 itemString[0] = '\0';
234 result = ((const char *(*)(void *, void *, char *, void *, bool *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnGetString])(Dclass,
235 ((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)data, itemString, null, null);
236 if(!first) strcat(tempString, ", ");
238 strcat(tempString, result);
247 void TakeOut(const D d)
249 IteratorPointer i = Find(d);
258 void OnSerialize(IOChannel channel)
260 uint count = GetCount();
262 Class Dclass = class(D);
263 bool isNormalClass = (Dclass.type == normalClass) && Dclass.structSize;
266 for(i = GetFirst(); i; i = GetNext(i))
269 Class Eclass = isNormalClass ? ((Instance)data)._class : Dclass;
270 ((void (*)(void *, void *, void *))(void *)Eclass._vTbl[__ecereVMethodID_class_OnSerialize])(Eclass,
271 ((Dclass.type == systemClass && !Dclass.byValueSystemClass) || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)data, channel);
275 void OnUnserialize(IOChannel channel)
277 Container container = eInstance_New(_class.fullName);
279 Class Dclass = class(D);
281 bool isStruct = Dclass.type == structClass;
285 data = (D)(new byte[Dclass.structSize]);
286 for(c = 0; c < count; c++)
289 memset((char *)data, 0, Dclass.structSize);
292 ((void (*)(void *, void *, void *))(void *)Dclass._vTbl[__ecereVMethodID_class_OnUnserialize])
293 (Dclass, isStruct ? (void *)data : &data, channel);