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(int i,const ExtValue& val); |
---|
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(arg1[1].getInt(),arg1[0]);} |
---|
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 | PARAMGETDEF(toString); |
---|
40 | PARAMPROCDEF(p_sort); |
---|
41 | PARAMPROCDEF(p_clone); |
---|
42 | #undef STATRICKCLASS |
---|
43 | static void p_new(void*,ExtValue*args,ExtValue*ret) |
---|
44 | {ret->setObject(ExtObject(&par,new VectorObject));} |
---|
45 | SString serialize(SerializationFormat format) const; |
---|
46 | ExtObject makeObject() {return ExtObject(&par,this);} |
---|
47 | |
---|
48 | static VectorObject* fromObject(const ExtObject& o, bool warn=true); |
---|
49 | }; |
---|
50 | |
---|
51 | /** object collection, indexed by name */ |
---|
52 | class DictionaryObject: public DestrBase |
---|
53 | { |
---|
54 | public: |
---|
55 | HashTable hash; |
---|
56 | HashEntryIterator it; |
---|
57 | int it_index; |
---|
58 | |
---|
59 | void clear(); |
---|
60 | HashEntryIterator* getIndexIterator(int i); |
---|
61 | |
---|
62 | static Param par; |
---|
63 | DictionaryObject():it(hash),it_index(-1) {} |
---|
64 | ~DictionaryObject() {clear();} |
---|
65 | static Param& getStaticParam() {return par;} |
---|
66 | #define STATRICKCLASS DictionaryObject |
---|
67 | PARAMPROCDEF(p_clear) {clear();} |
---|
68 | PARAMGETDEF(size) {arg1->setInt(hash.getSize());} |
---|
69 | PARAMPROCDEF(p_remove); |
---|
70 | PARAMPROCDEF(p_get); |
---|
71 | PARAMPROCDEF(p_getKey); |
---|
72 | PARAMPROCDEF(p_set); |
---|
73 | PARAMPROCDEF(p_find); |
---|
74 | PARAMGETDEF(toString); |
---|
75 | PARAMPROCDEF(p_clone); |
---|
76 | PARAMPROCDEF(p_assign); |
---|
77 | #undef STATRICKCLASS |
---|
78 | ExtValue get(SString key); |
---|
79 | ExtValue get(int index); |
---|
80 | ExtValue set(SString key,ExtValue new_value); |
---|
81 | void copyFrom(DictionaryObject *other); |
---|
82 | SString serialize(SerializationFormat format) const; |
---|
83 | static void p_new(void*,ExtValue*args,ExtValue*ret) |
---|
84 | {ret->setObject(ExtObject(&par,new DictionaryObject));} |
---|
85 | static DictionaryObject* fromObject(const ExtObject& v, bool warn=true); |
---|
86 | ExtObject makeObject() {return ExtObject(&par,this);} |
---|
87 | }; |
---|
88 | |
---|
89 | class VectorIterator: public DestrBase |
---|
90 | { |
---|
91 | public: |
---|
92 | VectorObject *vec; |
---|
93 | int pos; |
---|
94 | VectorIterator(VectorObject* v); |
---|
95 | ~VectorIterator(); |
---|
96 | #define STATRICKCLASS VectorIterator |
---|
97 | PARAMGETDEF(next); |
---|
98 | PARAMGETDEF(value); |
---|
99 | #undef STATRICKCLASS |
---|
100 | static ExtObject makeFrom(VectorObject *v); |
---|
101 | }; |
---|
102 | |
---|
103 | #endif |
---|