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

Last change on this file since 569 was 490, checked in by Maciej Komosinski, 9 years ago

Introduced general-use ErrorObject?, fixed enumeration of mixed private/public property lists

  • Property svn:eol-style set to native
File size: 3.1 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{
16  public:
17SList data;
18unsigned int readonly:1, owndata:1;
19void clear();
20ExtValue *get(int i) {return (ExtValue*)data.get(i);}
21void set(int i,const ExtValue& val);
22
23static Param par;
24VectorObject(Pt3D& pt);
25VectorObject():readonly(0),owndata(1) {}
26~VectorObject() {clear();}
27static Param& getStaticParam() {return par;}
28#define STATRICKCLASS VectorObject
29PARAMPROCDEF(p_clear) {if (readonly) return; clear();}
30PARAMGETDEF(size) {arg1->setInt(data.size());}
31PARAMGETDEF(avg);
32PARAMGETDEF(stdev);
33PARAMGETDEF(iterator);
34PARAMPROCDEF(p_remove);
35PARAMPROCDEF(p_get);
36PARAMPROCDEF(p_find);
37PARAMPROCDEF(p_set) {if (!readonly) set(arg1[1].getInt(),arg1[0]);}
38PARAMPROCDEF(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);}
39PARAMGETDEF(toString);
40PARAMPROCDEF(p_sort);
41PARAMPROCDEF(p_clone);
42#undef STATRICKCLASS
43static void p_new(void*,ExtValue*args,ExtValue*ret)
44        {ret->setObject(ExtObject(&par,new VectorObject));}
45SString serialize(SerializationFormat format) const;
46ExtObject makeObject() {return ExtObject(&par,this);}
47
48static VectorObject* fromObject(const ExtObject& o, bool warn=true);
49};
50
51/** object collection, indexed by name */
52class DictionaryObject: public DestrBase
53{
54  public:
55HashTable hash;
56HashEntryIterator it;
57int it_index;
58
59void clear();
60HashEntryIterator* getIndexIterator(int i);
61
62static Param par;
63DictionaryObject():it(hash),it_index(-1) {}
64~DictionaryObject() {clear();}
65static Param& getStaticParam() {return par;}
66#define STATRICKCLASS DictionaryObject
67PARAMPROCDEF(p_clear) {clear();}
68PARAMGETDEF(size) {arg1->setInt(hash.getSize());}
69PARAMPROCDEF(p_remove);
70PARAMPROCDEF(p_get);
71PARAMPROCDEF(p_getKey);
72PARAMPROCDEF(p_set);
73PARAMPROCDEF(p_find);
74PARAMGETDEF(toString);
75PARAMPROCDEF(p_clone);
76PARAMPROCDEF(p_assign);
77#undef STATRICKCLASS
78ExtValue get(SString key);
79ExtValue get(int index);
80ExtValue set(SString key,ExtValue new_value);
81void copyFrom(DictionaryObject *other);
82SString serialize(SerializationFormat format) const;
83static void p_new(void*,ExtValue*args,ExtValue*ret)
84        {ret->setObject(ExtObject(&par,new DictionaryObject));}
85static DictionaryObject* fromObject(const ExtObject& v, bool warn=true);
86ExtObject makeObject() {return ExtObject(&par,this);}
87};
88
89class VectorIterator: public DestrBase
90{
91  public:
92VectorObject *vec;
93int pos;
94VectorIterator(VectorObject* v);
95~VectorIterator();
96#define STATRICKCLASS VectorIterator
97PARAMGETDEF(next);
98PARAMGETDEF(value);
99#undef STATRICKCLASS
100static ExtObject makeFrom(VectorObject *v);
101};
102
103#endif
Note: See TracBrowser for help on using the repository browser.