aboutsummaryrefslogtreecommitdiff
path: root/Src/Agave/Config/ifc_configitem.h
blob: 7a0f5180c17eba1266f164922a7627ab79c34b9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#ifndef NULLSOFT_AGAVE_IFC_CONFIGITEM_H
#define NULLSOFT_AGAVE_IFC_CONFIGITEM_H

#include <bfc/dispatch.h>
#include <stddef.h>
/*
notes:
The Set() functions are "public-facing", meaning that they can be called by anyone.  If you want to make your config item read-only,
then simply don't implement these.  You can always make "private" Set functions in your implementation.

SetStringInternal and GetStringInternal are written for use with classes to load and save from INI files (or XML files or whatever).
It's up to you to figure out a clever way to encode yourself.

*/

enum
{
	CONFIG_ITEM_TYPE_STRING = 0,
	CONFIG_ITEM_TYPE_INT = 1,
	CONFIG_ITEM_TYPE_UNSIGNED =2,
	CONFIG_ITEM_TYPE_BOOL =3,
	CONFIG_ITEM_TYPE_BINARY =4,
	CONFIG_ITEM_TYPE_INT_ARRAY = 5,
};

class ifc_configitem : public Dispatchable
{
protected:
	ifc_configitem() {}
	~ifc_configitem() {}
public:
	const wchar_t *GetName();
	int GetType();

	const wchar_t *GetString();
	void SetString(const wchar_t *stringValue);

	intptr_t GetInt();
	void SetInt(intptr_t intValue);

	uintptr_t GetUnsigned();
	void SetUnsigned(uintptr_t unsignedValue);

	bool GetBool();
	void SetBool(bool boolValue);

	float GetFloat();
	void SetFloat(float floatValue);

	size_t GetBinarySize();
	size_t GetBinaryData(void *data, size_t bytes); // returns bytes written
	void SetBinaryData(void *data, size_t bytes);

	size_t GetIntArrayElements();
	size_t GetIntArray(intptr_t *array, size_t elements); // returns elements written
	void SetIntArray(intptr_t *array, size_t elements);

	const wchar_t *GetStringInternal(); // gets a string suitable for saving in an INI file or XML
	void SetStringInternal(const wchar_t *internalString);

public:
	DISPATCH_CODES
	{
		IFC_CONFIGITEM_GETNAME = 10,
		IFC_CONFIGITEM_GETTYPE = 20,

		IFC_CONFIGITEM_GETSTRING= 30,
		IFC_CONFIGITEM_SETSTRING= 40,

		IFC_CONFIGITEM_GETINT= 50,
		IFC_CONFIGITEM_SETINT= 60,

		IFC_CONFIGITEM_GETUNSIGNED= 70,
		IFC_CONFIGITEM_SETUNSIGNED= 80,

		IFC_CONFIGITEM_GETBOOL= 90,
		IFC_CONFIGITEM_SETBOOL= 100,

		IFC_CONFIGITEM_GETBINARYSIZE= 110,
		IFC_CONFIGITEM_GETBINARYDATA= 120,
		IFC_CONFIGITEM_SETBINARYDATA= 130,

		IFC_CONFIGITEM_GETINTARRAYELEMENTS= 140,
		IFC_CONFIGITEM_GETINTARRAY= 150,
		IFC_CONFIGITEM_SETINTARRAY= 160,

		IFC_CONFIGITEM_GETSTRINGINTERNAL= 170,
		IFC_CONFIGITEM_SETSTRINGINTERNAL= 180,

		IFC_CONFIGITEM_GETFLOAT= 190,
		IFC_CONFIGITEM_SETFLOAT= 200,
	};
};



inline const wchar_t *ifc_configitem::GetName()
{
	return _call(IFC_CONFIGITEM_GETNAME, (const wchar_t *)0);
}

inline int ifc_configitem::GetType()
{
	return _call(IFC_CONFIGITEM_GETTYPE, (int)0);
}

inline const wchar_t *ifc_configitem::GetString()
{
	return _call(IFC_CONFIGITEM_GETSTRING, (const wchar_t *)0);
}

inline void ifc_configitem::SetString(const wchar_t *stringValue)
{
	_voidcall(IFC_CONFIGITEM_SETSTRING, stringValue);
}


inline intptr_t ifc_configitem::GetInt()
{
	return _call(IFC_CONFIGITEM_GETINT, (intptr_t)0);
}
#pragma warning(push)
#pragma warning(disable: 4244)
inline void ifc_configitem::SetInt(intptr_t intValue)
{
	_voidcall(IFC_CONFIGITEM_SETINT, intValue);
}
#pragma warning(pop)

inline uintptr_t ifc_configitem::GetUnsigned()
{
	return _call(IFC_CONFIGITEM_GETUNSIGNED, (uintptr_t)0);
}

inline void ifc_configitem::SetUnsigned(uintptr_t unsignedValue)
{
	_voidcall(IFC_CONFIGITEM_SETUNSIGNED, unsignedValue);
}


inline bool ifc_configitem::GetBool()
{
	return _call(IFC_CONFIGITEM_GETBOOL, (bool)false);
}

inline void ifc_configitem::SetBool(bool boolValue)
{
	_voidcall(IFC_CONFIGITEM_SETBOOL, boolValue);
}

inline size_t ifc_configitem::GetBinarySize()
{
	return _call(IFC_CONFIGITEM_GETBINARYSIZE, (size_t)0);
}

inline size_t ifc_configitem::GetBinaryData(void *data, size_t bytes)
{
	return _call(IFC_CONFIGITEM_GETBINARYDATA, (size_t)0, data, bytes);
}

inline void ifc_configitem::SetBinaryData(void *data, size_t bytes)
{
	_voidcall(IFC_CONFIGITEM_SETBINARYDATA, data, bytes);
}

inline size_t ifc_configitem::GetIntArrayElements()
{
	return _call(IFC_CONFIGITEM_GETINTARRAYELEMENTS, (size_t)0);
}

inline size_t ifc_configitem::GetIntArray(intptr_t *array, size_t elements)
{
	return _call(IFC_CONFIGITEM_GETINTARRAY, (size_t)0, array, elements);
}
inline void ifc_configitem::SetIntArray(intptr_t *array, size_t elements)
{
	_voidcall(IFC_CONFIGITEM_SETINTARRAY, array, elements);
}

inline const wchar_t *ifc_configitem::GetStringInternal()
{
	return _call(IFC_CONFIGITEM_GETSTRINGINTERNAL, (const wchar_t *)0);
}
inline void ifc_configitem::SetStringInternal(const wchar_t *internalString)
{
	_voidcall(IFC_CONFIGITEM_SETSTRINGINTERNAL, internalString);
}

inline float ifc_configitem::GetFloat()
{
	return _call(IFC_CONFIGITEM_GETFLOAT, (float)0);
}

inline void ifc_configitem::SetFloat(float floatValue)
{
	_voidcall(IFC_CONFIGITEM_SETFLOAT, floatValue);
}


#endif