]>
Commit | Line | Data |
---|---|---|
70e88103 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/xtistrm.h | |
3 | // Purpose: streaming runtime metadata information (extended class info) | |
4 | // Author: Stefan Csomor | |
cab1a605 | 5 | // Modified by: |
70e88103 SC |
6 | // Created: 27/07/03 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2003 Stefan Csomor | |
65571936 | 9 | // Licence: wxWindows licence |
70e88103 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_XTISTRMH__ | |
13 | #define _WX_XTISTRMH__ | |
14 | ||
28953245 | 15 | #include "wx/defs.h" |
70e88103 SC |
16 | |
17 | #if wxUSE_EXTENDED_RTTI | |
18 | ||
28953245 SC |
19 | #include "wx/string.h" |
20 | #include "wx/object.h" | |
21 | ||
22 | const int wxInvalidObjectID = -2; | |
23 | const int wxNullObjectID = -3; | |
8ec1974e | 24 | |
70e88103 SC |
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 | ||
70e88103 | 33 | |
ab6e4913 | 34 | // ---------------------------------------------------------------------------- |
28953245 | 35 | // wxObjectReaderCallback |
ab6e4913 SC |
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 | ||
28953245 SC |
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; | |
ab6e4913 | 50 | |
28953245 | 51 | class WXDLLIMPEXP_BASE wxObjectReaderCallback |
aa8d7c2f | 52 | { |
28953245 SC |
53 | public: |
54 | virtual ~wxObjectReaderCallback() {} | |
afc89ff4 | 55 | |
ab6e4913 | 56 | // will be called before an object is written, may veto by returning false |
28953245 SC |
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 | {} | |
ab6e4913 SC |
93 | |
94 | // will be called before this delegate gets written | |
28953245 SC |
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 | }; | |
aa8d7c2f | 111 | |
28953245 | 112 | class WXDLLIMPEXP_BASE wxObjectWriter: public wxObject |
aa8d7c2f | 113 | { |
28953245 SC |
114 | public: |
115 | wxObjectWriter(); | |
116 | virtual ~wxObjectWriter(); | |
aa8d7c2f SC |
117 | |
118 | // with this call you start writing out a new top-level object | |
28953245 SC |
119 | void WriteObject(const wxObject *object, const wxClassInfo *classInfo, |
120 | wxObjectReaderCallback *persister, const wxString &name, | |
121 | wxVariantBaseArray &WXUNUSED(metadata)); | |
aa8d7c2f | 122 | |
ab6e4913 SC |
123 | // Managing the object identity table a.k.a context |
124 | // | |
28953245 SC |
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(); | |
2abce515 | 130 | |
ab6e4913 | 131 | // gets the object Id for a passed in object in the context |
28953245 | 132 | int GetObjectID(const wxObject *obj); |
aa8d7c2f | 133 | |
ab6e4913 | 134 | // returns true if this object has already been written in this context |
28953245 | 135 | bool IsObjectKnown( const wxObject *obj ); |
aa8d7c2f SC |
136 | |
137 | // | |
138 | // streaming callbacks | |
139 | // | |
140 | // these callbacks really write out the values in the stream format | |
aa8d7c2f | 141 | |
ab6e4913 | 142 | // begins writing out a new toplevel entry which has the indicated unique name |
28953245 | 143 | virtual void DoBeginWriteTopLevelEntry( const wxString &name ) = 0; |
ab6e4913 SC |
144 | |
145 | // ends writing out a new toplevel entry which has the indicated unique name | |
28953245 | 146 | virtual void DoEndWriteTopLevelEntry( const wxString &name ) = 0; |
ab6e4913 SC |
147 | |
148 | // start of writing an object having the passed in ID | |
28953245 SC |
149 | virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, |
150 | int objectID, wxVariantBaseArray &metadata ) = 0; | |
aa8d7c2f | 151 | |
28953245 SC |
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; | |
ab6e4913 SC |
156 | |
157 | // writes a simple property in the stream format | |
28953245 | 158 | virtual void DoWriteSimpleType( wxVariantBase &value ) = 0; |
aa8d7c2f | 159 | |
ab6e4913 | 160 | // start of writing a complex property into the stream ( |
28953245 | 161 | virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) = 0; |
aa8d7c2f | 162 | |
ab6e4913 SC |
163 | // end of writing a complex property into the stream |
164 | virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) = 0; | |
aa8d7c2f | 165 | |
28953245 SC |
166 | virtual void DoBeginWriteElement() = 0; |
167 | virtual void DoEndWriteElement() = 0; | |
cab1a605 | 168 | // insert an object reference to an already written object |
28953245 | 169 | virtual void DoWriteRepeatedObject( int objectID ) = 0; |
aa8d7c2f | 170 | |
ab6e4913 | 171 | // insert a null reference |
28953245 | 172 | virtual void DoWriteNullObject() = 0; |
aa8d7c2f SC |
173 | |
174 | // writes a delegate in the stream format | |
28953245 SC |
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; | |
aa8d7c2f | 185 | |
28953245 SC |
186 | void WriteAllProperties( const wxObject * obj, const wxClassInfo* ci, |
187 | wxObjectReaderCallback *persister, | |
188 | wxObjectWriterInternalPropertiesData * data ); | |
aa8d7c2f | 189 | |
28953245 SC |
190 | void WriteOneProperty( const wxObject *obj, const wxClassInfo* ci, |
191 | const wxPropertyInfo* pi, wxObjectReaderCallback *persister, | |
192 | wxObjectWriterInternalPropertiesData *data ); | |
aa8d7c2f | 193 | |
28953245 SC |
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 | }; | |
aa8d7c2f | 201 | |
70e88103 | 202 | |
70e88103 | 203 | /* |
8ec1974e | 204 | Streaming callbacks for depersisting XML to code, or running objects |
70e88103 SC |
205 | */ |
206 | ||
28953245 | 207 | class WXDLLIMPEXP_BASE wxObjectWriterCallback; |
70e88103 SC |
208 | |
209 | /* | |
28953245 SC |
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. | |
70e88103 | 213 | */ |
8ec1974e | 214 | |
28953245 | 215 | class WXDLLIMPEXP_BASE wxObjectReader: public wxObject |
70e88103 | 216 | { |
28953245 SC |
217 | public: |
218 | wxObjectReader(); | |
219 | virtual ~wxObjectReader(); | |
aa8d7c2f | 220 | |
28953245 SC |
221 | // the only thing wxObjectReader knows about is the class info by object ID |
222 | wxClassInfo *GetObjectClassInfo(int objectID); | |
223 | bool HasObjectClassInfo( int objectID ); | |
8ec1974e SC |
224 | void SetObjectClassInfo(int objectID, wxClassInfo* classInfo); |
225 | ||
cab1a605 | 226 | // Reads the component the reader is pointed at from the underlying format. |
8ec1974e SC |
227 | // The return value is the root object ID, which can |
228 | // then be used to ask the depersister about that object | |
8f2b1cfd SC |
229 | // if there was a problem you will get back wxInvalidObjectID and the current |
230 | // error log will carry the problems encoutered | |
28953245 | 231 | virtual int ReadObject( const wxString &name, wxObjectWriterCallback *depersist ) = 0; |
8ec1974e | 232 | |
28953245 SC |
233 | private: |
234 | struct wxObjectReaderInternal; | |
235 | wxObjectReaderInternal *m_data; | |
236 | }; | |
8ec1974e | 237 | |
8ec1974e SC |
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 | ||
28953245 | 243 | class WXDLLIMPEXP_BASE wxObjectWriterCallback |
70e88103 | 244 | { |
28953245 SC |
245 | public: |
246 | virtual ~wxObjectWriterCallback() {} | |
afc89ff4 | 247 | |
8ec1974e | 248 | // allocate the new object on the heap, that object will have the passed in ID |
28953245 SC |
249 | virtual void AllocateObject(int objectID, wxClassInfo *classInfo, |
250 | wxVariantBaseArray &metadata) = 0; | |
8ec1974e | 251 | |
16a45a23 | 252 | // initialize the already allocated object having the ID objectID with the Create method |
8ec1974e SC |
253 | // creation parameters which are objects are having their Ids passed in objectIDValues |
254 | // having objectId <> wxInvalidObjectID | |
255 | ||
16a45a23 SC |
256 | virtual void CreateObject(int objectID, |
257 | const wxClassInfo *classInfo, | |
258 | int paramCount, | |
28953245 SC |
259 | wxVariantBase *VariantValues, |
260 | int *objectIDValues, | |
261 | const wxClassInfo **objectClassInfos, | |
262 | wxVariantBaseArray &metadata) = 0; | |
8ec1974e | 263 | |
28953245 SC |
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 | |
583150e3 SC |
268 | |
269 | virtual void ConstructObject(int objectID, | |
270 | const wxClassInfo *classInfo, | |
271 | int paramCount, | |
28953245 SC |
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 | |
16a45a23 | 280 | virtual void DestroyObject(int objectID, wxClassInfo *classInfo) = 0; |
8ec1974e SC |
281 | |
282 | // set the corresponding property | |
16a45a23 SC |
283 | virtual void SetProperty(int objectID, |
284 | const wxClassInfo *classInfo, | |
28953245 SC |
285 | const wxPropertyInfo* propertyInfo, |
286 | const wxVariantBase &VariantValue) = 0; | |
8ec1974e SC |
287 | |
288 | // sets the corresponding property (value is an object) | |
16a45a23 SC |
289 | virtual void SetPropertyAsObject(int objectID, |
290 | const wxClassInfo *classInfo, | |
28953245 | 291 | const wxPropertyInfo* propertyInfo, |
8ec1974e SC |
292 | int valueObjectId) = 0; |
293 | ||
16a45a23 | 294 | // adds an element to a property collection |
28953245 | 295 | virtual void AddToPropertyCollection( int objectID, |
16a45a23 | 296 | const wxClassInfo *classInfo, |
28953245 SC |
297 | const wxPropertyInfo* propertyInfo, |
298 | const wxVariantBase &VariantValue) = 0; | |
16a45a23 SC |
299 | |
300 | // sets the corresponding property (value is an object) | |
301 | virtual void AddToPropertyCollectionAsObject(int objectID, | |
302 | const wxClassInfo *classInfo, | |
28953245 | 303 | const wxPropertyInfo* propertyInfo, |
16a45a23 | 304 | int valueObjectId) = 0; |
8ec1974e SC |
305 | |
306 | // sets the corresponding event handler | |
70e88103 | 307 | virtual void SetConnect(int EventSourceObjectID, |
8ec1974e | 308 | const wxClassInfo *EventSourceClassInfo, |
28953245 SC |
309 | const wxPropertyInfo *delegateInfo, |
310 | const wxClassInfo *EventSinkClassInfo, | |
311 | const wxHandlerInfo* handlerInfo, | |
8ec1974e | 312 | int EventSinkObjectID ) = 0; |
70e88103 SC |
313 | }; |
314 | ||
315 | /* | |
28953245 | 316 | wxObjectRuntimeReaderCallback implements the callbacks that will depersist |
8ec1974e SC |
317 | an object into a running memory image, as opposed to writing |
318 | C++ initialization code to bring the object to life. | |
70e88103 | 319 | */ |
1c263d56 | 320 | |
28953245 | 321 | class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback: public wxObjectWriterCallback |
70e88103 | 322 | { |
28953245 SC |
323 | struct wxObjectRuntimeReaderCallbackInternal; |
324 | wxObjectRuntimeReaderCallbackInternal * m_data; | |
325 | ||
326 | public: | |
327 | wxObjectRuntimeReaderCallback(); | |
328 | virtual ~wxObjectRuntimeReaderCallback(); | |
8ec1974e | 329 | |
cab1a605 | 330 | // returns the object having the corresponding ID fully constructed |
28953245 | 331 | wxObject *GetObject(int objectID); |
8ec1974e SC |
332 | |
333 | // allocate the new object on the heap, that object will have the passed in ID | |
28953245 SC |
334 | virtual void AllocateObject(int objectID, wxClassInfo *classInfo, |
335 | wxVariantBaseArray &metadata); | |
8ec1974e | 336 | |
28953245 SC |
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 | |
8ec1974e | 340 | |
16a45a23 SC |
341 | virtual void CreateObject(int objectID, |
342 | const wxClassInfo *classInfo, | |
343 | int paramCount, | |
28953245 | 344 | wxVariantBase *VariantValues, |
8ec1974e | 345 | int *objectIDValues, |
28953245 SC |
346 | const wxClassInfo **objectClassInfos, |
347 | wxVariantBaseArray &metadata | |
348 | ); | |
8ec1974e | 349 | |
28953245 SC |
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 | |
583150e3 SC |
354 | |
355 | virtual void ConstructObject(int objectID, | |
356 | const wxClassInfo *classInfo, | |
357 | int paramCount, | |
28953245 | 358 | wxVariantBase *VariantValues, |
8ec1974e | 359 | int *objectIDValues, |
28953245 SC |
360 | const wxClassInfo **objectClassInfos, |
361 | wxVariantBaseArray &metadata); | |
583150e3 | 362 | |
28953245 SC |
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); | |
8ec1974e SC |
367 | |
368 | // set the corresponding property | |
369 | virtual void SetProperty(int objectID, | |
370 | const wxClassInfo *classInfo, | |
28953245 SC |
371 | const wxPropertyInfo* propertyInfo, |
372 | const wxVariantBase &variantValue); | |
8ec1974e SC |
373 | |
374 | // sets the corresponding property (value is an object) | |
375 | virtual void SetPropertyAsObject(int objectId, | |
376 | const wxClassInfo *classInfo, | |
28953245 SC |
377 | const wxPropertyInfo* propertyInfo, |
378 | int valueObjectId); | |
8ec1974e | 379 | |
16a45a23 | 380 | // adds an element to a property collection |
28953245 | 381 | virtual void AddToPropertyCollection( int objectID, |
16a45a23 | 382 | const wxClassInfo *classInfo, |
28953245 SC |
383 | const wxPropertyInfo* propertyInfo, |
384 | const wxVariantBase &VariantValue); | |
16a45a23 SC |
385 | |
386 | // sets the corresponding property (value is an object) | |
387 | virtual void AddToPropertyCollectionAsObject(int objectID, | |
388 | const wxClassInfo *classInfo, | |
28953245 SC |
389 | const wxPropertyInfo* propertyInfo, |
390 | int valueObjectId); | |
8ec1974e SC |
391 | |
392 | // sets the corresponding event handler | |
393 | virtual void SetConnect(int eventSourceObjectID, | |
394 | const wxClassInfo *eventSourceClassInfo, | |
28953245 SC |
395 | const wxPropertyInfo *delegateInfo, |
396 | const wxClassInfo *eventSinkClassInfo, | |
397 | const wxHandlerInfo* handlerInfo, | |
398 | int eventSinkObjectID ); | |
70e88103 SC |
399 | }; |
400 | ||
401 | #endif // wxUSE_EXTENDED_RTTI | |
402 | ||
12028905 | 403 | #endif |