1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: streaming runtime metadata information (extended class info)
4 // Author: Stefan Csomor
8 // Copyright: (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_XTISTRMH__
13 #define _WX_XTISTRMH__
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "xtistrm.h"
21 #if wxUSE_EXTENDED_RTTI
23 const int wxInvalidObjectID
= -2 ;
24 const int wxNullObjectID
= -1 ;
26 // Filer contains the interfaces for streaming objects in and out of XML,
27 // rendering them either to objects in memory, or to code. Note: We
28 // consider the process of generating code to be one of *depersisting* the
29 // object from xml, *not* of persisting the object to code from an object
30 // in memory. This distincation can be confusing, and should be kept
31 // in mind when looking at the property streamers and callback interfaces
35 Main interfaces for streaming out objects.
38 // ----------------------------------------------------------------------------
41 // This class will be asked during the streaming-out process about every single
42 // property or object instance. It can veto streaming out by returning false
43 // or modify the value before it is streamed-out.
44 // ----------------------------------------------------------------------------
52 // will be called before an object is written, may veto by returning false
53 virtual bool BeforeWriteObject( wxWriter
*WXUNUSED(writer
) , const wxObject
*WXUNUSED(object
) , const wxClassInfo
*WXUNUSED(classInfo
) , wxxVariantArray
&WXUNUSED(metadata
)) { return true ; }
55 // will be called after this object has been written, may be needed for adjusting stacks
56 virtual void AfterWriteObject( wxWriter
*WXUNUSED(writer
) , const wxObject
*WXUNUSED(object
) , const wxClassInfo
*WXUNUSED(classInfo
) ) {}
58 // will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( -1 , -1 ) or veto
59 // writing that property at all by returning false
60 virtual bool BeforeWriteProperty( wxWriter
*WXUNUSED(writer
) , const wxPropertyInfo
*WXUNUSED(propInfo
) , wxxVariant
&WXUNUSED(value
) ) { return true ; }
62 // will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( -1 , -1 ) or veto
63 // writing that property at all by returning false
64 virtual bool BeforeWriteProperty( wxWriter
*WXUNUSED(writer
) , const wxPropertyInfo
*WXUNUSED(propInfo
) , wxxVariantArray
&WXUNUSED(value
) ) { return true ; }
66 // will be called after a property has been written out, may be needed for adjusting stacks
67 virtual void AfterWriteProperty( wxWriter
*WXUNUSED(writer
) , const wxPropertyInfo
*WXUNUSED(propInfo
) ) {}
69 // will be called before this delegate gets written
70 virtual bool BeforeWriteDelegate( wxWriter
*WXUNUSED(writer
) , const wxObject
*WXUNUSED(object
), const wxClassInfo
* WXUNUSED(classInfo
) , const wxPropertyInfo
*WXUNUSED(propInfo
) ,
71 const wxObject
*&WXUNUSED(eventSink
) , const wxHandlerInfo
* &WXUNUSED(handlerInfo
) ) { return true ; }
73 virtual void AfterWriteDelegate( wxWriter
*WXUNUSED(writer
) , const wxObject
*WXUNUSED(object
), const wxClassInfo
* WXUNUSED(classInfo
) , const wxPropertyInfo
*WXUNUSED(propInfo
) ,
74 const wxObject
*&WXUNUSED(eventSink
) , const wxHandlerInfo
* &WXUNUSED(handlerInfo
) ) { }
77 class wxWriter
: public wxObject
83 // with this call you start writing out a new top-level object
84 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, wxPersister
*persister
, const wxString
&name
, wxxVariantArray
&WXUNUSED(metadata
)) ;
87 // Managing the object identity table a.k.a context
89 // these methods make sure that no object gets written twice, because sometimes multiple calls to the WriteObject will be
90 // made without wanting to have duplicate objects written, the object identity table will be reset manually
92 virtual void ClearObjectContext() ;
94 // gets the object Id for a passed in object in the context
95 int GetObjectID(const wxObject
*obj
) ;
97 // returns true if this object has already been written in this context
98 bool IsObjectKnown( const wxObject
*obj
) ;
101 // streaming callbacks
103 // these callbacks really write out the values in the stream format
105 // begins writing out a new toplevel entry which has the indicated unique name
106 virtual void DoBeginWriteTopLevelEntry( const wxString
&name
) = 0 ;
108 // ends writing out a new toplevel entry which has the indicated unique name
109 virtual void DoEndWriteTopLevelEntry( const wxString
&name
) = 0 ;
111 // start of writing an object having the passed in ID
112 virtual void DoBeginWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, int objectID
, wxxVariantArray
&metadata
) = 0 ;
114 // end of writing an toplevel object name param is used for unique identification within the container
115 virtual void DoEndWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, int objectID
) = 0 ;
117 // writes a simple property in the stream format
118 virtual void DoWriteSimpleType( wxxVariant
&value
) = 0 ;
120 // start of writing a complex property into the stream (
121 virtual void DoBeginWriteProperty( const wxPropertyInfo
*propInfo
) = 0 ;
123 // end of writing a complex property into the stream
124 virtual void DoEndWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
126 virtual void DoBeginWriteElement() = 0 ;
127 virtual void DoEndWriteElement() = 0 ;
128 // insert an object reference to an already written object
129 virtual void DoWriteRepeatedObject( int objectID
) = 0 ;
131 // insert a null reference
132 virtual void DoWriteNullObject() = 0 ;
134 // writes a delegate in the stream format
135 virtual void DoWriteDelegate( const wxObject
*object
, const wxClassInfo
* classInfo
, const wxPropertyInfo
*propInfo
,
136 const wxObject
*eventSink
, int sinkObjectID
, const wxClassInfo
* eventSinkClassInfo
, const wxHandlerInfo
* handlerIndo
) = 0;
139 struct wxWriterInternal
;
140 wxWriterInternal
* m_data
;
142 struct wxWriterInternalPropertiesData
;
144 void WriteAllProperties( const wxObject
* obj
, const wxClassInfo
* ci
, wxPersister
*persister
, wxWriterInternalPropertiesData
* data
) ;
145 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, wxPersister
*persister
, bool isEmbedded
, wxxVariantArray
&metadata
) ;
146 void FindConnectEntry(const wxWindow
* evSource
,const wxDelegateTypeInfo
* dti
, const wxObject
* &sink
, const wxHandlerInfo
*&handler
) ;
149 class wxXmlWriter
: public wxWriter
153 wxXmlWriter( wxXmlNode
* parent
) ;
157 // streaming callbacks
159 // these callbacks really write out the values in the stream format
163 // streaming callbacks
165 // these callbacks really write out the values in the stream format
167 // begins writing out a new toplevel entry which has the indicated unique name
168 virtual void DoBeginWriteTopLevelEntry( const wxString
&name
) ;
170 // ends writing out a new toplevel entry which has the indicated unique name
171 virtual void DoEndWriteTopLevelEntry( const wxString
&name
) ;
173 // start of writing an object having the passed in ID
174 virtual void DoBeginWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, int objectID
, wxxVariantArray
&metadata
) ;
176 // end of writing an toplevel object name param is used for unique identification within the container
177 virtual void DoEndWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, int objectID
) ;
179 // writes a simple property in the stream format
180 virtual void DoWriteSimpleType( wxxVariant
&value
) ;
182 // start of writing a complex property into the stream (
183 virtual void DoBeginWriteProperty( const wxPropertyInfo
*propInfo
) ;
185 // end of writing a complex property into the stream
186 virtual void DoEndWriteProperty( const wxPropertyInfo
*propInfo
) ;
188 virtual void DoBeginWriteElement() ;
189 virtual void DoEndWriteElement() ;
191 // insert an object reference to an already written object
192 virtual void DoWriteRepeatedObject( int objectID
) ;
194 // insert a null reference
195 virtual void DoWriteNullObject() ;
197 // writes a delegate in the stream format
198 virtual void DoWriteDelegate( const wxObject
*object
, const wxClassInfo
* classInfo
, const wxPropertyInfo
*propInfo
,
199 const wxObject
*eventSink
, int sinkObjectID
, const wxClassInfo
* eventSinkClassInfo
, const wxHandlerInfo
* handlerIndo
) ;
201 struct wxXmlWriterInternal
;
202 wxXmlWriterInternal
* m_data
;
206 Streaming callbacks for depersisting XML to code, or running objects
209 class wxDepersister
;
212 wxReader handles streaming in a class from a arbitrary format. While walking through
213 it issues calls out to interfaces to depersist the guts from the underlying storage format.
216 class wxReader
: public wxObject
222 // the only thing wxReader knows about is the class info by object ID
223 wxClassInfo
*GetObjectClassInfo(int objectID
) ;
224 bool HasObjectClassInfo( int objectID
) ;
225 void SetObjectClassInfo(int objectID
, wxClassInfo
* classInfo
);
227 // Reads the component the reader is pointed at from the underlying format.
228 // The return value is the root object ID, which can
229 // then be used to ask the depersister about that object
230 virtual int ReadObject( const wxString
&name
, wxDepersister
*depersist
) = 0 ;
233 struct wxReaderInternal
;
234 wxReaderInternal
*m_data
;
238 wxXmlReader handles streaming in a class from XML
241 class wxXmlReader
: public wxReader
244 wxXmlReader(wxXmlNode
*parent
) { m_parent
= parent
; }
247 // Reads a component from XML. The return value is the root object ID, which can
248 // then be used to ask the depersister about that object
250 virtual int ReadObject( const wxString
&name
, wxDepersister
*depersist
) ;
253 int ReadComponent(wxXmlNode
*parent
, wxDepersister
*callbacks
);
255 // read the content of this node (simple type) and return the corresponding value
256 wxxVariant
ReadValue(wxXmlNode
*Node
,
257 const wxTypeInfo
*type
);
259 wxXmlNode
* m_parent
;
262 // This abstract class matches the allocate-init/create model of creation of objects.
263 // At runtime, these will create actual instances, and manipulate them.
264 // When generating code, these will just create statements of C++
265 // code to create the objects.
270 // allocate the new object on the heap, that object will have the passed in ID
271 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
, wxxVariantArray
&metadata
) = 0;
273 // initialize the already allocated object having the ID objectID with the Create method
274 // creation parameters which are objects are having their Ids passed in objectIDValues
275 // having objectId <> wxInvalidObjectID
277 virtual void CreateObject(int objectID
,
278 const wxClassInfo
*classInfo
,
280 wxxVariant
*VariantValues
,
281 int *objectIDValues
,
282 const wxClassInfo
**objectClassInfos
,
283 wxxVariantArray
&metadata
) = 0;
285 // destroy the heap-allocated object having the ID objectID, this may be used if an object
286 // is embedded in another object and set via value semantics, so the intermediate
287 // object can be destroyed after safely
288 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) = 0;
290 // set the corresponding property
291 virtual void SetProperty(int objectID
,
292 const wxClassInfo
*classInfo
,
293 const wxPropertyInfo
* propertyInfo
,
294 const wxxVariant
&VariantValue
) = 0;
296 // sets the corresponding property (value is an object)
297 virtual void SetPropertyAsObject(int objectID
,
298 const wxClassInfo
*classInfo
,
299 const wxPropertyInfo
* propertyInfo
,
300 int valueObjectId
) = 0;
302 // adds an element to a property collection
303 virtual void AddToPropertyCollection( int objectID
,
304 const wxClassInfo
*classInfo
,
305 const wxPropertyInfo
* propertyInfo
,
306 const wxxVariant
&VariantValue
) = 0;
308 // sets the corresponding property (value is an object)
309 virtual void AddToPropertyCollectionAsObject(int objectID
,
310 const wxClassInfo
*classInfo
,
311 const wxPropertyInfo
* propertyInfo
,
312 int valueObjectId
) = 0;
314 // sets the corresponding event handler
315 virtual void SetConnect(int EventSourceObjectID
,
316 const wxClassInfo
*EventSourceClassInfo
,
317 const wxDelegateTypeInfo
*delegateInfo
,
318 const wxClassInfo
*EventSinkClassInfo
,
319 const wxHandlerInfo
* handlerInfo
,
320 int EventSinkObjectID
) = 0;
324 wxRuntimeDepersister implements the callbacks that will depersist
325 an object into a running memory image, as opposed to writing
326 C++ initialization code to bring the object to life.
328 class wxRuntimeDepersister
: public wxDepersister
330 struct wxRuntimeDepersisterInternal
;
331 wxRuntimeDepersisterInternal
* m_data
;
333 wxRuntimeDepersister() ;
334 ~wxRuntimeDepersister() ;
336 // returns the object having the corresponding ID fully constructed
337 wxObject
*GetObject(int objectID
) ;
339 // allocate the new object on the heap, that object will have the passed in ID
340 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
,
341 wxxVariantArray
&metadata
) ;
343 // initialize the already allocated object having the ID objectID with the Create method
344 // creation parameters which are objects are having their Ids passed in objectIDValues
345 // having objectId <> wxInvalidObjectID
347 virtual void CreateObject(int objectID
,
348 const wxClassInfo
*classInfo
,
350 wxxVariant
*VariantValues
,
352 const wxClassInfo
**objectClassInfos
,
353 wxxVariantArray
&metadata
356 // destroy the heap-allocated object having the ID objectID, this may be used if an object
357 // is embedded in another object and set via value semantics, so the intermediate
358 // object can be destroyed after safely
359 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) ;
361 // set the corresponding property
362 virtual void SetProperty(int objectID
,
363 const wxClassInfo
*classInfo
,
364 const wxPropertyInfo
* propertyInfo
,
365 const wxxVariant
&variantValue
);
367 // sets the corresponding property (value is an object)
368 virtual void SetPropertyAsObject(int objectId
,
369 const wxClassInfo
*classInfo
,
370 const wxPropertyInfo
* propertyInfo
,
373 // adds an element to a property collection
374 virtual void AddToPropertyCollection( int objectID
,
375 const wxClassInfo
*classInfo
,
376 const wxPropertyInfo
* propertyInfo
,
377 const wxxVariant
&VariantValue
) ;
379 // sets the corresponding property (value is an object)
380 virtual void AddToPropertyCollectionAsObject(int objectID
,
381 const wxClassInfo
*classInfo
,
382 const wxPropertyInfo
* propertyInfo
,
385 // sets the corresponding event handler
386 virtual void SetConnect(int eventSourceObjectID
,
387 const wxClassInfo
*eventSourceClassInfo
,
388 const wxDelegateTypeInfo
*delegateInfo
,
389 const wxClassInfo
*eventSinkClassInfo
,
390 const wxHandlerInfo
* handlerInfo
,
391 int eventSinkObjectID
) ;
395 wxDepersisterCode implements the callbacks that will depersist
396 an object into a C++ initialization function.
399 class wxTextOutputStream
;
401 class wxCodeDepersister
: public wxDepersister
404 struct wxCodeDepersisterInternal
;
405 wxCodeDepersisterInternal
* m_data
;
406 wxTextOutputStream
*m_fp
;
407 wxString
ValueAsCode( const wxxVariant
¶m
) ;
409 wxCodeDepersister(wxTextOutputStream
*out
) ;
410 ~wxCodeDepersister() ;
412 // allocate the new object on the heap, that object will have the passed in ID
413 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
,
414 wxxVariantArray
&metadata
) ;
416 // initialize the already allocated object having the ID objectID with the Create method
417 // creation parameters which are objects are having their Ids passed in objectIDValues
418 // having objectId <> wxInvalidObjectID
420 virtual void CreateObject(int objectID
,
421 const wxClassInfo
*classInfo
,
423 wxxVariant
*variantValues
,
425 const wxClassInfo
**objectClassInfos
,
426 wxxVariantArray
&metadata
429 // destroy the heap-allocated object having the ID objectID, this may be used if an object
430 // is embedded in another object and set via value semantics, so the intermediate
431 // object can be destroyed after safely
432 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) ;
434 // set the corresponding property
435 virtual void SetProperty(int objectID
,
436 const wxClassInfo
*classInfo
,
437 const wxPropertyInfo
* propertyInfo
,
438 const wxxVariant
&variantValue
);
440 // sets the corresponding property (value is an object)
441 virtual void SetPropertyAsObject(int objectId
,
442 const wxClassInfo
*classInfo
,
443 const wxPropertyInfo
* propertyInfo
,
446 // adds an element to a property collection
447 virtual void AddToPropertyCollection( int objectID
,
448 const wxClassInfo
*classInfo
,
449 const wxPropertyInfo
* propertyInfo
,
450 const wxxVariant
&VariantValue
) ;
452 // sets the corresponding property (value is an object)
453 virtual void AddToPropertyCollectionAsObject(int objectID
,
454 const wxClassInfo
*classInfo
,
455 const wxPropertyInfo
* propertyInfo
,
458 // sets the corresponding event handler
459 virtual void SetConnect(int eventSourceObjectID
,
460 const wxClassInfo
*eventSourceClassInfo
,
461 const wxDelegateTypeInfo
*delegateInfo
,
462 const wxClassInfo
*eventSinkClassInfo
,
463 const wxHandlerInfo
* handlerInfo
,
464 int eventSinkObjectID
) ;
467 #endif // wxUSE_EXTENDED_RTTI