[286] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
[849] | 2 | // Copyright (C) 1999-2019 Maciej Komosinski and Szymon Ulatowski. |
---|
[286] | 3 | // See LICENSE.txt for details. |
---|
[109] | 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 */ |
---|
[746] | 14 | class VectorObject : public DestrBase |
---|
[109] | 15 | { |
---|
[746] | 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); |
---|
[109] | 22 | |
---|
[746] | 23 | static Param par; |
---|
| 24 | VectorObject(Pt3D& pt); |
---|
| 25 | VectorObject() :readonly(0), owndata(1) {} |
---|
| 26 | ~VectorObject() { clear(); } |
---|
| 27 | static Param& getStaticParam() { return par; } |
---|
[109] | 28 | #define STATRICKCLASS VectorObject |
---|
[746] | 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); |
---|
[109] | 43 | #undef STATRICKCLASS |
---|
[746] | 44 | static void p_new(void*, ExtValue*args, ExtValue*ret) |
---|
| 45 | { |
---|
| 46 | ret->setObject(ExtObject(&par, new VectorObject)); |
---|
| 47 | } |
---|
| 48 | SString serialize(SerializationFormat format) const; |
---|
| 49 | ExtObject makeObject() { return ExtObject(&par, this); } |
---|
[109] | 50 | |
---|
[746] | 51 | static VectorObject* fromObject(const ExtObject& o, bool warn = true); |
---|
[109] | 52 | }; |
---|
| 53 | |
---|
| 54 | /** object collection, indexed by name */ |
---|
[746] | 55 | class DictionaryObject : public DestrBase |
---|
[109] | 56 | { |
---|
[746] | 57 | public: |
---|
| 58 | HashTable hash; |
---|
| 59 | HashEntryIterator it; |
---|
| 60 | int it_index; |
---|
[109] | 61 | |
---|
[746] | 62 | void clear(); |
---|
| 63 | HashEntryIterator* getIndexIterator(int i); |
---|
[109] | 64 | |
---|
[746] | 65 | static Param par; |
---|
| 66 | DictionaryObject() :it(hash), it_index(-1) {} |
---|
| 67 | ~DictionaryObject() { clear(); } |
---|
| 68 | static Param& getStaticParam() { return par; } |
---|
[109] | 69 | #define STATRICKCLASS DictionaryObject |
---|
[746] | 70 | PARAMPROCDEF(p_clear) { clear(); } |
---|
| 71 | PARAMGETDEF(size) { arg1->setInt(hash.getSize()); } |
---|
| 72 | PARAMPROCDEF(p_remove); |
---|
| 73 | PARAMPROCDEF(p_get); |
---|
| 74 | PARAMPROCDEF(p_getKey); |
---|
[849] | 75 | PARAMPROCDEF(p_hasKey); |
---|
[746] | 76 | PARAMPROCDEF(p_set); |
---|
| 77 | PARAMPROCDEF(p_find); |
---|
| 78 | PARAMGETDEF(toString); |
---|
| 79 | PARAMPROCDEF(p_clone); |
---|
| 80 | PARAMPROCDEF(p_assign); |
---|
[868] | 81 | PARAMGETDEF(iterator); |
---|
| 82 | PARAMGETDEF(keys); |
---|
[109] | 83 | #undef STATRICKCLASS |
---|
[746] | 84 | ExtValue get(SString key); |
---|
| 85 | ExtValue get(int index); |
---|
| 86 | ExtValue set(SString key, ExtValue new_value); |
---|
| 87 | void copyFrom(DictionaryObject *other); |
---|
| 88 | SString serialize(SerializationFormat format) const; |
---|
| 89 | static void p_new(void*, ExtValue*args, ExtValue*ret) |
---|
| 90 | { |
---|
| 91 | ret->setObject(ExtObject(&par, new DictionaryObject)); |
---|
| 92 | } |
---|
| 93 | static DictionaryObject* fromObject(const ExtObject& v, bool warn = true); |
---|
| 94 | ExtObject makeObject() { return ExtObject(&par, this); } |
---|
[109] | 95 | }; |
---|
| 96 | |
---|
[746] | 97 | class VectorIterator : public DestrBase |
---|
[109] | 98 | { |
---|
[746] | 99 | public: |
---|
| 100 | VectorObject *vec; |
---|
| 101 | int pos; |
---|
| 102 | VectorIterator(VectorObject* v); |
---|
| 103 | ~VectorIterator(); |
---|
[109] | 104 | #define STATRICKCLASS VectorIterator |
---|
[746] | 105 | PARAMGETDEF(next); |
---|
| 106 | PARAMGETDEF(value); |
---|
[109] | 107 | #undef STATRICKCLASS |
---|
[746] | 108 | static ExtObject makeFrom(VectorObject *v); |
---|
[109] | 109 | }; |
---|
| 110 | |
---|
[868] | 111 | class DictionaryIterator : public DestrBase |
---|
| 112 | { |
---|
| 113 | public: |
---|
| 114 | DictionaryObject *dic; |
---|
| 115 | HashEntryIterator it; |
---|
| 116 | bool initial, keys; |
---|
| 117 | DictionaryIterator(DictionaryObject* d, bool _keys); |
---|
| 118 | ~DictionaryIterator(); |
---|
| 119 | #define STATRICKCLASS DictionaryIterator |
---|
| 120 | PARAMGETDEF(next); |
---|
| 121 | PARAMGETDEF(value); |
---|
| 122 | PARAMGETDEF(iterator); |
---|
| 123 | #undef STATRICKCLASS |
---|
| 124 | static ExtObject makeFrom(DictionaryObject *v, bool _keys = false); |
---|
| 125 | }; |
---|
| 126 | |
---|
[109] | 127 | #endif |
---|