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