1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: streaming runtime metadata information (extended class info)
4 // Author: Stefan Csomor
8 // Copyright: (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_XTISTRMH__
13 #define _WX_XTISTRMH__
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "xtistrm.h"
21 #if wxUSE_EXTENDED_RTTI
23 const int wxInvalidObjectID
= -2 ;
24 const int wxNullObjectID
= -1 ;
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
35 Main interface for streaming out an object to XML.
38 void WriteComponent(wxObject
*Object
, const wxClassInfo
*ClassInfo
, wxXmlNode
*parent
, const wxString
& nodeName
);
41 Streaming callbacks for depersisting XML to code, or running objects
47 wxReader handles streaming in a class from a arbitrary format. While walking through
48 it issues calls out to interfaces to depersist the guts from the underlying storage format.
51 class wxReader
: public wxObject
56 // the only thing wxReader knows about is the class info by object ID
57 wxClassInfo
*GetObjectClassInfo(int objectID
) ;
58 bool HasObjectClassInfo( int objectID
) ;
59 void SetObjectClassInfo(int objectID
, wxClassInfo
* classInfo
);
61 // Reads the component the reader is pointed at from the underlying format.
62 // The return value is the root object ID, which can
63 // then be used to ask the depersister about that object
64 virtual int ReadObject( wxDepersister
*depersist
) = 0 ;
67 struct wxReaderInternal
;
68 wxReaderInternal
*m_data
;
72 wxXmlReader handles streaming in a class from XML
75 class wxXmlReader
: public wxReader
78 wxXmlReader(wxXmlNode
*parent
) { m_parent
= parent
; }
81 // Reads a component from XML. The return value is the root object ID, which can
82 // then be used to ask the depersister about that object
84 int ReadObject(wxDepersister
*callbacks
);
87 int ReadComponent(wxXmlNode
*parent
, wxDepersister
*callbacks
);
89 // accessor is only used as a temporary measure
90 wxxVariant
ReadValue(wxXmlNode
*Node
,
91 wxPropertyAccessor
*accessor
);
93 wxXmlNode
* m_parent
;
96 // This abstract class matches the allocate-init/create model of creation of objects.
97 // At runtime, these will create actual instances, and manipulate them.
98 // When generating code, these will just create statements of C++
99 // code to create the objects.
104 // allocate the new object on the heap, that object will have the passed in ID
105 virtual void AllocateObject(int ObjectID
, wxClassInfo
*ClassInfo
) = 0;
107 // initialize the already allocated object having the ID ObjectID with the Create method
108 // creation parameters which are objects are having their Ids passed in objectIDValues
109 // having objectId <> wxInvalidObjectID
111 virtual void CreateObject(int ObjectID
,
112 const wxClassInfo
*ClassInfo
,
114 wxxVariant
*VariantValues
,
115 int *objectIDValues
,
116 const wxClassInfo
**objectClassInfos
119 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
120 // is embedded in another object and set via value semantics, so the intermediate
121 // object can be destroyed after safely
122 virtual void DestroyObject(int ObjectID
, wxClassInfo
*ClassInfo
) = 0;
124 // set the corresponding property
125 virtual void SetProperty(int ObjectID
,
126 const wxClassInfo
*ClassInfo
,
127 const wxPropertyInfo
* PropertyInfo
,
128 const wxxVariant
&VariantValue
) = 0;
130 // sets the corresponding property (value is an object)
131 virtual void SetPropertyAsObject(int ObjectId
,
132 const wxClassInfo
*ClassInfo
,
133 const wxPropertyInfo
* PropertyInfo
,
134 int valueObjectId
) = 0;
137 // sets the corresponding event handler
138 virtual void SetConnect(int EventSourceObjectID
,
139 const wxClassInfo
*EventSourceClassInfo
,
140 const wxDelegateTypeInfo
*delegateInfo
,
141 const wxClassInfo
*EventSinkClassInfo
,
142 const wxHandlerInfo
* handlerInfo
,
143 int EventSinkObjectID
) = 0;
147 wxRuntimeDepersister implements the callbacks that will depersist
148 an object into a running memory image, as opposed to writing
149 C++ initialization code to bring the object to life.
151 class wxRuntimeDepersister
: public wxDepersister
153 struct wxRuntimeDepersisterInternal
;
154 wxRuntimeDepersisterInternal
* m_data
;
156 wxRuntimeDepersister() ;
157 ~wxRuntimeDepersister() ;
159 // returns the object having the corresponding ID fully constructed
160 wxObject
*GetObject(int objectID
) ;
162 // allocate the new object on the heap, that object will have the passed in ID
163 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
) ;
165 // initialize the already allocated object having the ID ObjectID with the Create method
166 // creation parameters which are objects are having their Ids passed in objectIDValues
167 // having objectId <> wxInvalidObjectID
169 virtual void CreateObject(int ObjectID
,
170 const wxClassInfo
*ClassInfo
,
172 wxxVariant
*VariantValues
,
174 const wxClassInfo
**objectClassInfos
177 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
178 // is embedded in another object and set via value semantics, so the intermediate
179 // object can be destroyed after safely
180 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) ;
182 // set the corresponding property
183 virtual void SetProperty(int objectID
,
184 const wxClassInfo
*classInfo
,
185 const wxPropertyInfo
* propertyInfo
,
186 const wxxVariant
&variantValue
);
188 // sets the corresponding property (value is an object)
189 virtual void SetPropertyAsObject(int objectId
,
190 const wxClassInfo
*classInfo
,
191 const wxPropertyInfo
* propertyInfo
,
195 // sets the corresponding event handler
196 virtual void SetConnect(int eventSourceObjectID
,
197 const wxClassInfo
*eventSourceClassInfo
,
198 const wxDelegateTypeInfo
*delegateInfo
,
199 const wxClassInfo
*eventSinkClassInfo
,
200 const wxHandlerInfo
* handlerInfo
,
201 int eventSinkObjectID
) ;
205 wxDepersisterCode implements the callbacks that will depersist
206 an object into a C++ initialization function.
209 class wxTextOutputStream
;
211 class wxCodeDepersister
: public wxDepersister
214 struct wxCodeDepersisterInternal
;
215 wxCodeDepersisterInternal
* m_data
;
216 wxTextOutputStream
*m_fp
;
217 wxString
ValueAsCode( const wxxVariant
¶m
) ;
219 wxCodeDepersister(wxTextOutputStream
*out
) ;
220 ~wxCodeDepersister() ;
222 // allocate the new object on the heap, that object will have the passed in ID
223 virtual void AllocateObject(int objectID
, wxClassInfo
*classInfo
) ;
225 // initialize the already allocated object having the ID ObjectID with the Create method
226 // creation parameters which are objects are having their Ids passed in objectIDValues
227 // having objectId <> wxInvalidObjectID
229 virtual void CreateObject(int objectID
,
230 const wxClassInfo
*classInfo
,
232 wxxVariant
*variantValues
,
234 const wxClassInfo
**objectClassInfos
237 // destroy the heap-allocated object having the ID ObjectID, this may be used if an object
238 // is embedded in another object and set via value semantics, so the intermediate
239 // object can be destroyed after safely
240 virtual void DestroyObject(int objectID
, wxClassInfo
*classInfo
) ;
242 // set the corresponding property
243 virtual void SetProperty(int objectID
,
244 const wxClassInfo
*classInfo
,
245 const wxPropertyInfo
* propertyInfo
,
246 const wxxVariant
&variantValue
);
248 // sets the corresponding property (value is an object)
249 virtual void SetPropertyAsObject(int objectId
,
250 const wxClassInfo
*classInfo
,
251 const wxPropertyInfo
* propertyInfo
,
255 // sets the corresponding event handler
256 virtual void SetConnect(int eventSourceObjectID
,
257 const wxClassInfo
*eventSourceClassInfo
,
258 const wxDelegateTypeInfo
*delegateInfo
,
259 const wxClassInfo
*eventSinkClassInfo
,
260 const wxHandlerInfo
* handlerInfo
,
261 int eventSinkObjectID
) ;
264 #endif // wxUSE_EXTENDED_RTTI