File: PropertyIO.h

package info (click to toggle)
codelite 17.0.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 136,204 kB
  • sloc: cpp: 491,547; ansic: 280,393; php: 10,259; sh: 8,930; lisp: 7,664; vhdl: 6,518; python: 6,020; lex: 4,920; yacc: 3,123; perl: 2,385; javascript: 1,715; cs: 1,193; xml: 1,110; makefile: 804; cobol: 741; sql: 709; ruby: 620; f90: 566; ada: 534; asm: 464; fortran: 350; objc: 289; tcl: 258; java: 157; erlang: 61; pascal: 51; ml: 49; awk: 44; haskell: 36
file content (321 lines) | stat: -rw-r--r-- 11,511 bytes parent folder | download | duplicates (6)
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/***************************************************************
 * Name:      PropertyIO.cpp
 * Purpose:   Declares data types I/O and conversion functions
 * Author:    Michal Bližňák (michal.bliznak@tiscali.cz)
 * Created:   2007-10-28
 * Copyright: Michal Bližňák
 * License:   wxWidgets license (www.wxwidgets.org)
 * Notes:
 **************************************************************/

#ifndef _XSPROPERTYIO_H
#define _XSPROPERTYIO_H

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include <wx/hashmap.h>
#include <wx/xml/xml.h>
#include <wx/tokenzr.h>
#include <wx/list.h>

#include <wx/wxxmlserializer/Defs.h>

class WXDLLIMPEXP_XS xsProperty;
class WXDLLIMPEXP_XS xsSerializable;
class WXDLLIMPEXP_XS SerializableList;

namespace wxXS
{
	WX_DECLARE_OBJARRAY_WITH_DECL(wxRealPoint, RealPointArray, class WXDLLIMPEXP_XS);
	WX_DECLARE_LIST_WITH_DECL(wxRealPoint, RealPointList, class WXDLLIMPEXP_XS);

	WX_DEFINE_USER_EXPORTED_ARRAY_CHAR(char, CharArray, class WXDLLIMPEXP_XS);
	WX_DEFINE_USER_EXPORTED_ARRAY_INT(int, IntArray, class WXDLLIMPEXP_XS);
	WX_DEFINE_USER_EXPORTED_ARRAY_LONG(long, LongArray, class WXDLLIMPEXP_XS);
	WX_DEFINE_USER_EXPORTED_ARRAY_DOUBLE(double, DoubleArray, class WXDLLIMPEXP_XS);

	WX_DECLARE_STRING_HASH_MAP_WITH_DECL(wxString, StringMap, class WXDLLIMPEXP_XS);
}

/*!
 * \brief Base class encapsulating a property I/O handler. The class is used by
 * the xsSerializable class and is responsiblefor reading and writing of an XML node
 * containing property information. Each supported property (data) type should have
 * its own I/O handler class. Moreover, all derived classes must provide public functions
 * 'static wxString classname::ToString(datatype value)' and 'static datatype classname::
 * FromString( const wxString& value )' responsible for conversion between datatype and
 * and its string representation (these functions are used internally by class virtual functions.
 */
class WXDLLIMPEXP_XS xsPropertyIO : public wxObject
{
public:
    DECLARE_DYNAMIC_CLASS(xsProperty);

    /*! \brief Constructor. */
    xsPropertyIO(){;}
    /*! \brief Destructor. */
    virtual ~xsPropertyIO(){;}

    /*!
     * \brief Read content of the property XML node and store it to given property object.
     * \param property Pointer to the target property object
     * \param source Pointer to the source XML node
     */
    virtual void Read(xsProperty *property, wxXmlNode *source){wxUnusedVar(property);wxUnusedVar(source);}
    /*!
     * \brief Write content of given property object to target XML node.
     * \param property Pointer to the source property object
     * \param target Pointer to the target XML node
     */
    virtual void Write(xsProperty *property, wxXmlNode *target){wxUnusedVar(property);wxUnusedVar(target);}
    /*!
     * \brief Get textual representation of current property value.
	 * \param property Pointer to the source property object
	 * \return Textual representation of property's value
     */
	virtual wxString GetValueStr(xsProperty *property){wxUnusedVar(property);return wxT("");}
    /*!
     * \brief Set value defined by its textual representation to given property.
	 * \param property Pointer to the target property object
	 * \param valstr Textual representation of given value
     */
	virtual void SetValueStr(xsProperty *property, const wxString& valstr){wxUnusedVar(property); wxUnusedVar(valstr);}

    /*!
     * \brief Create new XML node of given name and value and assign it to the given
     * parent XML node.
     * \param parent Pointer to parent XML node
     * \param name Name of new XML node
     * \param value Content of new XML node
     * \param type Type of new XML (content) node
     */
     static wxXmlNode* AddPropertyNode(wxXmlNode* parent, const wxString& name, const wxString& value, wxXmlNodeType type = wxXML_TEXT_NODE );

protected:

