3 import "BuiltInContainer"
7 static void UnusedFunction()
12 a.OnGetString(null, null, null);
15 extern int __ecereVMethodID_class_OnCompare;
16 extern int __ecereVMethodID_class_OnGetString;
19 // CAUSES PROBLEM WHEN AFTER
20 public struct Iterator<class T, class IT = int>
22 Container<T, IT> container;
24 IteratorPointer pointer;
29 get { return container.GetData(pointer); }
30 set { container.SetData(pointer, value); }
35 if(pointer && container)
36 pointer = container.GetPrev(pointer);
38 pointer = container.GetLast();
39 return pointer != null;
44 if(pointer && container)
45 pointer = container.GetNext(pointer);
47 pointer = container.GetFirst();
48 return pointer != null;
53 return container.GetData(pointer);
58 return container.SetData(pointer, value);
66 pointer = container.Find(value);
68 return pointer != null;
74 container.Remove(pointer);
81 container.FreeIterator(pointer);
84 bool Index(IT index, bool create)
89 pointer = container.GetAtPosition(index, create);
90 return pointer != null;
96 public class Container<class T, class I = int, class D = T>
100 public property Container<T> copySrc { set { Copy(value); } }
101 property Iterator<T> firstIterator { get { value = { (Container<T>)this, pointer = GetFirst() }; } }
102 property Iterator<T> lastIterator { get { value = { (Container<T>)this, pointer = GetLast() }; } }
104 virtual IteratorPointer GetFirst() { return null; }
105 virtual IteratorPointer GetLast() { return null; }
106 virtual IteratorPointer GetPrev(IteratorPointer pointer) { return null; }
107 virtual IteratorPointer GetNext(IteratorPointer pointer) { return null; }
108 virtual D GetData(IteratorPointer pointer) { return (D)0; }
109 virtual bool SetData(IteratorPointer pointer, D data);
110 virtual IteratorPointer GetAtPosition(I pos, bool create) { return null; }
112 virtual IteratorPointer Insert(IteratorPointer after, T value);
113 virtual IteratorPointer Add(T value);
114 virtual void Remove(IteratorPointer it);
115 virtual void Move(IteratorPointer it, IteratorPointer after);
117 virtual void RemoveAll()
119 IteratorPointer i, next;
120 for(i = GetFirst(), next = i ? GetNext(i) : null; i; i = next, next = i ? GetNext(i) : null)
124 virtual void Copy(Container<T> source)
128 for(i = source.GetFirst(); i; i = source.GetNext(i))
130 D data = source.GetData(i);
131 // WARNING: This doesn't make a new copy of the elements it adds
145 void OnCopy(Container<T> source)
149 // BUG IN this = SYNTAX
150 Container<T> container = eInstance_New(source._class);
151 // See WARNING in Copy()
152 container.Copy(source);
153 *(void **)this = container;
157 *(void **)this = null;
161 virtual IteratorPointer Find(D value)
164 Class Dclass = class(D);
165 if((Dclass.type == systemClass || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass))
167 for(i = GetFirst(); i; i = GetNext(i))
170 int result = Dclass._vTbl[__ecereVMethodID_class_OnCompare](Dclass, &value,&data);
177 for(i = GetFirst(); i; i = GetNext(i))
180 int result = Dclass._vTbl[__ecereVMethodID_class_OnCompare](Dclass, (void *)value, (void *)data);
188 virtual void FreeIterator(IteratorPointer it);
190 virtual int GetCount()
194 for(i = GetFirst(); i; i = GetNext(i)) count++;
201 while(i = GetFirst())
205 virtual void Delete(IteratorPointer i)
212 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
216 char itemString[4096];//1024];
219 tempString[0] = '\0';
220 for(i = GetFirst(); i; i = GetNext(i))
222 Class Dclass = class(D);
226 itemString[0] = '\0';
228 result = (char *)Dclass._vTbl[__ecereVMethodID_class_OnGetString](Dclass,
229 (Dclass.type == systemClass || Dclass.type == bitClass || Dclass.type == enumClass || Dclass.type == unitClass) ? &data : (void *)data,
231 if(!first) strcat(tempString, ", ");
233 strcat(tempString, result);
244 IteratorPointer i = Find(d);