1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: streaming runtime metadata information (extended class info)
4 // Author: Stefan Csomor
7 // Copyright: (c) 2003 Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_XTISTRMH__
12 #define _WX_XTISTRMH__
16 #if wxUSE_EXTENDED_RTTI
18 #include "wx/object.h"
20 const int wxInvalidObjectID
= -2;
21 const int wxNullObjectID
= -3;
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
32 // ----------------------------------------------------------------------------
33 // wxObjectWriterCallback
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 // ----------------------------------------------------------------------------
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;
48 class WXDLLIMPEXP_BASE wxObjectWriter
;
49 class WXDLLIMPEXP_BASE wxObjectReader
;
51 class WXDLLIMPEXP_BASE wxObjectWriterCallback
54 virtual ~wxObjectWriterCallback() {}
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
))
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 const wxAny
&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 const wxAnyList
&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 wxObjectWriterFunctor
: public wxObjectFunctor
116 class WXDLLIMPEXP_BASE wxObjectWriter
: public wxObject
118 friend class wxObjectWriterFunctor
;
121 virtual ~wxObjectWriter();
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
);
128 // Managing the object identity table a.k.a context
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();
136 // gets the object Id for a passed in object in the context
137 int GetObjectID(const wxObject
*obj
);
139 // returns true if this object has already been written in this context
140 bool IsObjectKnown( const wxObject
*obj
);
143 // streaming callbacks
145 // these callbacks really write out the values in the stream format
147 // begins writing out a new toplevel entry which has the indicated unique name
148 virtual void DoBeginWriteTopLevelEntry( const wxString
&name
) = 0;
150 // ends writing out a new toplevel entry which has the indicated unique name
151 virtual void DoEndWriteTopLevelEntry( const wxString
&name
) = 0;
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;
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;
162 // writes a simple property in the stream format
163 virtual void DoWriteSimpleType( const wxAny
&value
) = 0;
165 // start of writing a complex property into the stream (
166 virtual void DoBeginWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
168 // end of writing a complex property into the stream
169 virtual void DoEndWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
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;
176 // insert a null reference
177 virtual void DoWriteNullObject() = 0;
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;
185 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
186 wxObjectWriterCallback
*writercallback
, bool isEmbedded
, const wxStringToAnyHashMap
&metadata
);
189 struct wxObjectWriterInternal
;
190 wxObjectWriterInternal
* m_data
;
192 struct wxObjectWriterInternalPropertiesData
;
194 void WriteAllProperties( const wxObject
* obj
, const wxClassInfo
* ci
,
195 wxObjectWriterCallback
*writercallback
,
196 wxObjectWriterInternalPropertiesData
* data
);
198 void WriteOneProperty( const wxObject
*obj
, const wxClassInfo
* ci
,
199 const wxPropertyInfo
* pi
, wxObjectWriterCallback
*writercallback
,
200 wxObjectWriterInternalPropertiesData
*data
);
203 void FindConnectEntry(const wxEvtHandler
* evSource
,
204 const wxEventSourceTypeInfo
* dti
, const wxObject
* &sink
,
205 const wxHandlerInfo
*&handler
);
210 Streaming callbacks for depersisting XML to code, or running objects
213 class WXDLLIMPEXP_BASE wxObjectReaderCallback
;
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.
221 class WXDLLIMPEXP_BASE wxObjectReader
: public wxObject
225 virtual ~wxObjectReader();
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
);
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;
240 struct wxObjectReaderInternal
;
241 wxObjectReaderInternal
*m_data
;
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.
249 class WXDLLIMPEXP_BASE wxObjectReaderCallback
252 virtual ~wxObjectReaderCallback() {}
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;
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
262 virtual void CreateObject(int objectID
,
263 const wxClassInfo
*classInfo
,
265 wxAny
*VariantValues
,
267 const wxClassInfo
**objectClassInfos
,
268 wxStringToAnyHashMap
&metadata
) = 0;
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
275 virtual void ConstructObject(int objectID
,
276 const wxClassInfo
*classInfo
,
278 wxAny
*VariantValues
,
280 const wxClassInfo
**objectClassInfos
,
281 wxStringToAnyHashMap
&metadata
) = 0;
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;
288 // set the corresponding property
289 virtual void SetProperty(int objectID
,
290 const wxClassInfo
*classInfo
,
291 const wxPropertyInfo
* propertyInfo
,
292 const wxAny
&VariantValue
) = 0;
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;
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;
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;
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;
322 wxObjectRuntimeReaderCallback implements the callbacks that will bring back
323 an object into a life memory instance
326 class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback
: public wxObjectReaderCallback
328 struct wxObjectRuntimeReaderCallbackInternal
;
329 wxObjectRuntimeReaderCallbackInternal
* m_data
;
332 wxObjectRuntimeReaderCallback();
333 virtual ~wxObjectRuntimeReaderCallback();
335 // returns the object having the corresponding ID fully constructed
336 wxObject
*GetObject(int objectID
);
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
);
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
346 virtual void CreateObject(int objectID
,
347 const wxClassInfo
*classInfo
,
349 wxAny
*VariantValues
,
351 const wxClassInfo
**objectClassInfos
,
352 wxStringToAnyHashMap
&metadata
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
360 virtual void ConstructObject(int objectID
,
361 const wxClassInfo
*classInfo
,
363 wxAny
*VariantValues
,
365 const wxClassInfo
**objectClassInfos
,
366 wxStringToAnyHashMap
&metadata
);
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
);
373 // set the corresponding property
374 virtual void SetProperty(int objectID
,
375 const wxClassInfo
*classInfo
,
376 const wxPropertyInfo
* propertyInfo
,
377 const wxAny
&variantValue
);
379 // sets the corresponding property (value is an object)
380 virtual void SetPropertyAsObject(int objectId
,
381 const wxClassInfo
*classInfo
,
382 const wxPropertyInfo
* propertyInfo
,
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
);
391 // sets the corresponding property (value is an object)
392 virtual void AddToPropertyCollectionAsObject(int objectID
,
393 const wxClassInfo
*classInfo
,
394 const wxPropertyInfo
* propertyInfo
,
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
);
406 #endif // wxUSE_EXTENDED_RTTI