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