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/object.h"
21 const int wxInvalidObjectID
= -2;
22 const int wxNullObjectID
= -3;
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
28 // in memory. This distinction can be confusing, and should be kept
29 // in mind when looking at the property streamers and callback interfaces
33 // ----------------------------------------------------------------------------
34 // wxObjectWriterCallback
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 // ----------------------------------------------------------------------------
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;
49 class WXDLLIMPEXP_BASE wxObjectWriter
;
50 class WXDLLIMPEXP_BASE wxObjectReader
;
52 class WXDLLIMPEXP_BASE wxObjectWriterCallback
55 virtual ~wxObjectWriterCallback() {}
57 // will be called before an object is written, may veto by returning false
58 virtual bool BeforeWriteObject( wxObjectWriter
*WXUNUSED(writer
),
59 const wxObject
*WXUNUSED(object
),
60 const wxClassInfo
*WXUNUSED(classInfo
),
61 const wxStringToAnyHashMap
&WXUNUSED(metadata
))
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
) )
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
),
77 const wxAny
&WXUNUSED(value
) )
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
),
86 const wxAnyList
&WXUNUSED(value
) )
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
) )
95 // will be called before this delegate gets written
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
) )
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
) )
113 class WXDLLIMPEXP_BASE wxObjectWriterFunctor
: public wxObjectFunctor
117 class WXDLLIMPEXP_BASE wxObjectWriter
: public wxObject
119 friend class wxObjectWriterFunctor
;
122 virtual ~wxObjectWriter();
124 // with this call you start writing out a new top-level object
125 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
126 wxObjectWriterCallback
*writercallback
, const wxString
&name
,
127 const wxStringToAnyHashMap
&metadata
);
129 // Managing the object identity table a.k.a context
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();
137 // gets the object Id for a passed in object in the context
138 int GetObjectID(const wxObject
*obj
);
140 // returns true if this object has already been written in this context
141 bool IsObjectKnown( const wxObject
*obj
);
144 // streaming callbacks
146 // these callbacks really write out the values in the stream format
148 // begins writing out a new toplevel entry which has the indicated unique name
149 virtual void DoBeginWriteTopLevelEntry( const wxString
&name
) = 0;
151 // ends writing out a new toplevel entry which has the indicated unique name
152 virtual void DoEndWriteTopLevelEntry( const wxString
&name
) = 0;
154 // start of writing an object having the passed in ID
155 virtual void DoBeginWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
156 int objectID
, const wxStringToAnyHashMap
&metadata
) = 0;
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;
163 // writes a simple property in the stream format
164 virtual void DoWriteSimpleType( const wxAny
&value
) = 0;
166 // start of writing a complex property into the stream (
167 virtual void DoBeginWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
169 // end of writing a complex property into the stream
170 virtual void DoEndWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
172 virtual void DoBeginWriteElement() = 0;
173 virtual void DoEndWriteElement() = 0;
174 // insert an object reference to an already written object
175 virtual void DoWriteRepeatedObject( int objectID
) = 0;
177 // insert a null reference
178 virtual void DoWriteNullObject() = 0;
180 // writes a delegate in the stream format
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;
186 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
187 wxObjectWriterCallback
*writercallback
, bool isEmbedded
, const wxStringToAnyHashMap
&metadata
);
190 struct wxObjectWriterInternal
;
191 wxObjectWriterInternal
* m_data
;
193 struct wxObjectWriterInternalPropertiesData
;
195 void WriteAllProperties( const wxObject
* obj
, const wxClassInfo
* ci
,
196 wxObjectWriterCallback
*writercallback
,
197 wxObjectWriterInternalPropertiesData
* data
);
199 void WriteOneProperty( const wxObject
*obj
, const wxClassInfo
* ci
,
200 const wxPropertyInfo
* pi
, wxObjectWriterCallback
*writercallback
,
201 wxObjectWriterInternalPropertiesData
*data
);
204 void FindConnectEntry(const wxEvtHandler
* evSource
,
205 const wxEventSourceTypeInfo
* dti
, const wxObject
* &sink
,
206 const wxHandlerInfo
*&handler
);
211 Streaming callbacks for depersisting XML to code, or running objects
214 class WXDLLIMPEXP_BASE wxObjectReaderCallback
;
217 wxObjectReader handles streaming in a class from a arbitrary format.
218 While walking through it issues calls out to interfaces to readercallback
219 the guts from the underlying storage format.
222 class WXDLLIMPEXP_BASE wxObjectReader
: public wxObject
226 virtual ~wxObjectReader();
228 // the only thing wxObjectReader knows about is the class info by object ID
229 wxClassInfo
*GetObjectClassInfo(int objectID
);
230 bool HasObjectClassInfo( int objectID
);
231 void SetObjectClassInfo(int objectID
, wxClassInfo
* classInfo
);
233 // Reads the component the reader is pointed at from the underlying format.
234 // The return value is the root object ID, which can
235 // then be used to ask the depersister about that object
236 // if there was a problem you will get back wxInvalidObjectID and the current
237 // error log will carry the problems encoutered
238 virtual int ReadObject( const wxString
&name
, wxObjectReaderCallback
*readercallback
) = 0;
241 struct wxObjectReaderInternal
;
242 wxObjectReaderInternal
*m_data
;
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.
250 class WXDLLIMPEXP_BASE wxObjectReaderCallback
253 virtual ~wxObjectReaderCallback() {}
255 // allocate the new object on the heap, that object will have the passed in ID
256 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
,
257 wxStringToAnyHashMap
&metadata
) = 0;
259 // initialize the already allocated object having the ID objectID with the Create method
260 // creation parameters which are objects are having their Ids passed in objectIDValues
261 // having objectId <> wxInvalidObjectID
263 virtual void CreateObject(int objectID
,
264 const wxClassInfo
*classInfo
,
266 wxAny
*VariantValues
,
268 const wxClassInfo
**objectClassInfos
,
269 wxStringToAnyHashMap
&metadata
) = 0;
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
276 virtual void ConstructObject(int objectID
,
277 const wxClassInfo
*classInfo
,
279 wxAny
*VariantValues
,
281 const wxClassInfo
**objectClassInfos
,
282 wxStringToAnyHashMap
&metadata
) = 0;
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
287 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) = 0;
289 // set the corresponding property
290 virtual void SetProperty(int objectID
,
291 const wxClassInfo
*classInfo
,
292 const wxPropertyInfo
* propertyInfo
,
293 const wxAny
&VariantValue
) = 0;
295 // sets the corresponding property (value is an object)
296 virtual void SetPropertyAsObject(int objectID
,
297 const wxClassInfo
*classInfo
,
298 const wxPropertyInfo
* propertyInfo
,
299 int valueObjectId
) = 0;
301 // adds an element to a property collection
302 virtual void AddToPropertyCollection( int objectID
,
303 const wxClassInfo
*classInfo
,
304 const wxPropertyInfo
* propertyInfo
,
305 const wxAny
&VariantValue
) = 0;
307 // sets the corresponding property (value is an object)
308 virtual void AddToPropertyCollectionAsObject(int objectID
,
309 const wxClassInfo
*classInfo
,
310 const wxPropertyInfo
* propertyInfo
,
311 int valueObjectId
) = 0;
313 // sets the corresponding event handler
314 virtual void SetConnect(int EventSourceObjectID
,
315 const wxClassInfo
*EventSourceClassInfo
,
316 const wxPropertyInfo
*delegateInfo
,
317 const wxClassInfo
*EventSinkClassInfo
,
318 const wxHandlerInfo
* handlerInfo
,
319 int EventSinkObjectID
) = 0;
323 wxObjectRuntimeReaderCallback implements the callbacks that will bring back
324 an object into a life memory instance
327 class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback
: public wxObjectReaderCallback
329 struct wxObjectRuntimeReaderCallbackInternal
;
330 wxObjectRuntimeReaderCallbackInternal
* m_data
;
333 wxObjectRuntimeReaderCallback();
334 virtual ~wxObjectRuntimeReaderCallback();
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 wxStringToAnyHashMap
&metadata
);
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
347 virtual void CreateObject(int objectID
,
348 const wxClassInfo
*classInfo
,
350 wxAny
*VariantValues
,
352 const wxClassInfo
**objectClassInfos
,
353 wxStringToAnyHashMap
&metadata
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
361 virtual void ConstructObject(int objectID
,
362 const wxClassInfo
*classInfo
,
364 wxAny
*VariantValues
,
366 const wxClassInfo
**objectClassInfos
,
367 wxStringToAnyHashMap
&metadata
);
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
);
374 // set the corresponding property
375 virtual void SetProperty(int objectID
,
376 const wxClassInfo
*classInfo
,
377 const wxPropertyInfo
* propertyInfo
,
378 const wxAny
&variantValue
);
380 // sets the corresponding property (value is an object)
381 virtual void SetPropertyAsObject(int objectId
,
382 const wxClassInfo
*classInfo
,
383 const wxPropertyInfo
* propertyInfo
,
386 // adds an element to a property collection
387 virtual void AddToPropertyCollection( int objectID
,
388 const wxClassInfo
*classInfo
,
389 const wxPropertyInfo
* propertyInfo
,
390 const wxAny
&VariantValue
);
392 // sets the corresponding property (value is an object)
393 virtual void AddToPropertyCollectionAsObject(int objectID
,
394 const wxClassInfo
*classInfo
,
395 const wxPropertyInfo
* propertyInfo
,
398 // sets the corresponding event handler
399 virtual void SetConnect(int eventSourceObjectID
,
400 const wxClassInfo
*eventSourceClassInfo
,
401 const wxPropertyInfo
*delegateInfo
,
402 const wxClassInfo
*eventSinkClassInfo
,
403 const wxHandlerInfo
* handlerInfo
,
404 int eventSinkObjectID
);
407 #endif // wxUSE_EXTENDED_RTTI