]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xtistrm.h
0876b9d5f91977e57605395f457a9b754444159b
[wxWidgets.git] / include / wx / xtistrm.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/xtistrm.h
3 // Purpose: streaming runtime metadata information (extended class info)
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 27/07/03
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_XTISTRMH__
13 #define _WX_XTISTRMH__
14
15 #include "wx/defs.h"
16
17 #if wxUSE_EXTENDED_RTTI
18
19 #include "wx/object.h"
20
21 const int wxInvalidObjectID = -2;
22 const int wxNullObjectID = -3;
23
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
30 // listed below.
31
32
33 // ----------------------------------------------------------------------------
34 // wxObjectWriterCallback
35 //
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 // ----------------------------------------------------------------------------
40
41 /*
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;
47 */
48
49 class WXDLLIMPEXP_BASE wxObjectWriter;
50 class WXDLLIMPEXP_BASE wxObjectReader;
51
52 class WXDLLIMPEXP_BASE wxObjectWriterCallback
53 {
54 public:
55 virtual ~wxObjectWriterCallback() {}
56
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))
62 { return true; }
63
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) )
69 {}
70
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) )
78 { return true; }
79
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) )
87 { return true; }
88
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) )
93 {}
94
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) )
102 { return true; }
103
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) )
110 { }
111 };
112
113 class WXDLLIMPEXP_BASE wxObjectWriterFunctor: public wxObjectFunctor
114 {
115 };
116
117 class WXDLLIMPEXP_BASE wxObjectWriter: public wxObject
118 {
119 friend class wxObjectWriterFunctor;
120 public:
121 wxObjectWriter();
122 virtual ~wxObjectWriter();
123
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);
128
129 // Managing the object identity table a.k.a context
130 //
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();
136
137 // gets the object Id for a passed in object in the context
138 int GetObjectID(const wxObject *obj);
139
140 // returns true if this object has already been written in this context
141 bool IsObjectKnown( const wxObject *obj );
142
143 //
144 // streaming callbacks
145 //
146 // these callbacks really write out the values in the stream format
147
148 // begins writing out a new toplevel entry which has the indicated unique name
149 virtual void DoBeginWriteTopLevelEntry( const wxString &name ) = 0;
150
151 // ends writing out a new toplevel entry which has the indicated unique name
152 virtual void DoEndWriteTopLevelEntry( const wxString &name ) = 0;
153
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;
157
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;
162
163 // writes a simple property in the stream format
164 virtual void DoWriteSimpleType( const wxAny &value ) = 0;
165
166 // start of writing a complex property into the stream (
167 virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) = 0;
168
169 // end of writing a complex property into the stream
170 virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) = 0;
171
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;
176
177 // insert a null reference
178 virtual void DoWriteNullObject() = 0;
179
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;
185
186 void WriteObject(const wxObject *object, const wxClassInfo *classInfo,
187 wxObjectWriterCallback *writercallback, bool isEmbedded, const wxStringToAnyHashMap &metadata );
188
189 protected:
190 struct wxObjectWriterInternal;
191 wxObjectWriterInternal* m_data;
192
193 struct wxObjectWriterInternalPropertiesData;
194
195 void WriteAllProperties( const wxObject * obj, const wxClassInfo* ci,
196 wxObjectWriterCallback *writercallback,
197 wxObjectWriterInternalPropertiesData * data );
198
199 void WriteOneProperty( const wxObject *obj, const wxClassInfo* ci,
200 const wxPropertyInfo* pi, wxObjectWriterCallback *writercallback,
201 wxObjectWriterInternalPropertiesData *data );
202
203
204 void FindConnectEntry(const wxEvtHandler * evSource,
205 const wxEventSourceTypeInfo* dti, const wxObject* &sink,
206 const wxHandlerInfo *&handler);
207 };
208
209
210 /*
211 Streaming callbacks for depersisting XML to code, or running objects
212 */
213
214 class WXDLLIMPEXP_BASE wxObjectReaderCallback;
215
216 /*
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.
220 */
221
222 class WXDLLIMPEXP_BASE wxObjectReader: public wxObject
223 {
224 public:
225 wxObjectReader();
226 virtual ~wxObjectReader();
227
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);
232
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;
239
240 private:
241 struct wxObjectReaderInternal;
242 wxObjectReaderInternal *m_data;
243 };
244
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.
249
250 class WXDLLIMPEXP_BASE wxObjectReaderCallback
251 {
252 public:
253 virtual ~wxObjectReaderCallback() {}
254
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;
258
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
262
263 virtual void CreateObject(int objectID,
264 const wxClassInfo *classInfo,
265 int paramCount,
266 wxAny *VariantValues,
267 int *objectIDValues,
268 const wxClassInfo **objectClassInfos,
269 wxStringToAnyHashMap &metadata) = 0;
270
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
275
276 virtual void ConstructObject(int objectID,
277 const wxClassInfo *classInfo,
278 int paramCount,
279 wxAny *VariantValues,
280 int *objectIDValues,
281 const wxClassInfo **objectClassInfos,
282 wxStringToAnyHashMap &metadata) = 0;
283
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;
288
289 // set the corresponding property
290 virtual void SetProperty(int objectID,
291 const wxClassInfo *classInfo,
292 const wxPropertyInfo* propertyInfo,
293 const wxAny &VariantValue) = 0;
294
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;
300
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;
306
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;
312
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;
320 };
321
322 /*
323 wxObjectRuntimeReaderCallback implements the callbacks that will bring back
324 an object into a life memory instance
325 */
326
327 class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback: public wxObjectReaderCallback
328 {
329 struct wxObjectRuntimeReaderCallbackInternal;
330 wxObjectRuntimeReaderCallbackInternal * m_data;
331
332 public:
333 wxObjectRuntimeReaderCallback();
334 virtual ~wxObjectRuntimeReaderCallback();
335
336 // returns the object having the corresponding ID fully constructed
337 wxObject *GetObject(int objectID);
338
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);
342
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
346
347 virtual void CreateObject(int objectID,
348 const wxClassInfo *classInfo,
349 int paramCount,
350 wxAny *VariantValues,
351 int *objectIDValues,
352 const wxClassInfo **objectClassInfos,
353 wxStringToAnyHashMap &metadata
354 );
355
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
360
361 virtual void ConstructObject(int objectID,
362 const wxClassInfo *classInfo,
363 int paramCount,
364 wxAny *VariantValues,
365 int *objectIDValues,
366 const wxClassInfo **objectClassInfos,
367 wxStringToAnyHashMap &metadata);
368
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);
373
374 // set the corresponding property
375 virtual void SetProperty(int objectID,
376 const wxClassInfo *classInfo,
377 const wxPropertyInfo* propertyInfo,
378 const wxAny &variantValue);
379
380 // sets the corresponding property (value is an object)
381 virtual void SetPropertyAsObject(int objectId,
382 const wxClassInfo *classInfo,
383 const wxPropertyInfo* propertyInfo,
384 int valueObjectId);
385
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);
391
392 // sets the corresponding property (value is an object)
393 virtual void AddToPropertyCollectionAsObject(int objectID,
394 const wxClassInfo *classInfo,
395 const wxPropertyInfo* propertyInfo,
396 int valueObjectId);
397
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 );
405 };
406
407 #endif // wxUSE_EXTENDED_RTTI
408
409 #endif