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

Last change on this file since 646 was 642, checked in by Maciej Komosinski, 8 years ago

Implemented insert() in FramScript? Vector class

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