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.
41 // will be called before a toplevel object is written, may veto even that (eg for objects that cannot be supported) by returning false
42 virtual bool BeforeWriteObject( const wxObject
*WXUNUSED(object
) , const wxClassInfo
*WXUNUSED(classInfo
) , const wxString
&WXUNUSED(name
)) { return true ; }
44 // will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( -1 , -1 ) or veto
45 // writing that property at all by returning false
46 virtual bool BeforeWriteProperty( const wxObject
*WXUNUSED(object
) , const wxClassInfo
*WXUNUSED(classInfo
) , const wxPropertyInfo
*WXUNUSED(propInfo
) , wxxVariant
&WXUNUSED(value
) ) { return true ; }
48 // will be called before a property with an object value gets written, may change the value , eg replace the instance, void it or veto
49 // writing that property at all by returning false
50 virtual bool BeforeWritePropertyAsObject( const wxObject
*WXUNUSED(object
) , const wxClassInfo
*WXUNUSED(classInfo
) , const wxPropertyInfo
*WXUNUSED(propInfo
) , wxxVariant
&WXUNUSED(value
) ) { return true ; }
52 // will be called before a delegate property gets written, you may change all informations about the event sink
53 virtual bool BeforeWriteDelegate( const wxObject
*WXUNUSED(object
), const wxClassInfo
* WXUNUSED(classInfo
) , const wxPropertyInfo
*WXUNUSED(propInfo
) ,
54 const wxObject
*&WXUNUSED(eventSink
) , const wxHandlerInfo
* &WXUNUSED(handlerInfo
) ) { return true ; }
57 class wxWriter
: public wxObject
63 // with this call you start writing out a new top-level object
64 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, wxPersister
*persister
, const wxString
&name
) ;
66 int GetObjectID(const wxObject
*obj
) ;
67 bool IsObjectKnown( const wxObject
*obj
) ;
71 // streaming callbacks
73 // these callbacks really write out the values in the stream format
76 // start of writing an toplevel object name param is used for unique identification within the container
77 virtual void DoBeginWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, int objectID
, const wxString
&name
) = 0 ;
79 // end of writing an toplevel object name param is used for unique identification within the container
80 virtual void DoEndWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, int objectID
, const wxString
&name
) = 0 ;
82 // start of writing an object used as param
83 virtual void DoBeginWriteParamAsObject(const wxObject
*parentObject
, const wxClassInfo
*parentClassInfo
, const wxObject
*valueObject
,
84 const wxClassInfo
*valueObjectClassInfo
, int valueObjectID
, const wxPropertyInfo
*propInfo
) = 0 ;
86 // end of writing an object used as param
87 virtual void DoEndWriteParamAsObject(const wxObject
*parentObject
, const wxClassInfo
*parentClassInfo
, const wxObject
*valueObject
,
88 const wxClassInfo
*valueObjectClassInfo
, int valueObjectID
, const wxPropertyInfo
*propInfo
) = 0 ;
90 // insert an object reference to an already written object
91 virtual void DoWriteObjectReference(const wxObject
*parentObject
, const wxClassInfo
*parentClassInfo
, const wxObject
*valueObject
,
92 const wxClassInfo
*valueObjectClassInfo
, int valueObjectID
, const wxPropertyInfo
*propInfo
) = 0 ;
94 // writes a property in the stream format
95 virtual void DoWriteProperty( const wxObject
*object
, const wxClassInfo
* classInfo
, const wxPropertyInfo
*propInfo
, wxxVariant
&value
) = 0 ;
97 // writes a delegate in the stream format
98 virtual void DoWriteDelegate( const wxObject
*object
, const wxClassInfo
* classInfo
, const wxPropertyInfo
*propInfo
,
99 const wxObject
*eventSink
, int sinkObjectID
, const wxClassInfo
* eventSinkClassInfo
, const wxHandlerInfo
* handlerIndo
) = 0;
102 struct wxWriterInternal
;
103 wxWriterInternal
* m_data
;
105 struct wxWriterInternalPropertiesData
;
107 void WriteAllProperties( const wxObject
* obj
, const wxClassInfo
* ci
, wxPersister
*persister
, wxWriterInternalPropertiesData
* data
) ;
110 class wxXmlWriter
: public wxWriter
114 wxXmlWriter( wxXmlNode
* parent
) ;
118 // streaming callbacks
120 // these callbacks really write out the values in the stream format
123 // start of writing an toplevel object name param is used for unique identification within the container
124 virtual void DoBeginWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, int objectID
, const wxString
&name
) ;
126 // end of writing an toplevel object name param is used for unique identification within the container
127 virtual void DoEndWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, int objectID
, const wxString
&name
) ;
129 // start of writing an object used as param
130 virtual void DoBeginWriteParamAsObject(const wxObject
*parentObject
, const wxClassInfo
*parentClassInfo
, const wxObject
*valueObject
,
131 const wxClassInfo
*valueObjectClassInfo
, int valueObjectID
, const wxPropertyInfo
*propInfo
) ;
133 // end of writing an object used as param
134 virtual void DoEndWriteParamAsObject(const wxObject
*parentObject
, const wxClassInfo
*parentClassInfo
, const wxObject
*valueObject
,
135 const wxClassInfo
*valueObjectClassInfo
, int valueObjectID
, const wxPropertyInfo
*propInfo
) ;
137 // insert an object reference to an already written object or to a null object
138 virtual void DoWriteObjectReference(const wxObject
*parentObject
, const wxClassInfo
*parentClassInfo
, const wxObject
*valueObject
,
139 const wxClassInfo
*valueObjectClassInfo
, int valueObjectID
, const wxPropertyInfo
*propInfo
) ;
141 // writes a property in the stream format
142 virtual void DoWriteProperty( const wxObject
*object
, const wxClassInfo
* classInfo
, const wxPropertyInfo
*propInfo
, wxxVariant
&value
) ;
144 // writes a delegate in the stream format
145 virtual void DoWriteDelegate( const wxObject
*object
, const wxClassInfo
* classInfo
, const wxPropertyInfo
*propInfo
,
146 const wxObject
*eventSink
, int sinkObjectID
, const wxClassInfo
* eventSinkClassInfo
, const wxHandlerInfo
* handlerInfo
) ;
148 struct wxXmlWriterInternal
;
149 wxXmlWriterInternal
* m_data
;
153 Streaming callbacks for depersisting XML to code, or running objects
156 class wxDepersister
;
159 wxReader handles streaming in a class from a arbitrary format. While walking through
160 it issues calls out to interfaces to depersist the guts from the underlying storage format.
163 class wxReader
: public wxObject
169 // the only thing wxReader knows about is the class info by object ID
170 wxClassInfo
*GetObjectClassInfo(int objectID
) ;
171 bool HasObjectClassInfo( int objectID
) ;
172 void SetObjectClassInfo(int objectID
, wxClassInfo
* classInfo
);
174 // Reads the component the reader is pointed at from the underlying format.
175 // The return value is the root object ID, which can
176 // then be used to ask the depersister about that object
177 virtual int ReadObject( wxDepersister
*depersist
) = 0 ;
180 struct wxReaderInternal
;
181 wxReaderInternal
*m_data
;
185 wxXmlReader handles streaming in a class from XML
188 class wxXmlReader
: public wxReader
191 wxXmlReader(wxXmlNode
*parent
) { m_parent
= parent
; }
194 // Reads a component from XML. The return value is the root object ID, which can
195 // then be used to ask the depersister about that object
197 int ReadObject(wxDepersister
*callbacks
);
200 int ReadComponent(wxXmlNode
*parent
, wxDepersister
*callbacks
);
202 // accessor is only used as a temporary measure
203 wxxVariant
ReadValue(wxXmlNode
*Node
,
204 wxPropertyAccessor
*accessor
);
206 wxXmlNode
* m_parent
;
209 // This abstract class matches the allocate-init/create model of creation of objects.
210 // At runtime, these will create actual instances, and manipulate them.
211 // When generating code, these will just create statements of C++
212 // code to create the objects.
217 // allocate the new object on the heap, that object will have the passed in ID
218 virtual void AllocateObject(int ObjectID
, wxClassInfo
*ClassInfo
) = 0;
220 // initialize the already allocated object having the ID ObjectID with the Create method
221 // creation parameters which are objects are having their Ids passed in objectIDValues
222 // having objectId <> wxInvalidObjectID
224 virtual void CreateObject(int ObjectID
,
225 const wxClassInfo
*ClassInfo
,
227 wxxVariant
*VariantValues
,
228 int *objectIDValues
,
229 const wxClassInfo
**objectClassInfos
232 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
233 // is embedded in another object and set via value semantics, so the intermediate
234 // object can be destroyed after safely
235 virtual void DestroyObject(int ObjectID
, wxClassInfo
*ClassInfo
) = 0;
237 // set the corresponding property
238 virtual void SetProperty(int ObjectID
,
239 const wxClassInfo
*ClassInfo
,
240 const wxPropertyInfo
* PropertyInfo
,
241 const wxxVariant
&VariantValue
) = 0;
243 // sets the corresponding property (value is an object)
244 virtual void SetPropertyAsObject(int ObjectId
,
245 const wxClassInfo
*ClassInfo
,
246 const wxPropertyInfo
* PropertyInfo
,
247 int valueObjectId
) = 0;
250 // sets the corresponding event handler
251 virtual void SetConnect(int EventSourceObjectID
,
252 const wxClassInfo
*EventSourceClassInfo
,
253 const wxDelegateTypeInfo
*delegateInfo
,
254 const wxClassInfo
*EventSinkClassInfo
,
255 const wxHandlerInfo
* handlerInfo
,
256 int EventSinkObjectID
) = 0;
260 wxRuntimeDepersister implements the callbacks that will depersist
261 an object into a running memory image, as opposed to writing
262 C++ initialization code to bring the object to life.
264 class wxRuntimeDepersister
: public wxDepersister
266 struct wxRuntimeDepersisterInternal
;
267 wxRuntimeDepersisterInternal
* m_data
;
269 wxRuntimeDepersister() ;
270 ~wxRuntimeDepersister() ;
272 // returns the object having the corresponding ID fully constructed
273 wxObject
*GetObject(int objectID
) ;
275 // allocate the new object on the heap, that object will have the passed in ID
276 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
) ;
278 // initialize the already allocated object having the ID ObjectID with the Create method
279 // creation parameters which are objects are having their Ids passed in objectIDValues
280 // having objectId <> wxInvalidObjectID
282 virtual void CreateObject(int ObjectID
,
283 const wxClassInfo
*ClassInfo
,
285 wxxVariant
*VariantValues
,
287 const wxClassInfo
**objectClassInfos
290 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
291 // is embedded in another object and set via value semantics, so the intermediate
292 // object can be destroyed after safely
293 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) ;
295 // set the corresponding property
296 virtual void SetProperty(int objectID
,
297 const wxClassInfo
*classInfo
,
298 const wxPropertyInfo
* propertyInfo
,
299 const wxxVariant
&variantValue
);
301 // sets the corresponding property (value is an object)
302 virtual void SetPropertyAsObject(int objectId
,
303 const wxClassInfo
*classInfo
,
304 const wxPropertyInfo
* propertyInfo
,
308 // sets the corresponding event handler
309 virtual void SetConnect(int eventSourceObjectID
,
310 const wxClassInfo
*eventSourceClassInfo
,
311 const wxDelegateTypeInfo
*delegateInfo
,
312 const wxClassInfo
*eventSinkClassInfo
,
313 const wxHandlerInfo
* handlerInfo
,
314 int eventSinkObjectID
) ;
318 wxDepersisterCode implements the callbacks that will depersist
319 an object into a C++ initialization function.
322 class wxTextOutputStream
;
324 class wxCodeDepersister
: public wxDepersister
327 struct wxCodeDepersisterInternal
;
328 wxCodeDepersisterInternal
* m_data
;
329 wxTextOutputStream
*m_fp
;
330 wxString
ValueAsCode( const wxxVariant
¶m
) ;
332 wxCodeDepersister(wxTextOutputStream
*out
) ;
333 ~wxCodeDepersister() ;
335 // allocate the new object on the heap, that object will have the passed in ID
336 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
) ;
338 // initialize the already allocated object having the ID ObjectID with the Create method
339 // creation parameters which are objects are having their Ids passed in objectIDValues
340 // having objectId <> wxInvalidObjectID
342 virtual void CreateObject(int objectID
,
343 const wxClassInfo
*classInfo
,
345 wxxVariant
*variantValues
,
347 const wxClassInfo
**objectClassInfos
350 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
351 // is embedded in another object and set via value semantics, so the intermediate
352 // object can be destroyed after safely
353 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) ;
355 // set the corresponding property
356 virtual void SetProperty(int objectID
,
357 const wxClassInfo
*classInfo
,
358 const wxPropertyInfo
* propertyInfo
,
359 const wxxVariant
&variantValue
);
361 // sets the corresponding property (value is an object)
362 virtual void SetPropertyAsObject(int objectId
,
363 const wxClassInfo
*classInfo
,
364 const wxPropertyInfo
* propertyInfo
,
368 // sets the corresponding event handler
369 virtual void SetConnect(int eventSourceObjectID
,
370 const wxClassInfo
*eventSourceClassInfo
,
371 const wxDelegateTypeInfo
*delegateInfo
,
372 const wxClassInfo
*eventSinkClassInfo
,
373 const wxHandlerInfo
* handlerInfo
,
374 int eventSinkObjectID
) ;
377 #endif // wxUSE_EXTENDED_RTTI