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