source: cpp/gdk/collectionobj.h @ 104

Last change on this file since 104 was 104, checked in by sz, 11 years ago

introducing object de/serialization - see serialtest.cpp
the core GDK classes can be now used in multiple threads (ifdef MULTITHREADED)

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// This file is a part of the Framsticks GDK library.
2// Copyright (C) 2002-2011  Szymon Ulatowski.  See LICENSE.txt for details.
3// Refer to http://www.framsticks.com/ for further information.
4
5#ifndef _COLLECTIONOBJ_H_
6#define _COLLECTIONOBJ_H_
7
8#include "param.h"
9#include "extvalue.h"
10#include "hashtable.h"
11#include "3d.h"
12
13/** object collection, indexed by int */
14class VectorObject: public DestrBase
15{
16  public:
17SList data;
18int 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);
32PARAMPROCDEF(p_remove);
33PARAMPROCDEF(p_get);
34PARAMPROCDEF(p_find);
35PARAMPROCDEF(p_set) {if (!readonly) set(arg1[1].getInt(),arg1[0]);}
36PARAMPROCDEF(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);}
37PARAMGETDEF(toString);
38#undef STATRICKCLASS
39static void p_new(void*,ExtValue*args,ExtValue*ret)
40        {ret->setObject(ExtObject(&par,new VectorObject));}
41SString serialize() const;
42ExtObject makeObject() {return ExtObject(&par,this);}
43
44static VectorObject* fromObject(const ExtObject& o);
45};
46
47/** object collection, indexed by name */
48class DictionaryObject: public DestrBase
49{
50  public:
51HashTable hash;
52HashEntryIterator it;
53int it_index;
54
55void clear();
56HashEntryIterator* getIndexIterator(int i);
57
58static Param par;
59DictionaryObject():it(hash),it_index(-1) {}
60~DictionaryObject() {clear();}
61#define STATRICKCLASS DictionaryObject
62PARAMPROCDEF(p_clear) {clear();}
63PARAMGETDEF(size) {arg1->setInt(hash.getSize());}
64PARAMPROCDEF(p_remove);
65PARAMPROCDEF(p_get);
66PARAMPROCDEF(p_getKey);
67PARAMPROCDEF(p_set);
68PARAMPROCDEF(p_find);
69PARAMGETDEF(toString);
70#undef STATRICKCLASS
71SString serialize() const;
72static void p_new(void*,ExtValue*args,ExtValue*ret)
73        {ret->setObject(ExtObject(&par,new DictionaryObject));} //NOWY KANDYDAT NA BUGA ROKU!!!
74static DictionaryObject* fromObject(const ExtObject& v);
75ExtObject makeObject() {return ExtObject(&par,this);}
76};
77
78#endif
Note: See TracBrowser for help on using the repository browser.