]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xtistrm.h
merging back XTI branch part 2
[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/string.h"
20 #include "wx/object.h"
21
22 const int wxInvalidObjectID = -2;
23 const int wxNullObjectID = -3;
24
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
31 // listed below.
32
33
34 // ----------------------------------------------------------------------------
35 // wxObjectReaderCallback
36 //
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 // ----------------------------------------------------------------------------
41
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;
50
51 class WXDLLIMPEXP_BASE wxObjectReaderCallback
52 {
53 public:
54 virtual ~wxObjectReaderCallback() {}
55
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))
61 { return true; }
62
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) )
68 {}
69
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) )
77 { return true; }
78
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) )
86 { return true; }
87
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) )
92 {}
93
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) )
101 { return true; }
102
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) )
109 { }
110 };
111
112 class WXDLLIMPEXP_BASE wxObjectWriter: public wxObject
113 {
114 public:
115 wxObjectWriter();
116 virtual ~wxObjectWriter();
117
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));
122
123 // Managing the object identity table a.k.a context
124 //
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();
130
131 // gets the object Id for a passed in object in the context
132 int GetObjectID(const wxObject *obj);
133
134 // returns true if this object has already been written in this context
135 bool IsObjectKnown( const wxObject *obj );
136
137 //
138 // streaming callbacks
139 //
140 // these callbacks really write out the values in the stream format
141
142 // begins writing out a new toplevel entry which has the indicated unique name
143 virtual void DoBeginWriteTopLevelEntry( const wxString &name ) = 0;
144
145 // ends writing out a new toplevel entry which has the indicated unique name
146 virtual void DoEndWriteTopLevelEntry( const wxString &name ) = 0;
147
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;
151
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;
156
157 // writes a simple property in the stream format
158 virtual void DoWriteSimpleType( wxVariantBase &value ) = 0;
159
160 // start of writing a complex property into the stream (
161 virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) = 0;
162
163 // end of writing a complex property into the stream
164 virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) = 0;
165
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;
170
171 // insert a null reference
172 virtual void DoWriteNullObject() = 0;
173
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;
179
180 private:
181 struct wxObjectWriterInternal;
182 wxObjectWriterInternal* m_data;
183
184 struct wxObjectWriterInternalPropertiesData;
185
186 void WriteAllProperties( const wxObject * obj, const wxClassInfo* ci,
187 wxObjectReaderCallback *persister,
188 wxObjectWriterInternalPropertiesData * data );
189
190 void WriteOneProperty( const wxObject *obj, const wxClassInfo* ci,
191 const wxPropertyInfo* pi, wxObjectReaderCallback *persister,
192 wxObjectWriterInternalPropertiesData *data );
193
194 void WriteObject(const wxObject *object, const wxClassInfo *classInfo,
195 wxObjectReaderCallback *persister, bool isEmbedded, wxVariantBaseArray &metadata );
196
197 void FindConnectEntry(const wxEvtHandler * evSource,
198 const wxEventSourceTypeInfo* dti, const wxObject* &sink,
199 const wxHandlerInfo *&handler);
200 };
201
202
203 /*
204 Streaming callbacks for depersisting XML to code, or running objects
205 */
206
207 class WXDLLIMPEXP_BASE wxObjectWriterCallback;
208
209 /*
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.
213 */
214
215 class WXDLLIMPEXP_BASE wxObjectReader: public wxObject
216 {
217 public:
218 wxObjectReader();
219 virtual ~wxObjectReader();
220
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);
225
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;
232
233 private:
234 struct wxObjectReaderInternal;
235 wxObjectReaderInternal *m_data;
236 };
237
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.
242
243 class WXDLLIMPEXP_BASE wxObjectWriterCallback
244 {
245 public:
246 virtual ~wxObjectWriterCallback() {}
247
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;
251
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
255
256 virtual void CreateObject(int objectID,
257 const wxClassInfo *classInfo,
258 int paramCount,
259 wxVariantBase *VariantValues,
260 int *objectIDValues,
261 const wxClassInfo **objectClassInfos,
262 wxVariantBaseArray &metadata) = 0;
263
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
268
269 virtual void ConstructObject(int objectID,
270 const wxClassInfo *classInfo,
271 int paramCount,
272 wxVariantBase *VariantValues,
273 int *objectIDValues,
274 const wxClassInfo **objectClassInfos,
275 wxVariantBaseArray &metadata) = 0;
276
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;
281
282 // set the corresponding property
283 virtual void SetProperty(int objectID,
284 const wxClassInfo *classInfo,
285 const wxPropertyInfo* propertyInfo,
286 const wxVariantBase &VariantValue) = 0;
287
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;
293
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;
299
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;
305
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;
313 };
314
315 /*
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.
319 */
320
321 class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback: public wxObjectWriterCallback
322 {
323 struct wxObjectRuntimeReaderCallbackInternal;
324 wxObjectRuntimeReaderCallbackInternal * m_data;
325
326 public:
327 wxObjectRuntimeReaderCallback();
328 virtual ~wxObjectRuntimeReaderCallback();
329
330 // returns the object having the corresponding ID fully constructed
331 wxObject *GetObject(int objectID);
332
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);
336
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
340
341 virtual void CreateObject(int objectID,
342 const wxClassInfo *classInfo,
343 int paramCount,
344 wxVariantBase *VariantValues,
345 int *objectIDValues,
346 const wxClassInfo **objectClassInfos,
347 wxVariantBaseArray &metadata
348 );
349
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
354
355 virtual void ConstructObject(int objectID,
356 const wxClassInfo *classInfo,
357 int paramCount,
358 wxVariantBase *VariantValues,
359 int *objectIDValues,
360 const wxClassInfo **objectClassInfos,
361 wxVariantBaseArray &metadata);
362
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);
367
368 // set the corresponding property
369 virtual void SetProperty(int objectID,
370 const wxClassInfo *classInfo,
371 const wxPropertyInfo* propertyInfo,
372 const wxVariantBase &variantValue);
373
374 // sets the corresponding property (value is an object)
375 virtual void SetPropertyAsObject(int objectId,
376 const wxClassInfo *classInfo,
377 const wxPropertyInfo* propertyInfo,
378 int valueObjectId);
379
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);
385
386 // sets the corresponding property (value is an object)
387 virtual void AddToPropertyCollectionAsObject(int objectID,
388 const wxClassInfo *classInfo,
389 const wxPropertyInfo* propertyInfo,
390 int valueObjectId);
391
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 );
399 };
400
401 #endif // wxUSE_EXTENDED_RTTI
402
403 #endif