]>
Commit | Line | Data |
---|---|---|
70e88103 SC |
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 | ||
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
70e88103 SC |
16 | #pragma interface "xtistrm.h" |
17 | #endif | |
18 | ||
19 | #include "wx/wx.h" | |
20 | ||
21 | #if wxUSE_EXTENDED_RTTI | |
22 | ||
8ec1974e SC |
23 | const int wxInvalidObjectID = -2 ; |
24 | const int wxNullObjectID = -1 ; | |
25 | ||
70e88103 SC |
26 | // Filer contains the interfaces for streaming objects in and out of XML, |
27 | // rendering them either to objects in memory, or to code. Note: We | |
28 | // consider the process of generating code to be one of *depersisting* the | |
29 | // object from xml, *not* of persisting the object to code from an object | |
30 | // in memory. This distincation can be confusing, and should be kept | |
31 | // in mind when looking at the property streamers and callback interfaces | |
32 | // listed below. | |
33 | ||
34 | /* | |
aa8d7c2f | 35 | Main interfaces for streaming out objects. |
70e88103 SC |
36 | */ |
37 | ||
ab6e4913 SC |
38 | // ---------------------------------------------------------------------------- |
39 | // wxPersister | |
40 | // | |
41 | // This class will be asked during the streaming-out process about every single | |
42 | // property or object instance. It can veto streaming out by returning false | |
43 | // or modify the value before it is streamed-out. | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
46 | class wxWriter ; | |
47 | class wxReader ; | |
48 | ||
aa8d7c2f SC |
49 | class wxPersister |
50 | { | |
51 | public : | |
ab6e4913 | 52 | // will be called before an object is written, may veto by returning false |
4f8ffae1 | 53 | virtual bool BeforeWriteObject( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) , wxxVariantArray &WXUNUSED(metadata)) { return true ; } |
ab6e4913 SC |
54 | |
55 | // will be called after this object has been written, may be needed for adjusting stacks | |
56 | virtual void AfterWriteObject( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) ) {} | |
aa8d7c2f SC |
57 | |
58 | // will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( -1 , -1 ) or veto | |
59 | // writing that property at all by returning false | |
ab6e4913 | 60 | virtual bool BeforeWriteProperty( wxWriter *WXUNUSED(writer) , const wxPropertyInfo *WXUNUSED(propInfo) , wxxVariant &WXUNUSED(value) ) { return true ; } |
aa8d7c2f | 61 | |
ab6e4913 | 62 | // will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( -1 , -1 ) or veto |
aa8d7c2f | 63 | // writing that property at all by returning false |
ab6e4913 SC |
64 | virtual bool BeforeWriteProperty( wxWriter *WXUNUSED(writer) , const wxPropertyInfo *WXUNUSED(propInfo) , wxxVariantArray &WXUNUSED(value) ) { return true ; } |
65 | ||
66 | // will be called after a property has been written out, may be needed for adjusting stacks | |
67 | virtual void AfterWriteProperty( wxWriter *WXUNUSED(writer) , const wxPropertyInfo *WXUNUSED(propInfo) ) {} | |
68 | ||
69 | // will be called before this delegate gets written | |
70 | virtual bool BeforeWriteDelegate( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object), const wxClassInfo* WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) , | |
71 | const wxObject *&WXUNUSED(eventSink) , const wxHandlerInfo* &WXUNUSED(handlerInfo) ) { return true ; } | |
aa8d7c2f | 72 | |
2abce515 SC |
73 | virtual void AfterWriteDelegate( wxWriter *WXUNUSED(writer) , const wxObject *WXUNUSED(object), const wxClassInfo* WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) , |
74 | const wxObject *&WXUNUSED(eventSink) , const wxHandlerInfo* &WXUNUSED(handlerInfo) ) { } | |
aa8d7c2f SC |
75 | } ; |
76 | ||
77 | class wxWriter : public wxObject | |
78 | { | |
79 | public : | |
80 | wxWriter() ; | |
81 | ~wxWriter() ; | |
82 | ||
83 | // with this call you start writing out a new top-level object | |
4f8ffae1 | 84 | void WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name , wxxVariantArray &WXUNUSED(metadata)) ; |
aa8d7c2f | 85 | |
ab6e4913 SC |
86 | // |
87 | // Managing the object identity table a.k.a context | |
88 | // | |
89 | // these methods make sure that no object gets written twice, because sometimes multiple calls to the WriteObject will be | |
90 | // made without wanting to have duplicate objects written, the object identity table will be reset manually | |
91 | ||
92 | virtual void ClearObjectContext() ; | |
2abce515 | 93 | |
ab6e4913 | 94 | // gets the object Id for a passed in object in the context |
aa8d7c2f | 95 | int GetObjectID(const wxObject *obj) ; |
aa8d7c2f | 96 | |
ab6e4913 SC |
97 | // returns true if this object has already been written in this context |
98 | bool IsObjectKnown( const wxObject *obj ) ; | |
aa8d7c2f SC |
99 | |
100 | // | |
101 | // streaming callbacks | |
102 | // | |
103 | // these callbacks really write out the values in the stream format | |
aa8d7c2f | 104 | |
ab6e4913 SC |
105 | // begins writing out a new toplevel entry which has the indicated unique name |
106 | virtual void DoBeginWriteTopLevelEntry( const wxString &name ) = 0 ; | |
107 | ||
108 | // ends writing out a new toplevel entry which has the indicated unique name | |
109 | virtual void DoEndWriteTopLevelEntry( const wxString &name ) = 0 ; | |
110 | ||
111 | // start of writing an object having the passed in ID | |
4f8ffae1 | 112 | virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , wxxVariantArray &metadata ) = 0 ; |
aa8d7c2f SC |
113 | |
114 | // end of writing an toplevel object name param is used for unique identification within the container | |
ab6e4913 SC |
115 | virtual void DoEndWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID ) = 0 ; |
116 | ||
117 | // writes a simple property in the stream format | |
118 | virtual void DoWriteSimpleType( wxxVariant &value ) = 0 ; | |
aa8d7c2f | 119 | |
ab6e4913 SC |
120 | // start of writing a complex property into the stream ( |
121 | virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) = 0 ; | |
aa8d7c2f | 122 | |
ab6e4913 SC |
123 | // end of writing a complex property into the stream |
124 | virtual void DoEndWriteProperty( const wxPropertyInfo *propInfo ) = 0; | |
aa8d7c2f | 125 | |
ab6e4913 SC |
126 | virtual void DoBeginWriteElement() = 0 ; |
127 | virtual void DoEndWriteElement() = 0 ; | |
128 | // insert an object reference to an already written object | |
129 | virtual void DoWriteRepeatedObject( int objectID ) = 0 ; | |
aa8d7c2f | 130 | |
ab6e4913 SC |
131 | // insert a null reference |
132 | virtual void DoWriteNullObject() = 0 ; | |
aa8d7c2f SC |
133 | |
134 | // writes a delegate in the stream format | |
135 | virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo , | |
136 | const wxObject *eventSink , int sinkObjectID , const wxClassInfo* eventSinkClassInfo , const wxHandlerInfo* handlerIndo ) = 0; | |
137 | private : | |
138 | ||
139 | struct wxWriterInternal ; | |
140 | wxWriterInternal* m_data ; | |
141 | ||
142 | struct wxWriterInternalPropertiesData ; | |
143 | ||
144 | void WriteAllProperties( const wxObject * obj , const wxClassInfo* ci , wxPersister *persister, wxWriterInternalPropertiesData * data ) ; | |
ae820c69 | 145 | void WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , const wxPropertyInfo* pi , wxPersister *persister , wxWriterInternalPropertiesData *data ) ; |
4f8ffae1 | 146 | void WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , bool isEmbedded, wxxVariantArray &metadata ) ; |
9c8046dd | 147 | void FindConnectEntry(const wxEvtHandler * evSource,const wxDelegateTypeInfo* dti, const wxObject* &sink , const wxHandlerInfo *&handler) ; |
aa8d7c2f SC |
148 | } ; |
149 | ||
70e88103 | 150 | |
70e88103 | 151 | /* |
8ec1974e | 152 | Streaming callbacks for depersisting XML to code, or running objects |
70e88103 SC |
153 | */ |
154 | ||
8ec1974e | 155 | class wxDepersister ; |
70e88103 SC |
156 | |
157 | /* | |
8ec1974e SC |
158 | wxReader handles streaming in a class from a arbitrary format. While walking through |
159 | it issues calls out to interfaces to depersist the guts from the underlying storage format. | |
70e88103 | 160 | */ |
8ec1974e SC |
161 | |
162 | class wxReader : public wxObject | |
70e88103 | 163 | { |
8ec1974e SC |
164 | public : |
165 | wxReader() ; | |
166 | ~wxReader() ; | |
aa8d7c2f | 167 | |
8ec1974e SC |
168 | // the only thing wxReader knows about is the class info by object ID |
169 | wxClassInfo *GetObjectClassInfo(int objectID) ; | |
170 | bool HasObjectClassInfo( int objectID ) ; | |
171 | void SetObjectClassInfo(int objectID, wxClassInfo* classInfo); | |
172 | ||
173 | // Reads the component the reader is pointed at from the underlying format. | |
174 | // The return value is the root object ID, which can | |
175 | // then be used to ask the depersister about that object | |
ab6e4913 | 176 | virtual int ReadObject( const wxString &name , wxDepersister *depersist ) = 0 ; |
8ec1974e SC |
177 | |
178 | private : | |
70e88103 | 179 | struct wxReaderInternal; |
8ec1974e SC |
180 | wxReaderInternal *m_data; |
181 | } ; | |
182 | ||
8ec1974e SC |
183 | // This abstract class matches the allocate-init/create model of creation of objects. |
184 | // At runtime, these will create actual instances, and manipulate them. | |
185 | // When generating code, these will just create statements of C++ | |
186 | // code to create the objects. | |
187 | ||
188 | class wxDepersister | |
70e88103 | 189 | { |
8ec1974e SC |
190 | public : |
191 | // allocate the new object on the heap, that object will have the passed in ID | |
4f8ffae1 | 192 | virtual void AllocateObject(int objectID, wxClassInfo *classInfo, wxxVariantArray &metadata) = 0; |
8ec1974e | 193 | |
16a45a23 | 194 | // initialize the already allocated object having the ID objectID with the Create method |
8ec1974e SC |
195 | // creation parameters which are objects are having their Ids passed in objectIDValues |
196 | // having objectId <> wxInvalidObjectID | |
197 | ||
16a45a23 SC |
198 | virtual void CreateObject(int objectID, |
199 | const wxClassInfo *classInfo, | |
200 | int paramCount, | |
8ec1974e SC |
201 | wxxVariant *VariantValues , |
202 | int *objectIDValues , | |
4f8ffae1 SC |
203 | const wxClassInfo **objectClassInfos , |
204 | wxxVariantArray &metadata) = 0; | |
8ec1974e | 205 | |
16a45a23 | 206 | // destroy the heap-allocated object having the ID objectID, this may be used if an object |
8ec1974e SC |
207 | // is embedded in another object and set via value semantics, so the intermediate |
208 | // object can be destroyed after safely | |
16a45a23 | 209 | virtual void DestroyObject(int objectID, wxClassInfo *classInfo) = 0; |
8ec1974e SC |
210 | |
211 | // set the corresponding property | |
16a45a23 SC |
212 | virtual void SetProperty(int objectID, |
213 | const wxClassInfo *classInfo, | |
214 | const wxPropertyInfo* propertyInfo , | |
8ec1974e SC |
215 | const wxxVariant &VariantValue) = 0; |
216 | ||
217 | // sets the corresponding property (value is an object) | |
16a45a23 SC |
218 | virtual void SetPropertyAsObject(int objectID, |
219 | const wxClassInfo *classInfo, | |
220 | const wxPropertyInfo* propertyInfo , | |
8ec1974e SC |
221 | int valueObjectId) = 0; |
222 | ||
16a45a23 SC |
223 | // adds an element to a property collection |
224 | virtual void AddToPropertyCollection( int objectID , | |
225 | const wxClassInfo *classInfo, | |
226 | const wxPropertyInfo* propertyInfo , | |
227 | const wxxVariant &VariantValue) = 0; | |
228 | ||
229 | // sets the corresponding property (value is an object) | |
230 | virtual void AddToPropertyCollectionAsObject(int objectID, | |
231 | const wxClassInfo *classInfo, | |
232 | const wxPropertyInfo* propertyInfo , | |
233 | int valueObjectId) = 0; | |
8ec1974e SC |
234 | |
235 | // sets the corresponding event handler | |
70e88103 | 236 | virtual void SetConnect(int EventSourceObjectID, |
8ec1974e SC |
237 | const wxClassInfo *EventSourceClassInfo, |
238 | const wxDelegateTypeInfo *delegateInfo , | |
239 | const wxClassInfo *EventSinkClassInfo , | |
240 | const wxHandlerInfo* handlerInfo , | |
241 | int EventSinkObjectID ) = 0; | |
70e88103 SC |
242 | }; |
243 | ||
244 | /* | |
8ec1974e SC |
245 | wxRuntimeDepersister implements the callbacks that will depersist |
246 | an object into a running memory image, as opposed to writing | |
247 | C++ initialization code to bring the object to life. | |
70e88103 | 248 | */ |
8ec1974e | 249 | class wxRuntimeDepersister : public wxDepersister |
70e88103 | 250 | { |
8ec1974e SC |
251 | struct wxRuntimeDepersisterInternal ; |
252 | wxRuntimeDepersisterInternal * m_data ; | |
253 | public : | |
254 | wxRuntimeDepersister() ; | |
255 | ~wxRuntimeDepersister() ; | |
256 | ||
257 | // returns the object having the corresponding ID fully constructed | |
258 | wxObject *GetObject(int objectID) ; | |
259 | ||
260 | // allocate the new object on the heap, that object will have the passed in ID | |
4f8ffae1 SC |
261 | virtual void AllocateObject(int objectID, wxClassInfo *classInfo , |
262 | wxxVariantArray &metadata) ; | |
8ec1974e | 263 | |
16a45a23 | 264 | // initialize the already allocated object having the ID objectID with the Create method |
8ec1974e SC |
265 | // creation parameters which are objects are having their Ids passed in objectIDValues |
266 | // having objectId <> wxInvalidObjectID | |
267 | ||
16a45a23 SC |
268 | virtual void CreateObject(int objectID, |
269 | const wxClassInfo *classInfo, | |
270 | int paramCount, | |
8ec1974e SC |
271 | wxxVariant *VariantValues , |
272 | int *objectIDValues, | |
4f8ffae1 SC |
273 | const wxClassInfo **objectClassInfos , |
274 | wxxVariantArray &metadata | |
8ec1974e SC |
275 | ) ; |
276 | ||
16a45a23 | 277 | // destroy the heap-allocated object having the ID objectID, this may be used if an object |
8ec1974e SC |
278 | // is embedded in another object and set via value semantics, so the intermediate |
279 | // object can be destroyed after safely | |
280 | virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ; | |
281 | ||
282 | // set the corresponding property | |
283 | virtual void SetProperty(int objectID, | |
284 | const wxClassInfo *classInfo, | |
285 | const wxPropertyInfo* propertyInfo , | |
286 | const wxxVariant &variantValue); | |
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) ; | |
293 | ||
16a45a23 SC |
294 | // adds an element to a property collection |
295 | virtual void AddToPropertyCollection( int objectID , | |
296 | const wxClassInfo *classInfo, | |
297 | const wxPropertyInfo* propertyInfo , | |
298 | const wxxVariant &VariantValue) ; | |
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) ; | |
8ec1974e SC |
305 | |
306 | // sets the corresponding event handler | |
307 | virtual void SetConnect(int eventSourceObjectID, | |
308 | const wxClassInfo *eventSourceClassInfo, | |
309 | const wxDelegateTypeInfo *delegateInfo , | |
310 | const wxClassInfo *eventSinkClassInfo , | |
311 | const wxHandlerInfo* handlerInfo , | |
312 | int eventSinkObjectID ) ; | |
70e88103 SC |
313 | }; |
314 | ||
315 | /* | |
8ec1974e SC |
316 | wxDepersisterCode implements the callbacks that will depersist |
317 | an object into a C++ initialization function. | |
70e88103 SC |
318 | */ |
319 | ||
320 | class wxTextOutputStream ; | |
321 | ||
8ec1974e | 322 | class wxCodeDepersister : public wxDepersister |
70e88103 | 323 | { |
8ec1974e SC |
324 | private : |
325 | struct wxCodeDepersisterInternal ; | |
326 | wxCodeDepersisterInternal * m_data ; | |
327 | wxTextOutputStream *m_fp; | |
328 | wxString ValueAsCode( const wxxVariant ¶m ) ; | |
70e88103 | 329 | public: |
8ec1974e SC |
330 | wxCodeDepersister(wxTextOutputStream *out) ; |
331 | ~wxCodeDepersister() ; | |
332 | ||
333 | // allocate the new object on the heap, that object will have the passed in ID | |
4f8ffae1 SC |
334 | virtual void AllocateObject(int objectID, wxClassInfo *classInfo , |
335 | wxxVariantArray &metadata) ; | |
8ec1974e | 336 | |
16a45a23 | 337 | // initialize the already allocated object having the ID objectID with the Create method |
8ec1974e SC |
338 | // creation parameters which are objects are having their Ids passed in objectIDValues |
339 | // having objectId <> wxInvalidObjectID | |
340 | ||
341 | virtual void CreateObject(int objectID, | |
342 | const wxClassInfo *classInfo, | |
343 | int paramCount, | |
344 | wxxVariant *variantValues , | |
345 | int *objectIDValues, | |
4f8ffae1 SC |
346 | const wxClassInfo **objectClassInfos , |
347 | wxxVariantArray &metadata | |
8ec1974e SC |
348 | ) ; |
349 | ||
16a45a23 | 350 | // destroy the heap-allocated object having the ID objectID, this may be used if an object |
8ec1974e SC |
351 | // is embedded in another object and set via value semantics, so the intermediate |
352 | // object can be destroyed after safely | |
353 | virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ; | |
354 | ||
355 | // set the corresponding property | |
356 | virtual void SetProperty(int objectID, | |
357 | const wxClassInfo *classInfo, | |
358 | const wxPropertyInfo* propertyInfo , | |
359 | const wxxVariant &variantValue); | |
360 | ||
361 | // sets the corresponding property (value is an object) | |
362 | virtual void SetPropertyAsObject(int objectId, | |
363 | const wxClassInfo *classInfo, | |
364 | const wxPropertyInfo* propertyInfo , | |
365 | int valueObjectId) ; | |
366 | ||
16a45a23 SC |
367 | // adds an element to a property collection |
368 | virtual void AddToPropertyCollection( int objectID , | |
369 | const wxClassInfo *classInfo, | |
370 | const wxPropertyInfo* propertyInfo , | |
371 | const wxxVariant &VariantValue) ; | |
372 | ||
373 | // sets the corresponding property (value is an object) | |
374 | virtual void AddToPropertyCollectionAsObject(int objectID, | |
375 | const wxClassInfo *classInfo, | |
376 | const wxPropertyInfo* propertyInfo , | |
377 | int valueObjectId) ; | |
8ec1974e SC |
378 | |
379 | // sets the corresponding event handler | |
380 | virtual void SetConnect(int eventSourceObjectID, | |
381 | const wxClassInfo *eventSourceClassInfo, | |
382 | const wxDelegateTypeInfo *delegateInfo , | |
383 | const wxClassInfo *eventSinkClassInfo , | |
384 | const wxHandlerInfo* handlerInfo , | |
385 | int eventSinkObjectID ) ; | |
70e88103 SC |
386 | }; |
387 | ||
388 | #endif // wxUSE_EXTENDED_RTTI | |
389 | ||
12028905 | 390 | #endif |