]> git.saurik.com Git - wxWidgets.git/blame - include/wx/xtistrm.h
check if we are using compatible C++ ABI when usin GCC or IntelC++
[wxWidgets.git] / include / wx / xtistrm.h
CommitLineData
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
23const int wxInvalidObjectID = -2 ;
24const 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 35Main interfaces for streaming out objects.
70e88103
SC
36*/
37
aa8d7c2f
SC
38class wxPersister
39{
40public :
41 // will be called before a toplevel object is written, may veto even that (eg for objects that cannot be supported) by returning false
42 virtual bool BeforeWriteObject( const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) , const wxString &WXUNUSED(name)) { return true ; }
43
44 // will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( -1 , -1 ) or veto
45 // writing that property at all by returning false
46 virtual bool BeforeWriteProperty( const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) , wxxVariant &WXUNUSED(value) ) { return true ; }
47
48 // will be called before a property with an object value gets written, may change the value , eg replace the instance, void it or veto
49 // writing that property at all by returning false
50 virtual bool BeforeWritePropertyAsObject( const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) , wxxVariant &WXUNUSED(value) ) { return true ; }
51
52 // will be called before a delegate property gets written, you may change all informations about the event sink
53 virtual bool BeforeWriteDelegate( const wxObject *WXUNUSED(object), const wxClassInfo* WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) ,
54 const wxObject *&WXUNUSED(eventSink) , const wxHandlerInfo* &WXUNUSED(handlerInfo) ) { return true ; }
55} ;
56
57class wxWriter : public wxObject
58{
59public :
60 wxWriter() ;
61 ~wxWriter() ;
62
63 // with this call you start writing out a new top-level object
64 void WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name ) ;
65
66 int GetObjectID(const wxObject *obj) ;
67 bool IsObjectKnown( const wxObject *obj ) ;
68
69
70 //
71 // streaming callbacks
72 //
73 // these callbacks really write out the values in the stream format
74 //
75
76 // start of writing an toplevel object name param is used for unique identification within the container
77 virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , const wxString &name ) = 0 ;
78
79 // end of writing an toplevel object name param is used for unique identification within the container
80 virtual void DoEndWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , const wxString &name ) = 0 ;
81
82 // start of writing an object used as param
83 virtual void DoBeginWriteParamAsObject(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
84 const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) = 0 ;
85
86 // end of writing an object used as param
87 virtual void DoEndWriteParamAsObject(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
88 const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) = 0 ;
89
90 // insert an object reference to an already written object
91 virtual void DoWriteObjectReference(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
92 const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) = 0 ;
93
94 // writes a property in the stream format
95 virtual void DoWriteProperty( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo , wxxVariant &value ) = 0 ;
96
97 // writes a delegate in the stream format
98 virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo ,
99 const wxObject *eventSink , int sinkObjectID , const wxClassInfo* eventSinkClassInfo , const wxHandlerInfo* handlerIndo ) = 0;
100private :
101
102 struct wxWriterInternal ;
103 wxWriterInternal* m_data ;
104
105 struct wxWriterInternalPropertiesData ;
106
107 void WriteAllProperties( const wxObject * obj , const wxClassInfo* ci , wxPersister *persister, wxWriterInternalPropertiesData * data ) ;
108} ;
109
110class wxXmlWriter : public wxWriter
111{
112public :
113
114 wxXmlWriter( wxXmlNode * parent ) ;
115 ~wxXmlWriter() ;
116
117 //
118 // streaming callbacks
119 //
120 // these callbacks really write out the values in the stream format
121 //
122
123 // start of writing an toplevel object name param is used for unique identification within the container
124 virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , const wxString &name ) ;
125
126 // end of writing an toplevel object name param is used for unique identification within the container
127 virtual void DoEndWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , const wxString &name ) ;
128
129 // start of writing an object used as param
130 virtual void DoBeginWriteParamAsObject(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
131 const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) ;
132
133 // end of writing an object used as param
134 virtual void DoEndWriteParamAsObject(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
135 const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) ;
136
137 // insert an object reference to an already written object or to a null object
138 virtual void DoWriteObjectReference(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
139 const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) ;
140
141 // writes a property in the stream format
142 virtual void DoWriteProperty( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo , wxxVariant &value ) ;
143
144 // writes a delegate in the stream format
145 virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo ,
146 const wxObject *eventSink, int sinkObjectID , const wxClassInfo* eventSinkClassInfo , const wxHandlerInfo* handlerInfo ) ;
147private :
148 struct wxXmlWriterInternal ;
149 wxXmlWriterInternal* m_data ;
150} ;
70e88103 151
70e88103 152/*
8ec1974e 153Streaming callbacks for depersisting XML to code, or running objects
70e88103
SC
154*/
155
8ec1974e 156class wxDepersister ;
70e88103
SC
157
158/*
8ec1974e
SC
159wxReader handles streaming in a class from a arbitrary format. While walking through
160it issues calls out to interfaces to depersist the guts from the underlying storage format.
70e88103 161*/
8ec1974e
SC
162
163class wxReader : public wxObject
70e88103 164{
8ec1974e
SC
165public :
166 wxReader() ;
167 ~wxReader() ;
aa8d7c2f 168
8ec1974e
SC
169 // the only thing wxReader knows about is the class info by object ID
170 wxClassInfo *GetObjectClassInfo(int objectID) ;
171 bool HasObjectClassInfo( int objectID ) ;
172 void SetObjectClassInfo(int objectID, wxClassInfo* classInfo);
173
174 // Reads the component the reader is pointed at from the underlying format.
175 // The return value is the root object ID, which can
176 // then be used to ask the depersister about that object
177 virtual int ReadObject( wxDepersister *depersist ) = 0 ;
178
179private :
70e88103 180 struct wxReaderInternal;
8ec1974e
SC
181 wxReaderInternal *m_data;
182} ;
183
184/*
185wxXmlReader handles streaming in a class from XML
186*/
187
188class wxXmlReader : public wxReader
189{
70e88103 190public:
8ec1974e
SC
191 wxXmlReader(wxXmlNode *parent) { m_parent = parent ; }
192 ~wxXmlReader() {}
193
194 // Reads a component from XML. The return value is the root object ID, which can
195 // then be used to ask the depersister about that object
196
197 int ReadObject(wxDepersister *callbacks);
198
199private :
200 int ReadComponent(wxXmlNode *parent, wxDepersister *callbacks);
201
202 // accessor is only used as a temporary measure
203 wxxVariant ReadValue(wxXmlNode *Node,
204 wxPropertyAccessor *accessor );
205
206 wxXmlNode * m_parent ;
70e88103
SC
207};
208
8ec1974e
SC
209// This abstract class matches the allocate-init/create model of creation of objects.
210// At runtime, these will create actual instances, and manipulate them.
211// When generating code, these will just create statements of C++
212// code to create the objects.
213
214class wxDepersister
70e88103 215{
8ec1974e
SC
216public :
217 // allocate the new object on the heap, that object will have the passed in ID
70e88103 218 virtual void AllocateObject(int ObjectID, wxClassInfo *ClassInfo) = 0;
8ec1974e
SC
219
220 // initialize the already allocated object having the ID ObjectID with the Create method
221 // creation parameters which are objects are having their Ids passed in objectIDValues
222 // having objectId <> wxInvalidObjectID
223
70e88103 224 virtual void CreateObject(int ObjectID,
8ec1974e
SC
225 const wxClassInfo *ClassInfo,
226 int ParamCount,
227 wxxVariant *VariantValues ,
228 int *objectIDValues ,
229 const wxClassInfo **objectClassInfos
230 ) = 0;
231
232 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
233 // is embedded in another object and set via value semantics, so the intermediate
234 // object can be destroyed after safely
235 virtual void DestroyObject(int ObjectID, wxClassInfo *ClassInfo) = 0;
236
237 // set the corresponding property
70e88103 238 virtual void SetProperty(int ObjectID,
8ec1974e
SC
239 const wxClassInfo *ClassInfo,
240 const wxPropertyInfo* PropertyInfo ,
241 const wxxVariant &VariantValue) = 0;
242
243 // sets the corresponding property (value is an object)
244 virtual void SetPropertyAsObject(int ObjectId,
245 const wxClassInfo *ClassInfo,
246 const wxPropertyInfo* PropertyInfo ,
247 int valueObjectId) = 0;
248
249
250 // sets the corresponding event handler
70e88103 251 virtual void SetConnect(int EventSourceObjectID,
8ec1974e
SC
252 const wxClassInfo *EventSourceClassInfo,
253 const wxDelegateTypeInfo *delegateInfo ,
254 const wxClassInfo *EventSinkClassInfo ,
255 const wxHandlerInfo* handlerInfo ,
256 int EventSinkObjectID ) = 0;
70e88103
SC
257};
258
259/*
8ec1974e
SC
260wxRuntimeDepersister implements the callbacks that will depersist
261an object into a running memory image, as opposed to writing
262C++ initialization code to bring the object to life.
70e88103 263*/
8ec1974e 264class wxRuntimeDepersister : public wxDepersister
70e88103 265{
8ec1974e
SC
266 struct wxRuntimeDepersisterInternal ;
267 wxRuntimeDepersisterInternal * m_data ;
268public :
269 wxRuntimeDepersister() ;
270 ~wxRuntimeDepersister() ;
271
272 // returns the object having the corresponding ID fully constructed
273 wxObject *GetObject(int objectID) ;
274
275 // allocate the new object on the heap, that object will have the passed in ID
276 virtual void AllocateObject(int objectID, wxClassInfo *classInfo) ;
277
278 // initialize the already allocated object having the ID ObjectID with the Create method
279 // creation parameters which are objects are having their Ids passed in objectIDValues
280 // having objectId <> wxInvalidObjectID
281
282 virtual void CreateObject(int ObjectID,
283 const wxClassInfo *ClassInfo,
284 int ParamCount,
285 wxxVariant *VariantValues ,
286 int *objectIDValues,
287 const wxClassInfo **objectClassInfos
288 ) ;
289
290 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
291 // is embedded in another object and set via value semantics, so the intermediate
292 // object can be destroyed after safely
293 virtual void DestroyObject(int objectID, wxClassInfo *classInfo) ;
294
295 // set the corresponding property
296 virtual void SetProperty(int objectID,
297 const wxClassInfo *classInfo,
298 const wxPropertyInfo* propertyInfo ,
299 const wxxVariant &variantValue);
300
301 // sets the corresponding property (value is an object)
302 virtual void SetPropertyAsObject(int objectId,
303 const wxClassInfo *classInfo,
304 const wxPropertyInfo* propertyInfo ,
305 int valueObjectId) ;
306
307
308 // sets the corresponding event handler
309 virtual void SetConnect(int eventSourceObjectID,
310 const wxClassInfo *eventSourceClassInfo,
311 const wxDelegateTypeInfo *delegateInfo ,
312 const wxClassInfo *eventSinkClassInfo ,
313 const wxHandlerInfo* handlerInfo ,
314 int eventSinkObjectID ) ;
70e88103
SC
315};
316
317/*
8ec1974e
SC
318wxDepersisterCode implements the callbacks that will depersist
319an object into a C++ initialization function.
70e88103
SC
320*/
321
322class wxTextOutputStream ;
323
8ec1974e 324class wxCodeDepersister : public wxDepersister
70e88103 325{
8ec1974e
SC
326private :
327 struct wxCodeDepersisterInternal ;
328 wxCodeDepersisterInternal * m_data ;
329 wxTextOutputStream *m_fp;
330 wxString ValueAsCode( const wxxVariant &param ) ;
70e88103 331public:
8ec1974e
SC
332 wxCodeDepersister(wxTextOutputStream *out) ;
333 ~wxCodeDepersister() ;
334
335 // allocate the new object on the heap, that object will have the passed in ID
336 virtual void AllocateObject(int objectID, wxClassInfo *classInfo) ;
337
338 // initialize the already allocated object having the ID ObjectID with the Create method
339 // creation parameters which are objects are having their Ids passed in objectIDValues
340 // having objectId <> wxInvalidObjectID
341
342 virtual void CreateObject(int objectID,
343 const wxClassInfo *classInfo,
344 int paramCount,
345 wxxVariant *variantValues ,
346 int *objectIDValues,
347 const wxClassInfo **objectClassInfos
348 ) ;
349
350 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
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
367
368 // sets the corresponding event handler
369 virtual void SetConnect(int eventSourceObjectID,
370 const wxClassInfo *eventSourceClassInfo,
371 const wxDelegateTypeInfo *delegateInfo ,
372 const wxClassInfo *eventSinkClassInfo ,
373 const wxHandlerInfo* handlerInfo ,
374 int eventSinkObjectID ) ;
70e88103
SC
375};
376
377#endif // wxUSE_EXTENDED_RTTI
378
12028905 379#endif