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

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

Accessing const objects, short -> paInt, less critical messages when not necessary, accessing dictionaries with "->"

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