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

Last change on this file since 1319 was 792, checked in by Maciej Komosinski, 6 years ago

Code formatting

  • Property svn:eol-style set to native
File size: 3.0 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#ifdef _MSC_VER
18#pragma warning(push)
19#pragma warning(disable: 4200) //Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
20#endif
21        ExtValue fields[0];
22#ifdef _MSC_VER
23#pragma warning(pop)
24#endif
25        ParamObject() { numfields = 0; }
26        ~ParamObject();
27
28        void* operator new(size_t s, int numfields){ return ::operator new(s + sizeof(ExtValue)*numfields); }
29        void* operator new(size_t s){ return ::operator new(s); }
30        void operator delete(void* ptr, int numfields) { ::operator delete(ptr); }
31        void operator delete(void* ptr) { ::operator delete(ptr); }
32        ParamObject *clone();
33        static void p_new(void* obj, ExtValue *args, ExtValue *ret);
34
35        void operator=(const ParamObject& src);
36
37        static int firstFieldOffset();
38
39        /** make a ParamEntry* array for use with Param object.
40                offsets in the array are calculated for the ExtObject array as the target.
41                valid array can be created with makeObject().
42                sample code:
43                @code
44                ParamInterface *pi=...; // any param interface
45                ParamEntry *tab=ParamObject::makeParamTab(pi);
46                void* obj=ParamObject::makeObject(tab);
47                void* obj2=ParamObject::makeObject(tab);
48                Param par(tab,obj);
49                par.set(...), par.get(...), par.load(...), par.saveSingle/MultiLine(...);
50                par.select(obj);
51                par.select(obj2);
52                ParamObject::freeObject(obj);
53                ParamObject::freeObject(obj2);
54                */
55        static ParamEntry* makeParamTab(ParamInterface *pi, bool stripgroups = 0, bool stripproc = 0, int firstprop = 0, int maxprops = 9999, bool dupentries = false, int flagsexclude_data = 0, int flagsexclude_tab = 0, bool addnew = false, const char* rename = NULL, bool readonly_into_userreadonly = false);
56
57        /** deallocate paramtab obtained from makeParamTab() */
58        static void freeParamTab(ParamEntry *pe);
59
60        static void setParamTabText(ParamEntry *pe, const char* &ptr, const char* txt);
61        static bool paramTabAllocatedString(ParamEntry *pe);
62        static bool paramTabEqual(ParamEntry *pe1, ParamEntry *pe2);
63
64        /** @return the object, suitable for Param.select(...).
65                @return NULL if 'pi' has no usable properties */
66        static ParamObject* makeObject(ParamEntry *tab);
67
68        /** copy data from src to dst (compatibility with older implementation), same as operator=  */
69        static void copyObject(void* dst, void* src);
70
71        /** duplicate object (compatibility with older implementation), same as clone()  */
72        static void* dupObject(void* obj);
73
74        /** delete all data in the array and deallocate it (compatibility with older implementation), same as delete */
75        static void freeObject(void* obj);
76};
77
78class ParamTabOwner
79{
80public:
81        ParamEntry *pe;
82        ParamTabOwner(ParamEntry *_pe) :pe(_pe) {}
83        ~ParamTabOwner() { ParamObject::freeParamTab(pe); }
84};
85
86#endif
Note: See TracBrowser for help on using the repository browser.