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 // ----------------------------------------------------------------------------
41 class WXDLLIMPEXP_BASE wxObjectWriter
;
42 class WXDLLIMPEXP_BASE wxObjectReader
;
43 class WXDLLIMPEXP_BASE wxClassInfo
;
44 class WXDLLIMPEXP_BASE wxAnyList
;
45 class WXDLLIMPEXP_BASE wxPropertyInfo
;
46 class WXDLLIMPEXP_BASE wxAny
;
47 class WXDLLIMPEXP_BASE wxObjectWriter
;
48 class WXDLLIMPEXP_BASE wxHandlerInfo
;
50 class WXDLLIMPEXP_BASE wxObjectWriterCallback
53 virtual ~wxObjectWriterCallback() {}
55 // will be called before an object is written, may veto by returning false
56 virtual bool BeforeWriteObject( wxObjectWriter
*WXUNUSED(writer
),
57 const wxObject
*WXUNUSED(object
),
58 const wxClassInfo
*WXUNUSED(classInfo
),
59 const wxStringToAnyHashMap
&WXUNUSED(metadata
))
62 // will be called after this object has been written, may be
63 // needed for adjusting stacks
64 virtual void AfterWriteObject( wxObjectWriter
*WXUNUSED(writer
),
65 const wxObject
*WXUNUSED(object
),
66 const wxClassInfo
*WXUNUSED(classInfo
) )
69 // will be called before a property gets written, may change the value,
70 // eg replace a concrete wxSize by wxSize( wxDefaultCoord, wxDefaultCoord )
71 // or veto writing that property at all by returning false
72 virtual bool BeforeWriteProperty( wxObjectWriter
*WXUNUSED(writer
),
73 const wxObject
*WXUNUSED(object
),
74 const wxPropertyInfo
*WXUNUSED(propInfo
),
75 const wxAny
&WXUNUSED(value
) )
78 // will be called before a property gets written, may change the value,
79 // eg replace a concrete wxSize by wxSize( wxDefaultCoord, wxDefaultCoord )
80 // or veto writing that property at all by returning false
81 virtual bool BeforeWriteProperty( wxObjectWriter
*WXUNUSED(writer
),
82 const wxObject
*WXUNUSED(object
),
83 const wxPropertyInfo
*WXUNUSED(propInfo
),
84 const wxAnyList
&WXUNUSED(value
) )
87 // will be called after a property has been written out, may be needed
88 // for adjusting stacks
89 virtual void AfterWriteProperty( wxObjectWriter
*WXUNUSED(writer
),
90 const wxPropertyInfo
*WXUNUSED(propInfo
) )
93 // will be called before this delegate gets written
94 virtual bool BeforeWriteDelegate( wxObjectWriter
*WXUNUSED(writer
),
95 const wxObject
*WXUNUSED(object
),
96 const wxClassInfo
* WXUNUSED(classInfo
),
97 const wxPropertyInfo
*WXUNUSED(propInfo
),
98 const wxObject
*&WXUNUSED(eventSink
),
99 const wxHandlerInfo
* &WXUNUSED(handlerInfo
) )
102 virtual void AfterWriteDelegate( wxObjectWriter
*WXUNUSED(writer
),
103 const wxObject
*WXUNUSED(object
),
104 const wxClassInfo
* WXUNUSED(classInfo
),
105 const wxPropertyInfo
*WXUNUSED(propInfo
),
106 const wxObject
*&WXUNUSED(eventSink
),
107 const wxHandlerInfo
* &WXUNUSED(handlerInfo
) )
111 class WXDLLIMPEXP_BASE wxObjectWriterFunctor
: public wxObjectFunctor
115 class WXDLLIMPEXP_BASE wxObjectWriter
: public wxObject
117 friend class wxObjectWriterFunctor
;
120 virtual ~wxObjectWriter();
122 // with this call you start writing out a new top-level object
123 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
124 wxObjectWriterCallback
*writercallback
, const wxString
&name
,
125 const wxStringToAnyHashMap
&metadata
);
127 // Managing the object identity table a.k.a context
129 // these methods make sure that no object gets written twice,
130 // because sometimes multiple calls to the WriteObject will be
131 // made without wanting to have duplicate objects written, the
132 // object identity table will be reset manually
133 virtual void ClearObjectContext();
135 // gets the object Id for a passed in object in the context
136 int GetObjectID(const wxObject
*obj
);
138 // returns true if this object has already been written in this context
139 bool IsObjectKnown( const wxObject
*obj
);
142 // streaming callbacks
144 // these callbacks really write out the values in the stream format
146 // begins writing out a new toplevel entry which has the indicated unique name
147 virtual void DoBeginWriteTopLevelEntry( const wxString
&name
) = 0;
149 // ends writing out a new toplevel entry which has the indicated unique name
150 virtual void DoEndWriteTopLevelEntry( const wxString
&name
) = 0;
152 // start of writing an object having the passed in ID
153 virtual void DoBeginWriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
154 int objectID
, const wxStringToAnyHashMap
&metadata
) = 0;
156 // end of writing an toplevel object name param is used for unique
157 // identification within the container
158 virtual void DoEndWriteObject(const wxObject
*object
,
159 const wxClassInfo
*classInfo
, int objectID
) = 0;
161 // writes a simple property in the stream format
162 virtual void DoWriteSimpleType( const wxAny
&value
) = 0;
164 // start of writing a complex property into the stream (
165 virtual void DoBeginWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
167 // end of writing a complex property into the stream
168 virtual void DoEndWriteProperty( const wxPropertyInfo
*propInfo
) = 0;
170 virtual void DoBeginWriteElement() = 0;
171 virtual void DoEndWriteElement() = 0;
172 // insert an object reference to an already written object
173 virtual void DoWriteRepeatedObject( int objectID
) = 0;
175 // insert a null reference
176 virtual void DoWriteNullObject() = 0;
178 // writes a delegate in the stream format
179 virtual void DoWriteDelegate( const wxObject
*object
, const wxClassInfo
* classInfo
,
180 const wxPropertyInfo
*propInfo
, const wxObject
*eventSink
,
181 int sinkObjectID
, const wxClassInfo
* eventSinkClassInfo
,
182 const wxHandlerInfo
* handlerIndo
) = 0;
184 void WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
,
185 wxObjectWriterCallback
*writercallback
, bool isEmbedded
, const wxStringToAnyHashMap
&metadata
);
188 struct wxObjectWriterInternal
;
189 wxObjectWriterInternal
* m_data
;
191 struct wxObjectWriterInternalPropertiesData
;
193 void WriteAllProperties( const wxObject
* obj
, const wxClassInfo
* ci
,
194 wxObjectWriterCallback
*writercallback
,
195 wxObjectWriterInternalPropertiesData
* data
);
197 void WriteOneProperty( const wxObject
*obj
, const wxClassInfo
* ci
,
198 const wxPropertyInfo
* pi
, wxObjectWriterCallback
*writercallback
,
199 wxObjectWriterInternalPropertiesData
*data
);
202 void FindConnectEntry(const wxEvtHandler
* evSource
,
203 const wxEventSourceTypeInfo
* dti
, const wxObject
* &sink
,
204 const wxHandlerInfo
*&handler
);
209 Streaming callbacks for depersisting XML to code, or running objects
212 class WXDLLIMPEXP_BASE wxObjectReaderCallback
;
215 wxObjectReader handles streaming in a class from a arbitrary format.
216 While walking through it issues calls out to interfaces to readercallback
217 the guts from the underlying storage format.
220 class WXDLLIMPEXP_BASE wxObjectReader
: public wxObject
224 virtual ~wxObjectReader();
226 // the only thing wxObjectReader knows about is the class info by object ID
227 wxClassInfo
*GetObjectClassInfo(int objectID
);
228 bool HasObjectClassInfo( int objectID
);
229 void SetObjectClassInfo(int objectID
, wxClassInfo
* classInfo
);
231 // Reads the component the reader is pointed at from the underlying format.
232 // The return value is the root object ID, which can
233 // then be used to ask the depersister about that object
234 // if there was a problem you will get back wxInvalidObjectID and the current
235 // error log will carry the problems encoutered
236 virtual int ReadObject( const wxString
&name
, wxObjectReaderCallback
*readercallback
) = 0;
239 struct wxObjectReaderInternal
;
240 wxObjectReaderInternal
*m_data
;
243 // This abstract class matches the allocate-init/create model of creation of objects.
244 // At runtime, these will create actual instances, and manipulate them.
245 // When generating code, these will just create statements of C++
246 // code to create the objects.
248 class WXDLLIMPEXP_BASE wxObjectReaderCallback
251 virtual ~wxObjectReaderCallback() {}
253 // allocate the new object on the heap, that object will have the passed in ID
254 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
,
255 wxStringToAnyHashMap
&metadata
) = 0;
257 // initialize the already allocated object having the ID objectID with the Create method
258 // creation parameters which are objects are having their Ids passed in objectIDValues
259 // having objectId <> wxInvalidObjectID
261 virtual void CreateObject(int objectID
,
262 const wxClassInfo
*classInfo
,
264 wxAny
*VariantValues
,
266 const wxClassInfo
**objectClassInfos
,
267 wxStringToAnyHashMap
&metadata
) = 0;
269 // construct the new object on the heap, that object will have the passed in ID
270 // (for objects that don't support allocate-create type of creation)
271 // creation parameters which are objects are having their Ids passed in
272 // objectIDValues having objectId <> wxInvalidObjectID
274 virtual void ConstructObject(int objectID
,
275 const wxClassInfo
*classInfo
,
277 wxAny
*VariantValues
,
279 const wxClassInfo
**objectClassInfos
,
280 wxStringToAnyHashMap
&metadata
) = 0;
282 // destroy the heap-allocated object having the ID objectID, this may be used
283 // if an object is embedded in another object and set via value semantics,
284 // so the intermediate object can be destroyed after safely
285 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) = 0;
287 // set the corresponding property
288 virtual void SetProperty(int objectID
,
289 const wxClassInfo
*classInfo
,
290 const wxPropertyInfo
* propertyInfo
,
291 const wxAny
&VariantValue
) = 0;
293 // sets the corresponding property (value is an object)
294 virtual void SetPropertyAsObject(int objectID
,
295 const wxClassInfo
*classInfo
,
296 const wxPropertyInfo
* propertyInfo
,
297 int valueObjectId
) = 0;
299 // adds an element to a property collection
300 virtual void AddToPropertyCollection( int objectID
,
301 const wxClassInfo
*classInfo
,
302 const wxPropertyInfo
* propertyInfo
,
303 const wxAny
&VariantValue
) = 0;
305 // sets the corresponding property (value is an object)
306 virtual void AddToPropertyCollectionAsObject(int objectID
,
307 const wxClassInfo
*classInfo
,
308 const wxPropertyInfo
* propertyInfo
,
309 int valueObjectId
) = 0;
311 // sets the corresponding event handler
312 virtual void SetConnect(int EventSourceObjectID
,
313 const wxClassInfo
*EventSourceClassInfo
,
314 const wxPropertyInfo
*delegateInfo
,
315 const wxClassInfo
*EventSinkClassInfo
,
316 const wxHandlerInfo
* handlerInfo
,
317 int EventSinkObjectID
) = 0;
321 wxObjectRuntimeReaderCallback implements the callbacks that will bring back
322 an object into a life memory instance
325 class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback
: public wxObjectReaderCallback
327 struct wxObjectRuntimeReaderCallbackInternal
;
328 wxObjectRuntimeReaderCallbackInternal
* m_data
;
331 wxObjectRuntimeReaderCallback();
332 virtual ~wxObjectRuntimeReaderCallback();
334 // returns the object having the corresponding ID fully constructed
335 wxObject
*GetObject(int objectID
);
337 // allocate the new object on the heap, that object will have the passed in ID
338 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
,
339 wxStringToAnyHashMap
&metadata
);
341 // initialize the already allocated object having the ID objectID with
342 // the Create method creation parameters which are objects are having
343 // their Ids passed in objectIDValues having objectId <> wxInvalidObjectID
345 virtual void CreateObject(int objectID
,
346 const wxClassInfo
*classInfo
,
348 wxAny
*VariantValues
,
350 const wxClassInfo
**objectClassInfos
,
351 wxStringToAnyHashMap
&metadata
354 // construct the new object on the heap, that object will have the
355 // passed in ID (for objects that don't support allocate-create type of
356 // creation) creation parameters which are objects are having their Ids
357 // passed in objectIDValues having objectId <> wxInvalidObjectID
359 virtual void ConstructObject(int objectID
,
360 const wxClassInfo
*classInfo
,
362 wxAny
*VariantValues
,
364 const wxClassInfo
**objectClassInfos
,
365 wxStringToAnyHashMap
&metadata
);
367 // destroy the heap-allocated object having the ID objectID, this may be
368 // used if an object is embedded in another object and set via value semantics,
369 // so the intermediate object can be destroyed after safely
370 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
);
372 // set the corresponding property
373 virtual void SetProperty(int objectID
,
374 const wxClassInfo
*classInfo
,
375 const wxPropertyInfo
* propertyInfo
,
376 const wxAny
&variantValue
);
378 // sets the corresponding property (value is an object)
379 virtual void SetPropertyAsObject(int objectId
,
380 const wxClassInfo
*classInfo
,
381 const wxPropertyInfo
* propertyInfo
,
384 // adds an element to a property collection
385 virtual void AddToPropertyCollection( int objectID
,
386 const wxClassInfo
*classInfo
,
387 const wxPropertyInfo
* propertyInfo
,
388 const wxAny
&VariantValue
);
390 // sets the corresponding property (value is an object)
391 virtual void AddToPropertyCollectionAsObject(int objectID
,
392 const wxClassInfo
*classInfo
,
393 const wxPropertyInfo
* propertyInfo
,
396 // sets the corresponding event handler
397 virtual void SetConnect(int eventSourceObjectID
,
398 const wxClassInfo
*eventSourceClassInfo
,
399 const wxPropertyInfo
*delegateInfo
,
400 const wxClassInfo
*eventSinkClassInfo
,
401 const wxHandlerInfo
* handlerInfo
,
402 int eventSinkObjectID
);
405 #endif // wxUSE_EXTENDED_RTTI