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

Last change on this file since 438 was 286, checked in by Maciej Komosinski, 10 years ago

Updated headers

  • Property svn:eol-style set to native
File size: 2.7 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);
40#undef STATRICKCLASS
41static void p_new(void*,ExtValue*args,ExtValue*ret)
42        {ret->setObject(ExtObject(&par,new VectorObject));}
43SString serialize() const;
44ExtObject makeObject() {return ExtObject(&par,this);}
45
46static VectorObject* fromObject(const ExtObject& o, bool warn=true);
47};
48
49/** object collection, indexed by name */
50class DictionaryObject: public DestrBase
51{
52  public:
53HashTable hash;
54HashEntryIterator it;
55int it_index;
56
57void clear();
58HashEntryIterator* getIndexIterator(int i);
59
60static Param par;
61DictionaryObject():it(hash),it_index(-1) {}
62~DictionaryObject() {clear();}
63#define STATRICKCLASS DictionaryObject
64PARAMPROCDEF(p_clear) {clear();}
65PARAMGETDEF(size) {arg1->setInt(hash.getSize());}
66PARAMPROCDEF(p_remove);
67PARAMPROCDEF(p_get);
68PARAMPROCDEF(p_getKey);
69PARAMPROCDEF(p_set);
70PARAMPROCDEF(p_find);
71PARAMGETDEF(toString);
72#undef STATRICKCLASS
73SString serialize() const;
74static void p_new(void*,ExtValue*args,ExtValue*ret)
75        {ret->setObject(ExtObject(&par,new DictionaryObject));}
76static DictionaryObject* fromObject(const ExtObject& v, bool warn=true);
77ExtObject makeObject() {return ExtObject(&par,this);}
78};
79
80class VectorIterator: public DestrBase
81{
82  public:
83VectorObject *vec;
84int pos;
85VectorIterator(VectorObject* v);
86~VectorIterator();
87#define STATRICKCLASS VectorIterator
88PARAMGETDEF(next);
89PARAMGETDEF(value);
90#undef STATRICKCLASS
91static ExtObject makeFrom(VectorObject *v);
92};
93
94#endif
Note: See TracBrowser for help on using the repository browser.