1 | // This file is a part of the Framsticks GDK. |
---|
2 | // Copyright (C) 1999-2014 Maciej Komosinski and 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 <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 | #undef STATRICKCLASS |
---|
41 | static void p_new(void*,ExtValue*args,ExtValue*ret) |
---|
42 | {ret->setObject(ExtObject(&par,new VectorObject));} |
---|
43 | SString serialize() const; |
---|
44 | ExtObject makeObject() {return ExtObject(&par,this);} |
---|
45 | |
---|
46 | static VectorObject* fromObject(const ExtObject& o, bool warn=true); |
---|
47 | }; |
---|
48 | |
---|
49 | /** object collection, indexed by name */ |
---|
50 | class DictionaryObject: public DestrBase |
---|
51 | { |
---|
52 | public: |
---|
53 | HashTable hash; |
---|
54 | HashEntryIterator it; |
---|
55 | int it_index; |
---|
56 | |
---|
57 | void clear(); |
---|
58 | HashEntryIterator* getIndexIterator(int i); |
---|
59 | |
---|
60 | static Param par; |
---|
61 | DictionaryObject():it(hash),it_index(-1) {} |
---|
62 | ~DictionaryObject() {clear();} |
---|
63 | #define STATRICKCLASS DictionaryObject |
---|
64 | PARAMPROCDEF(p_clear) {clear();} |
---|
65 | PARAMGETDEF(size) {arg1->setInt(hash.getSize());} |
---|
66 | PARAMPROCDEF(p_remove); |
---|
67 | PARAMPROCDEF(p_get); |
---|
68 | PARAMPROCDEF(p_getKey); |
---|
69 | PARAMPROCDEF(p_set); |
---|
70 | PARAMPROCDEF(p_find); |
---|
71 | PARAMGETDEF(toString); |
---|
72 | #undef STATRICKCLASS |
---|
73 | SString serialize() const; |
---|
74 | static void p_new(void*,ExtValue*args,ExtValue*ret) |
---|
75 | {ret->setObject(ExtObject(&par,new DictionaryObject));} |
---|
76 | static DictionaryObject* fromObject(const ExtObject& v, bool warn=true); |
---|
77 | ExtObject makeObject() {return ExtObject(&par,this);} |
---|
78 | }; |
---|
79 | |
---|
80 | class VectorIterator: public DestrBase |
---|
81 | { |
---|
82 | public: |
---|
83 | VectorObject *vec; |
---|
84 | int pos; |
---|
85 | VectorIterator(VectorObject* v); |
---|
86 | ~VectorIterator(); |
---|
87 | #define STATRICKCLASS VectorIterator |
---|
88 | PARAMGETDEF(next); |
---|
89 | PARAMGETDEF(value); |
---|
90 | #undef STATRICKCLASS |
---|
91 | static ExtObject makeFrom(VectorObject *v); |
---|
92 | }; |
---|
93 | |
---|
94 | #endif |
---|