    /*!
     * \brief Append info about the source property to given XML node.
     * \param source Pointer to the source property
     * \param target Pointer to modified XML node
     */
    void AppendPropertyType(xsProperty *source, wxXmlNode *target);
};

/*!
 * \brief Macro suitable for declaration of new property I/O handler
 * \param datatype Property's data type
 * \param name Handler class name
 */
#define XS_DECLARE_IO_HANDLER(datatype, name) \
class name : public xsPropertyIO \
{ \
public: \
	DECLARE_DYNAMIC_CLASS(name); \
	name(){;} \
	virtual ~name(){;} \
\
	virtual void Read(xsProperty *property, wxXmlNode *source); \
	virtual void Write(xsProperty *property, wxXmlNode *target); \
	virtual wxString GetValueStr(xsProperty *property); \
	virtual void SetValueStr(xsProperty *property, const wxString& valstr); \
	static wxString ToString(const datatype& value); \
	static datatype FromString(const wxString& value); \
}; \

/*!
 * \brief Macro suitable for declaration of exported new property I/O handler
 * \param datatype Property's data type
 * \param name Handler class name
 * \param decoration Class decoration
 */
#define XS_DECLARE_EXPORTED_IO_HANDLER(datatype, name, decoration) \
class decoration name : public xsPropertyIO \
{ \
public: \
	DECLARE_DYNAMIC_CLASS(name); \
	name(){;} \
	virtual ~name(){;} \
\
	virtual void Read(xsProperty *property, wxXmlNode *source); \
	virtual void Write(xsProperty *property, wxXmlNode *target); \
	virtual wxString GetValueStr(xsProperty *property); \
	virtual void SetValueStr(xsProperty *property, const wxString& valstr); \
	static wxString ToString(const datatype& value); \
	static datatype FromString(const wxString& value); \
}; \

/*!
 * \brief Macro suitable for implementation of new property I/O handler
 * \param datatype Property's data type
 * \param name Handler class name
 */
#define XS_DEFINE_IO_HANDLER(datatype, name) \
IMPLEMENT_DYNAMIC_CLASS(name, xsPropertyIO); \
\
void name::Read(xsProperty *property, wxXmlNode *source) \
{ \
    *((datatype*)property->m_pSourceVariable) = FromString(source->GetNodeContent()); \
} \
\
void name::Write(xsProperty *property, wxXmlNode *target) \
{ \
    wxString val = ToString(*((datatype*)property->m_pSourceVariable)); \
\
    if(val != property->m_sDefaultValueStr) \
    { \
        wxXmlNode *newNode = AddPropertyNode(target, wxT("property"), val); \
        AppendPropertyType(property, newNode); \
    } \
} \
\
wxString name::GetValueStr(xsProperty *property) \
{ \
	return ToString(*((datatype*)property->m_pSourceVariable)); \
} \
\
void name::SetValueStr(xsProperty *property, const wxString& valstr) \
{ \
	*((datatype*)property->m_pSourceVariable) = FromString(valstr); \
} \

/*!
 * \brief Property class encapsulating I/O functions used by 'wxString' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxString, xsStringPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxChar' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxChar, xsCharPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'long' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(long, xsLongPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'int' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(int, xsIntPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'bool' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(bool, xsBoolPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'double' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(double, xsDoublePropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'float' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(float, xsFloatPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxPoint' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxPoint, xsPointPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxSize' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxSize, xsSizePropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxRealPoint' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxRealPoint, xsRealPointPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxColour' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxColour, xsColourPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxPen' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxPen, xsPenPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxBrush' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxBrush, xsBrushPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxFont' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxFont, xsFontPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'wxArrayString' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxArrayString, xsArrayStringPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'CharArray' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::CharArray, xsArrayCharPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'IntArray' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::IntArray, xsArrayIntPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'LongArray' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::LongArray, xsArrayLongPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'DoubleArray' properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::DoubleArray, xsArrayDoublePropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'RealPointArray' (array of
 * integer values) properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::RealPointArray, xsArrayRealPointPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'ListRealPoint' (list of
 * wxRealPoint objects) properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::RealPointList, xsListRealPointPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'SerializableList' (list of
 * xsSerializable objects) properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(SerializableList, xsListSerializablePropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'serializabledynamic' (xsSerializable
 * dynamic class objects which are created during the deserialization process) properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(xsSerializable, xsDynObjPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'serializabledynamicnocreate' (already
 * existing xsSerializable dynamic class objects) properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(xsSerializable, xsDynNCObjPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'serializablestatic' (static
 * xsSerializable class objects) properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(xsSerializable, xsStaticObjPropIO, WXDLLIMPEXP_XS);

/*!
 * \brief Property class encapsulating I/O functions used by 'mapstring' (string hash map) properties.
 */
XS_DECLARE_EXPORTED_IO_HANDLER(wxXS::StringMap, xsMapStringPropIO, WXDLLIMPEXP_XS);

WX_DECLARE_HASH_MAP( wxString, xsPropertyIO*, wxStringHash, wxStringEqual, PropertyIOMap );

#endif //_XSPROPERTYIO_H