1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #ifndef _COLLECTIONOBJ_H_ |
---|
6 | #define _COLLECTIONOBJ_H_ |
---|
7 | |
---|
8 | #include <frams/param/param.h> |
---|
9 | #include <frams/util/extvalue.h> |
---|
10 | #include <frams/util/hashtable.h> |
---|
11 | #include <frams/util/3d.h> |
---|
12 | |
---|
13 | /** object collection, indexed by int */ |
---|
14 | class VectorObject: public DestrBase |
---|
15 | { |
---|
16 | public: |
---|
17 | SList data; |
---|
18 | unsigned int readonly:1, owndata:1; |
---|
19 | void clear(); |
---|
20 | ExtValue *get(int i) {return (ExtValue*)data.get(i);} |
---|
21 | void set_or_insert(int i,const ExtValue& val,bool insert); |
---|
22 | |
---|
23 | static Param par; |
---|
24 | VectorObject(Pt3D& pt); |
---|
25 | VectorObject():readonly(0),owndata(1) {} |
---|
26 | ~VectorObject() {clear();} |
---|
27 | static Param& getStaticParam() {return par;} |
---|
28 | #define STATRICKCLASS VectorObject |
---|
29 | PARAMPROCDEF(p_clear) {if (readonly) return; clear();} |
---|
30 | PARAMGETDEF(size) {arg1->setInt(data.size());} |
---|
31 | PARAMGETDEF(avg); |
---|
32 | PARAMGETDEF(stdev); |
---|
33 | PARAMGETDEF(iterator); |
---|
34 | PARAMPROCDEF(p_remove); |
---|
35 | PARAMPROCDEF(p_get); |
---|
36 | PARAMPROCDEF(p_find); |
---|
37 | PARAMPROCDEF(p_set) {if (!readonly) set_or_insert(arg1[1].getInt(),arg1[0],false);} |
---|
38 | PARAMPROCDEF(p_add) {if (readonly) return; /*ExtValue tmp; get_toString(&tmp); printf("%s += %s",(const char*)tmp.getString(),(const char*)arg1[0].getString());*/ data+=new ExtValue(arg1[0]); /*get_toString(&tmp); printf(" -> %s\n",(const char*)tmp.getString());*/ arg2->setInt(data.size()-1);} |
---|
39 | PARAMPROCDEF(p_insert) {if (!readonly) set_or_insert(arg1[1].getInt(),arg1[0],true);} |
---|
40 | PARAMGETDEF(toString); |
---|
41 | PARAMPROCDEF(p_sort); |
---|
42 | PARAMPROCDEF(p_clone); |
---|
43 | #undef STATRICKCLASS |
---|
44 | static void p_new(void*,ExtValue*args,ExtValue*ret) |
---|
45 | {ret->setObject(ExtObject(&par,new VectorObject));} |
---|
46 | SString serialize(SerializationFormat format) const; |
---|
47 | ExtObject makeObject() {return ExtObject(&par,this);} |
---|
48 | |
---|
49 | static VectorObject* fromObject(const ExtObject& o, bool warn=true); |
---|
50 | }; |
---|
51 | |
---|
52 | /** object collection, indexed by name */ |
---|
53 | class DictionaryObject: public DestrBase |
---|
54 | { |
---|
55 | public: |
---|
56 | HashTable hash; |
---|
57 | HashEntryIterator it; |
---|
58 | int it_index; |
---|
59 | |
---|
60 | void clear(); |
---|
61 | HashEntryIterator* getIndexIterator(int i); |
---|
62 | |
---|
63 | static Param par; |
---|
64 | DictionaryObject():it(hash),it_index(-1) {} |
---|
65 | ~DictionaryObject() {clear();} |
---|
66 | static Param& getStaticParam() {return par;} |
---|
67 | #define STATRICKCLASS DictionaryObject |
---|
68 | PARAMPROCDEF(p_clear) {clear();} |
---|
69 | PARAMGETDEF(size) {arg1->setInt(hash.getSize());} |
---|
70 | PARAMPROCDEF(p_remove); |
---|
71 | PARAMPROCDEF(p_get); |
---|
72 | PARAMPROCDEF(p_getKey); |
---|
73 | PARAMPROCDEF(p_set); |
---|
74 | PARAMPROCDEF(p_find); |
---|
75 | PARAMGETDEF(toString); |
---|
76 | PARAMPROCDEF(p_clone); |
---|
77 | PARAMPROCDEF(p_assign); |
---|
78 | #undef STATRICKCLASS |
---|
79 | ExtValue get(SString key); |
---|
80 | ExtValue get(int index); |
---|
81 | ExtValue set(SString key,ExtValue new_value); |
---|
82 | void copyFrom(DictionaryObject *other); |
---|
83 | SString serialize(SerializationFormat format) const; |
---|
84 | static void p_new(void*,ExtValue*args,ExtValue*ret) |
---|
85 | {ret->setObject(ExtObject(&par,new DictionaryObject));} |
---|
86 | static DictionaryObject* fromObject(const ExtObject& v, bool warn=true); |
---|
87 | ExtObject makeObject() {return ExtObject(&par,this);} |
---|
88 | }; |
---|
89 | |
---|
90 | class VectorIterator: public DestrBase |
---|
91 | { |
---|
92 | public: |
---|
93 | VectorObject *vec; |
---|
94 | int pos; |
---|
95 | VectorIterator(VectorObject* v); |
---|
96 | ~VectorIterator(); |
---|
97 | #define STATRICKCLASS VectorIterator |
---|
98 | PARAMGETDEF(next); |
---|
99 | PARAMGETDEF(value); |
---|
100 | #undef STATRICKCLASS |
---|
101 | static ExtObject makeFrom(VectorObject *v); |
---|
102 | }; |
---|
103 | |
---|
104 | #endif |
---|