]> git.saurik.com Git - wxWidgets.git/blame - include/wx/xtistrm.h
Check axis number in the received joystick messages.
[wxWidgets.git] / include / wx / xtistrm.h
CommitLineData
70e88103
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/xtistrm.h
3// Purpose: streaming runtime metadata information (extended class info)
4// Author: Stefan Csomor
cab1a605 5// Modified by:
70e88103
SC
6// Created: 27/07/03
7// RCS-ID: $Id$
8// Copyright: (c) 2003 Stefan Csomor
65571936 9// Licence: wxWindows licence
70e88103
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_XTISTRMH__
13#define _WX_XTISTRMH__
14
28953245 15#include "wx/defs.h"
70e88103
SC
16
17#if wxUSE_EXTENDED_RTTI
18
28953245
SC
19#include "wx/object.h"
20
21const int wxInvalidObjectID = -2;
22const int wxNullObjectID = -3;
8ec1974e 23
70e88103
SC
24// Filer contains the interfaces for streaming objects in and out of XML,
25// rendering them either to objects in memory, or to code. Note: We
26// consider the process of generating code to be one of *depersisting* the
27// object from xml, *not* of persisting the object to code from an object
cbca59a8 28// in memory. This distinction can be confusing, and should be kept
70e88103
SC
29// in mind when looking at the property streamers and callback interfaces
30// listed below.
31
70e88103 32
ab6e4913 33// ----------------------------------------------------------------------------
cbca59a8 34// wxObjectWriterCallback
ab6e4913
SC
35//
36// This class will be asked during the streaming-out process about every single
37// property or object instance. It can veto streaming out by returning false
38// or modify the value before it is streamed-out.
39// ----------------------------------------------------------------------------
40
9ae4b67f
SC
41/*
42 class WXDLLIMPEXP_BASE wxClassInfo;
43 class WXDLLIMPEXP_BASE wxAnyList;
44 class WXDLLIMPEXP_BASE wxPropertyInfo;
45 class WXDLLIMPEXP_BASE wxAny;
46 class WXDLLIMPEXP_BASE wxHandlerInfo;
47 */
48
28953245
SC
49class WXDLLIMPEXP_BASE wxObjectWriter;
50class WXDLLIMPEXP_BASE wxObjectReader;
ab6e4913 51
cbca59a8 52class WXDLLIMPEXP_BASE wxObjectWriterCallback
aa8d7c2f 53{
28953245 54public:
cbca59a8 55 virtual ~wxObjectWriterCallback() {}
afc89ff4 56
ab6e4913 57 // will be called before an object is written, may veto by returning false
28953245
SC
58 virtual bool BeforeWriteObject( wxObjectWriter *WXUNUSED(writer),
59 const wxObject *WXUNUSED(object),
60 const wxClassInfo *WXUNUSED(classInfo),
cbca59a8 61 const wxStringToAnyHashMap &WXUNUSED(metadata))
28953245
SC
62 { return true; }
63
64 // will be called after this object has been written, may be
65 // needed for adjusting stacks
66 virtual void AfterWriteObject( wxObjectWriter *WXUNUSED(writer),
67 const wxObject *WXUNUSED(object),
68 const wxClassInfo *WXUNUSED(classInfo) )
69 {}
70
71 // will be called before a property gets written, may change the value,
72 // eg replace a concrete wxSize by wxSize( wxDefaultCoord, wxDefaultCoord )
73 // or veto writing that property at all by returning false
74 virtual bool BeforeWriteProperty( wxObjectWriter *WXUNUSED(writer),
75 const wxObject *WXUNUSED(object),
76 const wxPropertyInfo *WXUNUSED(propInfo),
cbca59a8 77 const wxAny &WXUNUSED(value) )
28953245
SC
78 { return true; }
79
80 // will be called before a property gets written, may change the value,
81 // eg replace a concrete wxSize by wxSize( wxDefaultCoord, wxDefaultCoord )
82 // or veto writing that property at all by returning false
83 virtual bool BeforeWriteProperty( wxObjectWriter *WXUNUSED(writer),
84 const wxObject *WXUNUSED(object),
85 const wxPropertyInfo *WXUNUSED(propInfo),
cbca59a8 86 const wxAnyList &WXUNUSED(value) )
28953245
SC
87 { return true; }
88
89 // will be called after a property has been written out, may be needed
90 // for adjusting stacks
91 virtual void AfterWriteProperty( wxObjectWriter *WXUNUSED(writer),
92 const wxPropertyInfo *WXUNUSED(propInfo) )
93 {}
ab6e4913
SC
94
95 // will be called before this delegate gets written
28953245
SC
96 virtual bool BeforeWriteDelegate( wxObjectWriter *WXUNUSED(writer),
97 const wxObject *WXUNUSED(object),
98 const wxClassInfo* WXUNUSED(classInfo),
99 const wxPropertyInfo *WXUNUSED(propInfo),
100 const wxObject *&WXUNUSED(eventSink),
101 const wxHandlerInfo* &WXUNUSED(handlerInfo) )
102 { return true; }
103
104 virtual void AfterWriteDelegate( wxObjectWriter *WXUNUSED(writer),
105 const wxObject *WXUNUSED(object),
106 const wxClassInfo* WXUNUSED(classInfo),
107 const wxPropertyInfo *WXUNUSED(propInfo),
108 const wxObject *&WXUNUSED(eventSink),
109 const wxHandlerInfo* &WXUNUSED(handlerInfo) )
110 { }
111};
aa8d7c2f 112
cbca59a8
SC
113class WXDLLIMPEXP_BASE wxObjectWriterFunctor: public wxObjectFunctor
114{
115};
116
28953245 117class WXDLLIMPEXP_BASE wxObjectWriter: public wxObject
aa8d7c2f 118{
cbca59a8 119 friend class wxObjectWriterFunctor;
28953245
SC
120public:
121 wxObjectWriter();
122 virtual ~wxObjectWriter();
aa8d7c2f
SC
123
124 // with this call you start writing out a new top-level object
28953245 125 void WriteObject(const wxObject *object, const wxClassInfo *classInfo,
cbca59a8
SC
126 wxObjectWriterCallback *writercallback, const wxString &name,
127 const wxStringToAnyHashMap &metadata);
aa8d7c2f 128
ab6e4913
SC
129 // Managing the object identity table a.k.a context
130 //
28953245
SC
131 // these methods make sure that no object gets written twice,
132 // because sometimes multiple calls to the WriteObject will be
133 // made without wanting to have duplicate objects written, the
134 // object identity table will be reset manually
135 virtual void ClearObjectContext();
2abce515 136
ab6e4913 137 // gets the object Id for a passed in object in the context
28953245 138 int GetObjectID(const wxObject *obj);
aa8d7c2f 139
ab6e4913 140 // returns true if this object has already been written in this context
28953245 141 bool IsObjectKnown( const wxObject *obj );
aa8d7c2f
SC
142
143 //
144 // streaming callbacks
145 //
146 // these callbacks really write out the values in the stream format
aa8d7c2f 147
ab6e4913 148 // begins writing out a new toplevel entry which has the indicated unique name
28953245 149 virtual void DoBeginWriteTopLevelEntry( const wxString &name ) = 0;
ab6e4913
SC
150
151 // ends writing out a new toplevel entry which has the indicated unique name
28953245 152 virtual void DoEndWriteTopLevelEntry( const wxString &name ) = 0;
ab6e4913
SC
153
154 // start of writing an object having the passed in ID
28953245 155 virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo,
cbca59a8 156 int objectID, const wxStringToAnyHashMap &metadata ) = 0;
aa8d7c2f 157
28953245
SC
158 // end of writing an toplevel object name param is used for unique
159 // identification within the container
160 virtual void DoEndWriteObject(const wxObject *object,
161 const wxClassInfo *classInfo, int objectID ) = 0;
ab6e4913
SC
162
163 // writes a simple property in the stream format
cbca59a8 164 virtual void DoWriteSimpleType( const wxAny &value ) = 0;
aa8d7c2f 165
ab6e4913 166 // start of writing a complex property into the stream (
28953245 167 virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) = 0;
aa8d7c2f 168
ab6e4913
SC
169 // end of writing a complex property into the stream
170 virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) = 0;
aa8d7c2f 171
28953245
SC
172 virtual void DoBeginWriteElement() = 0;
173 virtual void DoEndWriteElement() = 0;
cab1a605 174 // insert an object reference to an already written object
28953245 175 virtual void DoWriteRepeatedObject( int objectID ) = 0;
aa8d7c2f 176
ab6e4913 177 // insert a null reference
28953245 178 virtual void DoWriteNullObject() = 0;
aa8d7c2f
SC
179
180 // writes a delegate in the stream format
28953245
SC
181 virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo,
182 const wxPropertyInfo *propInfo, const wxObject *eventSink,
183 int sinkObjectID, const wxClassInfo* eventSinkClassInfo,
184 const wxHandlerInfo* handlerIndo ) = 0;
185
cbca59a8
SC
186 void WriteObject(const wxObject *object, const wxClassInfo *classInfo,
187 wxObjectWriterCallback *writercallback, bool isEmbedded, const wxStringToAnyHashMap &metadata );
188
189protected:
28953245
SC
190 struct wxObjectWriterInternal;
191 wxObjectWriterInternal* m_data;
192
193 struct wxObjectWriterInternalPropertiesData;
aa8d7c2f 194
28953245 195 void WriteAllProperties( const wxObject * obj, const wxClassInfo* ci,
cbca59a8 196 wxObjectWriterCallback *writercallback,
28953245 197 wxObjectWriterInternalPropertiesData * data );
aa8d7c2f 198
28953245 199 void WriteOneProperty( const wxObject *obj, const wxClassInfo* ci,
cbca59a8 200 const wxPropertyInfo* pi, wxObjectWriterCallback *writercallback,
28953245 201 wxObjectWriterInternalPropertiesData *data );
aa8d7c2f 202
28953245
SC
203
204 void FindConnectEntry(const wxEvtHandler * evSource,
205 const wxEventSourceTypeInfo* dti, const wxObject* &sink,
206 const wxHandlerInfo *&handler);
207};
aa8d7c2f 208
70e88103 209
70e88103 210/*
8ec1974e 211Streaming callbacks for depersisting XML to code, or running objects
70e88103
SC
212*/
213
cbca59a8 214class WXDLLIMPEXP_BASE wxObjectReaderCallback;
70e88103
SC
215
216/*
28953245 217wxObjectReader handles streaming in a class from a arbitrary format.
cbca59a8 218While walking through it issues calls out to interfaces to readercallback
28953245 219the guts from the underlying storage format.
70e88103 220*/
8ec1974e 221
28953245 222class WXDLLIMPEXP_BASE wxObjectReader: public wxObject
70e88103 223{
28953245
SC
224public:
225 wxObjectReader();
226 virtual ~wxObjectReader();
aa8d7c2f 227
28953245
SC
228 // the only thing wxObjectReader knows about is the class info by object ID
229 wxClassInfo *GetObjectClassInfo(int objectID);
230 bool HasObjectClassInfo( int objectID );
8ec1974e
SC
231 void SetObjectClassInfo(int objectID, wxClassInfo* classInfo);
232
cab1a605 233 // Reads the component the reader is pointed at from the underlying format.
8ec1974e
SC
234 // The return value is the root object ID, which can
235 // then be used to ask the depersister about that object
8f2b1cfd
SC
236 // if there was a problem you will get back wxInvalidObjectID and the current
237 // error log will carry the problems encoutered
cbca59a8 238 virtual int ReadObject( const wxString &name, wxObjectReaderCallback *readercallback ) = 0;
8ec1974e 239
28953245
SC
240private:
241 struct wxObjectReaderInternal;
242 wxObjectReaderInternal *m_data;
243};
8ec1974e 244
8ec1974e
SC
245// This abstract class matches the allocate-init/create model of creation of objects.
246// At runtime, these will create actual instances, and manipulate them.
247// When generating code, these will just create statements of C++
248// code to create the objects.
249
cbca59a8 250class WXDLLIMPEXP_BASE wxObjectReaderCallback
70e88103 251{
28953245 252public:
cbca59a8 253 virtual ~wxObjectReaderCallback() {}
afc89ff4 254
8ec1974e 255 // allocate the new object on the heap, that object will have the passed in ID
28953245 256 virtual void AllocateObject(int objectID, wxClassInfo *classInfo,
cbca59a8 257 wxStringToAnyHashMap &metadata) = 0;
8ec1974e 258
16a45a23 259 // initialize the already allocated object having the ID objectID with the Create method
8ec1974e
SC
260 // creation parameters which are objects are having their Ids passed in objectIDValues
261 // having objectId <> wxInvalidObjectID
262
16a45a23
SC
263 virtual void CreateObject(int objectID,
264 const wxClassInfo *classInfo,
265 int paramCount,
cbca59a8 266 wxAny *VariantValues,
28953245
SC
267 int *objectIDValues,
268 const wxClassInfo **objectClassInfos,
cbca59a8 269 wxStringToAnyHashMap &metadata) = 0;
8ec1974e 270
28953245
SC
271 // construct the new object on the heap, that object will have the passed in ID
272 // (for objects that don't support allocate-create type of creation)
273 // creation parameters which are objects are having their Ids passed in
274 // objectIDValues having objectId <> wxInvalidObjectID
583150e3
SC
275
276 virtual void ConstructObject(int objectID,
277 const wxClassInfo *classInfo,
278 int paramCount,
cbca59a8 279 wxAny *VariantValues,
28953245
SC
280 int *objectIDValues,
281 const wxClassInfo **objectClassInfos,
cbca59a8 282 wxStringToAnyHashMap &metadata) = 0;
28953245
SC
283
284 // destroy the heap-allocated object having the ID objectID, this may be used
285 // if an object is embedded in another object and set via value semantics,
286 // so the intermediate object can be destroyed after safely
16a45a23 287 virtual void DestroyObject(int objectID, wxClassInfo *classInfo) = 0;
8ec1974e
SC
288
289 // set the corresponding property
16a45a23
SC
290 virtual void SetProperty(int objectID,
291 const wxClassInfo *classInfo,
28953245 292 const wxPropertyInfo* propertyInfo,
cbca59a8 293 const wxAny &VariantValue) = 0;
8ec1974e
SC
294
295 // sets the corresponding property (value is an object)
16a45a23
SC
296 virtual void SetPropertyAsObject(int objectID,
297 const wxClassInfo *classInfo,
28953245 298 const wxPropertyInfo* propertyInfo,
8ec1974e
SC
299 int valueObjectId) = 0;
300
16a45a23 301 // adds an element to a property collection
28953245 302 virtual void AddToPropertyCollection( int objectID,
16a45a23 303 const wxClassInfo *classInfo,
28953245 304 const wxPropertyInfo* propertyInfo,
cbca59a8 305 const wxAny &VariantValue) = 0;
16a45a23
SC
306
307 // sets the corresponding property (value is an object)
308 virtual void AddToPropertyCollectionAsObject(int objectID,
309 const wxClassInfo *classInfo,
28953245 310 const wxPropertyInfo* propertyInfo,
16a45a23 311 int valueObjectId) = 0;
8ec1974e
SC
312
313 // sets the corresponding event handler
70e88103 314 virtual void SetConnect(int EventSourceObjectID,
8ec1974e 315 const wxClassInfo *EventSourceClassInfo,
28953245
SC
316 const wxPropertyInfo *delegateInfo,
317 const wxClassInfo *EventSinkClassInfo,
318 const wxHandlerInfo* handlerInfo,
8ec1974e 319 int EventSinkObjectID ) = 0;
70e88103
SC
320};
321
322/*
cbca59a8
SC
323wxObjectRuntimeReaderCallback implements the callbacks that will bring back
324an object into a life memory instance
70e88103 325*/
1c263d56 326
cbca59a8 327class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback: public wxObjectReaderCallback
70e88103 328{
28953245
SC
329 struct wxObjectRuntimeReaderCallbackInternal;
330 wxObjectRuntimeReaderCallbackInternal * m_data;
331
332public:
333 wxObjectRuntimeReaderCallback();
334 virtual ~wxObjectRuntimeReaderCallback();
8ec1974e 335
cab1a605 336 // returns the object having the corresponding ID fully constructed
28953245 337 wxObject *GetObject(int objectID);
8ec1974e
SC
338
339 // allocate the new object on the heap, that object will have the passed in ID
28953245 340 virtual void AllocateObject(int objectID, wxClassInfo *classInfo,
cbca59a8 341 wxStringToAnyHashMap &metadata);
8ec1974e 342
28953245
SC
343 // initialize the already allocated object having the ID objectID with
344 // the Create method creation parameters which are objects are having
345 // their Ids passed in objectIDValues having objectId <> wxInvalidObjectID
8ec1974e 346
16a45a23
SC
347 virtual void CreateObject(int objectID,
348 const wxClassInfo *classInfo,
349 int paramCount,
cbca59a8 350 wxAny *VariantValues,
8ec1974e 351 int *objectIDValues,
28953245 352 const wxClassInfo **objectClassInfos,
cbca59a8 353 wxStringToAnyHashMap &metadata
28953245 354 );
8ec1974e 355
28953245
SC
356 // construct the new object on the heap, that object will have the
357 // passed in ID (for objects that don't support allocate-create type of
358 // creation) creation parameters which are objects are having their Ids
359 // passed in objectIDValues having objectId <> wxInvalidObjectID
583150e3
SC
360
361 virtual void ConstructObject(int objectID,
362 const wxClassInfo *classInfo,
363 int paramCount,
cbca59a8 364 wxAny *VariantValues,
8ec1974e 365 int *objectIDValues,
28953245 366 const wxClassInfo **objectClassInfos,
cbca59a8 367 wxStringToAnyHashMap &metadata);
583150e3 368
28953245
SC
369 // destroy the heap-allocated object having the ID objectID, this may be
370 // used if an object is embedded in another object and set via value semantics,
371 // so the intermediate object can be destroyed after safely
372 virtual void DestroyObject(int objectID, wxClassInfo *classInfo);
8ec1974e
SC
373
374 // set the corresponding property
375 virtual void SetProperty(int objectID,
376 const wxClassInfo *classInfo,
28953245 377 const wxPropertyInfo* propertyInfo,
cbca59a8 378 const wxAny &variantValue);
8ec1974e
SC
379
380 // sets the corresponding property (value is an object)
381 virtual void SetPropertyAsObject(int objectId,
382 const wxClassInfo *classInfo,
28953245
SC
383 const wxPropertyInfo* propertyInfo,
384 int valueObjectId);
8ec1974e 385
16a45a23 386 // adds an element to a property collection
28953245 387 virtual void AddToPropertyCollection( int objectID,
16a45a23 388 const wxClassInfo *classInfo,
28953245 389 const wxPropertyInfo* propertyInfo,
cbca59a8 390 const wxAny &VariantValue);
16a45a23
SC
391
392 // sets the corresponding property (value is an object)
393 virtual void AddToPropertyCollectionAsObject(int objectID,
394 const wxClassInfo *classInfo,
28953245
SC
395 const wxPropertyInfo* propertyInfo,
396 int valueObjectId);
8ec1974e
SC
397
398 // sets the corresponding event handler
399 virtual void SetConnect(int eventSourceObjectID,
400 const wxClassInfo *eventSourceClassInfo,
28953245
SC
401 const wxPropertyInfo *delegateInfo,
402 const wxClassInfo *eventSinkClassInfo,
403 const wxHandlerInfo* handlerInfo,
404 int eventSinkObjectID );
70e88103
SC
405};
406
407#endif // wxUSE_EXTENDED_RTTI
408
12028905 409#endif