source: cpp/frams/vm/classes/collectionobj.h @ 757

Last change on this file since 757 was 746, checked in by Maciej Komosinski, 7 years ago

Code formatting

  • Property svn:eol-style set to native
File size: 3.3 KB
Line 
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 */
14class VectorObject : public DestrBase
15{
16public:
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);
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_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);
43#undef STATRICKCLASS
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); }
50
51        static VectorObject* fromObject(const ExtObject& o, bool warn = true);
52};
53
54/** object collection, indexed by name */
55class DictionaryObject : public DestrBase
56{
57public:
58        HashTable hash;
59        HashEntryIterator it;
60        int it_index;
61
62        void clear();
63        HashEntryIterator* getIndexIterator(int i);
64
65        static Param par;
66        DictionaryObject() :it(hash), it_index(-1) {}
67        ~DictionaryObject() { clear(); }
68        static Param& getStaticParam() { return par; }
69#define STATRICKCLASS DictionaryObject
70        PARAMPROCDEF(p_clear) { clear(); }
71        PARAMGETDEF(size) { arg1->setInt(hash.getSize()); }
72        PARAMPROCDEF(p_remove);
73        PARAMPROCDEF(p_get);
74        PARAMPROCDEF(p_getKey);
75        PARAMPROCDEF(p_set);
76        PARAMPROCDEF(p_find);
77        PARAMGETDEF(toString);
78        PARAMPROCDEF(p_clone);
79        PARAMPROCDEF(p_assign);
80#undef STATRICKCLASS
81        ExtValue get(SString key);
82        ExtValue get(int index);
83        ExtValue set(SString key, ExtValue new_value);
84        void copyFrom(DictionaryObject *other);
85        SString serialize(SerializationFormat format) const;
86        static void p_new(void*, ExtValue*args, ExtValue*ret)
87        {
88                ret->setObject(ExtObject(&par, new DictionaryObject));
89        }
90        static DictionaryObject* fromObject(const ExtObject& v, bool warn = true);
91        ExtObject makeObject() { return ExtObject(&par, this); }
92};
93
94class VectorIterator : public DestrBase
95{
96public:
97        VectorObject *vec;
98        int pos;
99        VectorIterator(VectorObject* v);
100        ~VectorIterator();
101#define STATRICKCLASS VectorIterator
102        PARAMGETDEF(next);
103        PARAMGETDEF(value);
104#undef STATRICKCLASS
105        static ExtObject makeFrom(VectorObject *v);
106};
107
108#endif
Note: See TracBrowser for help on using the repository browser.