1 | // This file is a part of the Framsticks GDK library.
|
---|
2 | // Copyright (C) 2002-2011 Szymon Ulatowski. See LICENSE.txt for details.
|
---|
3 | // Refer to http://www.framsticks.com/ for further information.
|
---|
4 |
|
---|
5 | #ifndef _COLLECTIONOBJ_H_
|
---|
6 | #define _COLLECTIONOBJ_H_
|
---|
7 |
|
---|
8 | #include "param.h"
|
---|
9 | #include "extvalue.h"
|
---|
10 | #include "hashtable.h"
|
---|
11 | #include "3d.h"
|
---|
12 |
|
---|
13 | /** object collection, indexed by int */
|
---|
14 | class VectorObject: public DestrBase
|
---|
15 | {
|
---|
16 | public:
|
---|
17 | SList data;
|
---|
18 | int readonly:1, owndata:1;
|
---|
19 | void clear();
|
---|
20 | ExtValue *get(int i) {return (ExtValue*)data.get(i);}
|
---|
21 | void set(int i,const ExtValue& val);
|
---|
22 |
|
---|
23 | static Param par;
|
---|
24 | VectorObject(Pt3D& pt);
|
---|
25 | VectorObject():readonly(0),owndata(1) {}
|
---|
26 | ~VectorObject() {clear();}
|
---|
27 | #define STATRICKCLASS VectorObject
|
---|
28 | PARAMPROCDEF(p_clear) {if (readonly) return; clear();}
|
---|
29 | PARAMGETDEF(size) {arg1->setInt(data.size());}
|
---|
30 | PARAMGETDEF(avg);
|
---|
31 | PARAMGETDEF(stdev);
|
---|
32 | PARAMPROCDEF(p_remove);
|
---|
33 | PARAMPROCDEF(p_get);
|
---|
34 | PARAMPROCDEF(p_find);
|
---|
35 | PARAMPROCDEF(p_set) {if (!readonly) set(arg1[1].getInt(),arg1[0]);}
|
---|
36 | PARAMPROCDEF(p_add) {if (readonly) return; data+=new ExtValue(arg1[0]);arg2->setInt(data.size()-1);}
|
---|
37 | PARAMGETDEF(toString);
|
---|
38 | #undef STATRICKCLASS
|
---|
39 | static void p_new(void*,ExtValue*args,ExtValue*ret)
|
---|
40 | {ret->setObject(ExtObject(&par,new VectorObject));}
|
---|
41 |
|
---|
42 | ExtObject makeObject()
|
---|
43 | {return ExtObject(&par,this);}
|
---|
44 | };
|
---|
45 |
|
---|
46 | /** object collection, indexed by name */
|
---|
47 | class DictionaryObject: public DestrBase
|
---|
48 | {
|
---|
49 | public:
|
---|
50 | HashTable hash;
|
---|
51 | HashEntryIterator it;
|
---|
52 | int it_index;
|
---|
53 |
|
---|
54 | void clear();
|
---|
55 | HashEntryIterator* getIndexIterator(int i);
|
---|
56 |
|
---|
57 | static Param par;
|
---|
58 | DictionaryObject():it_index(-1),it(hash) {}
|
---|
59 | ~DictionaryObject() {clear();}
|
---|
60 | #define STATRICKCLASS DictionaryObject
|
---|
61 | PARAMPROCDEF(p_clear) {clear();}
|
---|
62 | PARAMGETDEF(size) {arg1->setInt(hash.getSize());}
|
---|
63 | PARAMPROCDEF(p_remove);
|
---|
64 | PARAMPROCDEF(p_get);
|
---|
65 | PARAMPROCDEF(p_getKey);
|
---|
66 | PARAMPROCDEF(p_set);
|
---|
67 | PARAMPROCDEF(p_find);
|
---|
68 | PARAMGETDEF(toString);
|
---|
69 | #undef STATRICKCLASS
|
---|
70 | static void p_new(void*,ExtValue*args,ExtValue*ret)
|
---|
71 | {ret->setObject(ExtObject(&par,new DictionaryObject));} //NOWY KANDYDAT NA BUGA ROKU!!!
|
---|
72 | };
|
---|
73 |
|
---|
74 | #endif
|
---|