source: cpp/frams/param/paramobj.h @ 326

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

Unified parsing of ints and floats; hex notation

  • Property svn:eol-style set to native
File size: 2.6 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 _PARAMOBJ_H_
6#define _PARAMOBJ_H_
7
8#include "param.h"
9#include <frams/util/extvalue.h>
10
11class ParamObject : public DestrBase
12{
13        ParamObject(int _numfields, ParamEntry *_tab);
14public:
15        int numfields;
16        Param par;
17        ExtValue fields[0];
18        ParamObject() { numfields = 0; }
19        ~ParamObject();
20
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);
25
26        void operator=(const ParamObject& src);
27
28        static int firstFieldOffset();
29
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);
47
48        /** deallocate paramtab obtained from makeParamTab() */
49        static void freeParamTab(ParamEntry *pe);
50
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);
67};
68
69class ParamTabOwner
70{
71public:
72        ParamEntry *pe;
73        ParamTabOwner(ParamEntry *_pe) :pe(_pe) {}
74        ~ParamTabOwner() { ParamObject::freeParamTab(pe); }
75};
76
77#endif
Note: See TracBrowser for help on using the repository browser.