[286] | 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. |
---|
[109] | 4 | |
---|
| 5 | #ifndef _PARAMOBJ_H_ |
---|
| 6 | #define _PARAMOBJ_H_ |
---|
| 7 | |
---|
| 8 | #include "param.h" |
---|
[326] | 9 | #include <frams/util/extvalue.h> |
---|
[109] | 10 | |
---|
[326] | 11 | class ParamObject : public DestrBase |
---|
[109] | 12 | { |
---|
[326] | 13 | ParamObject(int _numfields, ParamEntry *_tab); |
---|
| 14 | public: |
---|
| 15 | int numfields; |
---|
| 16 | Param par; |
---|
| 17 | ExtValue fields[0]; |
---|
| 18 | ParamObject() { numfields = 0; } |
---|
| 19 | ~ParamObject(); |
---|
[109] | 20 | |
---|
[326] | 21 | void* operator new(size_t s, int numfields){ return ::operator new(s + sizeof(ExtValue)*numfields); } |
---|
| 22 | void* operator new(size_t s){ return ::operator new(s); } |
---|
| 23 | ParamObject *clone(); |
---|
| 24 | static void p_new(void* obj, ExtValue *args, ExtValue *ret); |
---|
[109] | 25 | |
---|
[326] | 26 | void operator=(const ParamObject& src); |
---|
[109] | 27 | |
---|
[326] | 28 | static int firstFieldOffset(); |
---|
[109] | 29 | |
---|
[326] | 30 | /** make a ParamEntry* array for use with Param object. |
---|
| 31 | offsets in the array are calculated for the ExtObject array as the target. |
---|
| 32 | valid array can be created with makeObject(). |
---|
| 33 | sample code: |
---|
| 34 | @code |
---|
| 35 | ParamInterface *pi=...; // any param interface |
---|
| 36 | ParamEntry *tab=ParamObject::makeParamTab(pi); |
---|
| 37 | void* obj=ParamObject::makeObject(tab); |
---|
| 38 | void* obj2=ParamObject::makeObject(tab); |
---|
| 39 | Param par(tab,obj); |
---|
| 40 | par.set(...), par.get(...), par.load(...), par.save(...); |
---|
| 41 | par.select(obj); |
---|
| 42 | par.select(obj2); |
---|
| 43 | ParamObject::freeObject(obj); |
---|
| 44 | ParamObject::freeObject(obj2); |
---|
| 45 | */ |
---|
| 46 | static ParamEntry* makeParamTab(ParamInterface *pi, bool stripgroups = 0, bool stripproc = 0, int firstprop = 0, int maxprops = 9999, bool dupentries = false, int flagsexclude = 0, bool addnew = false, const char* rename = NULL); |
---|
[109] | 47 | |
---|
[326] | 48 | /** deallocate paramtab obtained from makeParamTab() */ |
---|
| 49 | static void freeParamTab(ParamEntry *pe); |
---|
[109] | 50 | |
---|
[326] | 51 | static void setParamTabText(ParamEntry *pe, const char* &ptr, const char* txt); |
---|
| 52 | static bool paramTabAllocatedString(ParamEntry *pe); |
---|
| 53 | static bool paramTabEqual(ParamEntry *pe1, ParamEntry *pe2); |
---|
| 54 | |
---|
| 55 | /** @return the object, suitable for Param.select(...). |
---|
| 56 | @return NULL if 'pi' has no usable properties */ |
---|
| 57 | static ParamObject* makeObject(ParamEntry *tab); |
---|
| 58 | |
---|
| 59 | /** copy data from src to dst (compatibility with older implementation), same as operator= */ |
---|
| 60 | static void copyObject(void* dst, void* src); |
---|
| 61 | |
---|
| 62 | /** duplicate object (compatibility with older implementation), same as clone() */ |
---|
| 63 | static void* dupObject(void* obj); |
---|
| 64 | |
---|
| 65 | /** delete all data in the array and deallocate it (compatibility with older implementation), same as delete */ |
---|
| 66 | static void freeObject(void* obj); |
---|
[109] | 67 | }; |
---|
| 68 | |
---|
[326] | 69 | class ParamTabOwner |
---|
| 70 | { |
---|
| 71 | public: |
---|
| 72 | ParamEntry *pe; |
---|
| 73 | ParamTabOwner(ParamEntry *_pe) :pe(_pe) {} |
---|
| 74 | ~ParamTabOwner() { ParamObject::freeParamTab(pe); } |
---|
| 75 | }; |
---|
| 76 | |
---|
[109] | 77 | #endif |
---|