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__
17 #if wxUSE_EXTENDED_RTTI
19 #include "wx/string.h"
20 #include "wx/object.h"
22 const int wxInvalidObjectID
= -2;
23 const int wxNullObjectID
= -3;
25 // Filer contains the interfaces for streaming objects in and out of XML,
26 // rendering them either to objects in memory, or to code. Note: We
27 // consider the process of generating code to be one of *depersisting* the
28 // object from xml, *not* of persisting the object to code from an object
29 // in memory. This distincation can be confusing, and should be kept
30 // in mind when looking at the property streamers and callback interfaces
34 // ----------------------------------------------------------------------------
35 // wxObjectReaderCallback
37 // This class will be asked during the streaming-out process about every single
38 // property or object instance. It can veto streaming out by returning false
39 // or modify the value before it is streamed-out.
40 // ----------------------------------------------------------------------------
42 class WXDLLIMPEXP_BASE wxObjectWriter
;
43 class WXDLLIMPEXP_BASE wxObjectReader
;
44 class WXDLLIMPEXP_BASE wxClassInfo
;
45 class WXDLLIMPEXP_BASE wxVariantBaseArray
;
46 class WXDLLIMPEXP_BASE wxPropertyInfo
;
47 class WXDLLIMPEXP_BASE wxVariantBase
;
48 class WXDLLIMPEXP_BASE wxObjectWriter
;
49 class WXDLLIMPEXP_BASE wxHandlerInfo
;
51 class WXDLLIMPEXP_BASE wxObjectReaderCallback
54 virtual ~wxObjectReaderCallback() {}
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 wxVariantBaseArray
&WXUNUSED(metadata
))
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
) )
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 wxVariantBase
&WXUNUSED(value
) )
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 wxVariantBaseArray
&WXUNUSED(value
) )
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
) )
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
) )
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
) )
112 class WXDLLIMPEXP_BASE wxObjectWriter
: public wxObject
116 virtual ~wxObjectWriter();
118 // with this call you start writing out a new top-level object
119 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
120 wxObjectReaderCallback
*persister
, const wxString
&name
,
121 wxVariantBaseArray
&WXUNUSED(metadata
));
123 // Managing the object identity table a.k.a context
125 // these methods make sure that no object gets written twice,
126 // because sometimes multiple calls to the WriteObject will be
127 // made without wanting to have duplicate objects written, the
128 // object identity table will be reset manually
129 virtual void ClearObjectContext();
131 // gets the object Id for a passed in object in the context
132 int GetObjectID(const wxObject
*obj
);
134 // returns true if this object has already been written in this context
135 bool IsObjectKnown( const wxObject
*obj
);
138 // streaming callbacks
140 // these callbacks really write out the values in the stream format
142 // begins writing out a new toplevel entry which has the indicated unique name
143 virtual void DoBeginWriteTopLevelEntry( const wxString
&name
) = 0;
145 // ends writing out a new toplevel entry which has the indicated unique name
146 virtual void DoEndWriteTopLevelEntry( const wxString
&name
) = 0;
148 // start of writing an object having the passed in ID
149 virtual void DoBeginWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
150 int objectID
, wxVariantBaseArray
&metadata
) = 0;
152 // end of writing an toplevel object name param is used for unique
153 // identification within the container
154 virtual void DoEndWriteObject(const wxObject
*object
,
155 const wxClassInfo
*classInfo
, int objectID
) = 0;
157 // writes a simple property in the stream format
158 virtual void DoWriteSimpleType( wxVariantBase
&value
) = 0;
160 // start of writing a complex property into the stream (
161 virtual void DoBeginWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
163 // end of writing a complex property into the stream
164 virtual void DoEndWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
166 virtual void DoBeginWriteElement() = 0;
167 virtual void DoEndWriteElement() = 0;
168 // insert an object reference to an already written object
169 virtual void DoWriteRepeatedObject( int objectID
) = 0;
171 // insert a null reference
172 virtual void DoWriteNullObject() = 0;
174 // writes a delegate in the stream format
175 virtual void DoWriteDelegate( const wxObject
*object
, const wxClassInfo
* classInfo
,
176 const wxPropertyInfo
*propInfo
, const wxObject
*eventSink
,
177 int sinkObjectID
, const wxClassInfo
* eventSinkClassInfo
,
178 const wxHandlerInfo
* handlerIndo
) = 0;
181 struct wxObjectWriterInternal
;
182 wxObjectWriterInternal
* m_data
;
184 struct wxObjectWriterInternalPropertiesData
;
186 void WriteAllProperties( const wxObject
* obj
, const wxClassInfo
* ci
,
187 wxObjectReaderCallback
*persister
,
188 wxObjectWriterInternalPropertiesData
* data
);
190 void WriteOneProperty( const wxObject
*obj
, const wxClassInfo
* ci
,
191 const wxPropertyInfo
* pi
, wxObjectReaderCallback
*persister
,
192 wxObjectWriterInternalPropertiesData
*data
);
194 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
195 wxObjectReaderCallback
*persister
, bool isEmbedded
, wxVariantBaseArray
&metadata
);
197 void FindConnectEntry(const wxEvtHandler
* evSource
,
198 const wxEventSourceTypeInfo
* dti
, const wxObject
* &sink
,
199 const wxHandlerInfo
*&handler
);
204 Streaming callbacks for depersisting XML to code, or running objects
207 class WXDLLIMPEXP_BASE wxObjectWriterCallback
;
210 wxObjectReader handles streaming in a class from a arbitrary format.
211 While walking through it issues calls out to interfaces to depersist
212 the guts from the underlying storage format.
215 class WXDLLIMPEXP_BASE wxObjectReader
: public wxObject
219 virtual ~wxObjectReader();
221 // the only thing wxObjectReader knows about is the class info by object ID
222 wxClassInfo
*GetObjectClassInfo(int objectID
);
223 bool HasObjectClassInfo( int objectID
);
224 void SetObjectClassInfo(int objectID
, wxClassInfo
* classInfo
);
226 // Reads the component the reader is pointed at from the underlying format.
227 // The return value is the root object ID, which can
228 // then be used to ask the depersister about that object
229 // if there was a problem you will get back wxInvalidObjectID and the current
230 // error log will carry the problems encoutered
231 virtual int ReadObject( const wxString
&name
, wxObjectWriterCallback
*depersist
) = 0;
234 struct wxObjectReaderInternal
;
235 wxObjectReaderInternal
*m_data
;
238 // This abstract class matches the allocate-init/create model of creation of objects.
239 // At runtime, these will create actual instances, and manipulate them.
240 // When generating code, these will just create statements of C++
241 // code to create the objects.
243 class WXDLLIMPEXP_BASE wxObjectWriterCallback
246 virtual ~wxObjectWriterCallback() {}
248 // allocate the new object on the heap, that object will have the passed in ID
249 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
,
250 wxVariantBaseArray
&metadata
) = 0;
252 // initialize the already allocated object having the ID objectID with the Create method
253 // creation parameters which are objects are having their Ids passed in objectIDValues
254 // having objectId <> wxInvalidObjectID
256 virtual void CreateObject(int objectID
,
257 const wxClassInfo
*classInfo
,
259 wxVariantBase
*VariantValues
,
261 const wxClassInfo
**objectClassInfos
,
262 wxVariantBaseArray
&metadata
) = 0;
264 // construct the new object on the heap, that object will have the passed in ID
265 // (for objects that don't support allocate-create type of creation)
266 // creation parameters which are objects are having their Ids passed in
267 // objectIDValues having objectId <> wxInvalidObjectID
269 virtual void ConstructObject(int objectID
,
270 const wxClassInfo
*classInfo
,
272 wxVariantBase
*VariantValues
,
274 const wxClassInfo
**objectClassInfos
,
275 wxVariantBaseArray
&metadata
) = 0;
277 // destroy the heap-allocated object having the ID objectID, this may be used
278 // if an object is embedded in another object and set via value semantics,
279 // so the intermediate object can be destroyed after safely
280 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) = 0;
282 // set the corresponding property
283 virtual void SetProperty(int objectID
,
284 const wxClassInfo
*classInfo
,
285 const wxPropertyInfo
* propertyInfo
,
286 const wxVariantBase
&VariantValue
) = 0;
288 // sets the corresponding property (value is an object)
289 virtual void SetPropertyAsObject(int objectID
,
290 const wxClassInfo
*classInfo
,
291 const wxPropertyInfo
* propertyInfo
,
292 int valueObjectId
) = 0;
294 // adds an element to a property collection
295 virtual void AddToPropertyCollection( int objectID
,
296 const wxClassInfo
*classInfo
,
297 const wxPropertyInfo
* propertyInfo
,
298 const wxVariantBase
&VariantValue
) = 0;
300 // sets the corresponding property (value is an object)
301 virtual void AddToPropertyCollectionAsObject(int objectID
,
302 const wxClassInfo
*classInfo
,
303 const wxPropertyInfo
* propertyInfo
,
304 int valueObjectId
) = 0;
306 // sets the corresponding event handler
307 virtual void SetConnect(int EventSourceObjectID
,
308 const wxClassInfo
*EventSourceClassInfo
,
309 const wxPropertyInfo
*delegateInfo
,
310 const wxClassInfo
*EventSinkClassInfo
,
311 const wxHandlerInfo
* handlerInfo
,
312 int EventSinkObjectID
) = 0;
316 wxObjectRuntimeReaderCallback implements the callbacks that will depersist
317 an object into a running memory image, as opposed to writing
318 C++ initialization code to bring the object to life.
321 class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback
: public wxObjectWriterCallback
323 struct wxObjectRuntimeReaderCallbackInternal
;
324 wxObjectRuntimeReaderCallbackInternal
* m_data
;
327 wxObjectRuntimeReaderCallback();
328 virtual ~wxObjectRuntimeReaderCallback();
330 // returns the object having the corresponding ID fully constructed
331 wxObject
*GetObject(int objectID
);
333 // allocate the new object on the heap, that object will have the passed in ID
334 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
,
335 wxVariantBaseArray
&metadata
);
337 // initialize the already allocated object having the ID objectID with
338 // the Create method creation parameters which are objects are having
339 // their Ids passed in objectIDValues having objectId <> wxInvalidObjectID
341 virtual void CreateObject(int objectID
,
342 const wxClassInfo
*classInfo
,
344 wxVariantBase
*VariantValues
,
346 const wxClassInfo
**objectClassInfos
,
347 wxVariantBaseArray
&metadata
350 // construct the new object on the heap, that object will have the
351 // passed in ID (for objects that don't support allocate-create type of
352 // creation) creation parameters which are objects are having their Ids
353 // passed in objectIDValues having objectId <> wxInvalidObjectID
355 virtual void ConstructObject(int objectID
,
356 const wxClassInfo
*classInfo
,
358 wxVariantBase
*VariantValues
,
360 const wxClassInfo
**objectClassInfos
,
361 wxVariantBaseArray
&metadata
);
363 // destroy the heap-allocated object having the ID objectID, this may be
364 // used if an object is embedded in another object and set via value semantics,
365 // so the intermediate object can be destroyed after safely
366 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
);
368 // set the corresponding property
369 virtual void SetProperty(int objectID
,
370 const wxClassInfo
*classInfo
,
371 const wxPropertyInfo
* propertyInfo
,
372 const wxVariantBase
&variantValue
);
374 // sets the corresponding property (value is an object)
375 virtual void SetPropertyAsObject(int objectId
,
376 const wxClassInfo
*classInfo
,
377 const wxPropertyInfo
* propertyInfo
,
380 // adds an element to a property collection
381 virtual void AddToPropertyCollection( int objectID
,
382 const wxClassInfo
*classInfo
,
383 const wxPropertyInfo
* propertyInfo
,
384 const wxVariantBase
&VariantValue
);
386 // sets the corresponding property (value is an object)
387 virtual void AddToPropertyCollectionAsObject(int objectID
,
388 const wxClassInfo
*classInfo
,
389 const wxPropertyInfo
* propertyInfo
,
392 // sets the corresponding event handler
393 virtual void SetConnect(int eventSourceObjectID
,
394 const wxClassInfo
*eventSourceClassInfo
,
395 const wxPropertyInfo
*delegateInfo
,
396 const wxClassInfo
*eventSinkClassInfo
,
397 const wxHandlerInfo
* handlerInfo
,
398 int eventSinkObjectID
);
401 #endif // wxUSE_EXTENDED_RTTI