]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/xtistrm.h
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 // Filer contains the interfaces for streaming objects in and out of XML,
24 // rendering them either to objects in memory, or to code. Note: We
25 // consider the process of generating code to be one of *depersisting* the
26 // object from xml, *not* of persisting the object to code from an object
27 // in memory. This distincation can be confusing, and should be kept
28 // in mind when looking at the property streamers and callback interfaces
32 Main interface for streaming out an object to XML.
35 void WriteComponent(wxObject
*Object
, const wxClassInfo
*ClassInfo
, wxXmlNode
*parent
, const wxString
& nodeName
);
39 Streaming callbacks for depersisting XML to code, or running objects
45 wxReader handles streaming in a class from XML. Maintains a list of
46 objects, and names, and issues calls out to interfaces to depersist the
47 guts from the XML tree.
49 class wxReader
: wxObject
51 struct wxReaderInternal
;
52 wxReaderInternal
*Data
;
54 wxxVariant
ReadPropertyValueNoAssign(wxXmlNode
*Node
,
55 wxClassInfo
*ClassInfo
,
56 const wxPropertyInfo
*& propertyInfo
,
57 wxIDepersist
*Callbacks
= NULL
);
59 void ReadPropertyValue(wxXmlNode
*Node
,
60 wxClassInfo
*ClassInfo
,
62 wxIDepersist
*Callbacks
= NULL
);
64 bool genCode
; // true if the reader should generate code.
66 // this interface is getting crufty. Why the
67 // different depersist callbacks in here, if there
68 // is another place that knows that we're generating
69 // code? Needs some repair work.
71 wxReader(bool GenerateCode
= false);
74 // Reads a component from XML. The return is the object ID, which can
75 // be used in calls to GetObject or GetObjectName.
77 // ISSUE: Still needs to implement references to objects.
78 // requires a bit of additional design in the XML (minor).
79 int ReadComponent(wxXmlNode
*parent
, wxIDepersist
*Callbacks
);
81 // When streaming in, we may we depersisting to code, or to objects
82 // in memory. The depersist callbacks for generating code will
83 // not create the objects, but will create names for them instead.
84 // So internally, we keep track of IDs, not pointers. Depending
85 // on who you are in your callbacks, you can query the names or
86 // pointers of the objects as need be. You should not mix both,
87 // because you will die if you do.
89 wxObject
*GetObject(int id
);
90 wxString
GetObjectName(int id
);
91 wxClassInfo
*GetObjectClassInfo(int id
) ;
93 void SetObject(int id
, wxObject
*Object
);
94 void SetObjectName(int id
, const wxString
&Name
, wxClassInfo
* ClassInfo
);
96 // Returns the result of a top level ReadComponent call. Used
97 // typically after you have instructed the reader to stream in an
98 // object, and you want the object back now. Only really valid if
99 // you are reading back in to an object in memory, as opposed to code.
100 wxObject
*GetRoot() { return GetObject( 0 ) ; }
105 // NotifyReader is called by wxReader so that we can have access to the
106 // object store functions in the reader when we are called back. Hmm.
107 // probably should have just made the callback functions each take a
109 virtual void NotifyReader(wxReader
*Reader
) = 0;
111 // The next three callbacks match the ACS model of creation of objects.
112 // At runtime, these will create actual instances, and manipulate them.
113 // When generating code, these will just create statements of C++
114 // code to create the objects.
115 virtual void AllocateObject(int ObjectID
, wxClassInfo
*ClassInfo
) = 0;
116 virtual void CreateObject(int ObjectID
,
117 wxClassInfo
*ClassInfo
,
119 wxxVariant
*VariantValues
) = 0;
120 virtual void SetProperty(int ObjectID
,
121 wxClassInfo
*ClassInfo
,
122 const wxPropertyInfo
* PropertyInfo
,
123 const wxxVariant
&VariantValue
) = 0;
124 virtual void SetConnect(int EventSourceObjectID
,
125 wxClassInfo
*EventSourceClassInfo
,
127 const wxString
&handlerName
,
128 int EventSinkObjectID
) = 0;
132 wxIDepersistRuntime implements the callbacks that will depersist
133 an object into a running memory image, as opposed to writing
134 C++ initialization code to bring the object to life.
136 class wxIDepersistRuntime
: public wxIDepersist
140 virtual void NotifyReader(wxReader
*_Reader
)
144 virtual void AllocateObject(int ObjectID
, wxClassInfo
*ClassInfo
);
145 virtual void CreateObject(int ObjectID
, wxClassInfo
*ClassInfo
, int ParamCount
, wxxVariant
*VariantValues
);
146 virtual void SetProperty(int ObjectID
, wxClassInfo
*ClassInfo
, const wxPropertyInfo
* PropertyInfo
, const wxxVariant
&VariantValue
);
147 virtual void SetConnect(int EventSourceObjectID
,
148 wxClassInfo
*EventSourceClassInfo
,
150 const wxString
&handlerName
,
151 int EventSinkObjectID
) ;
155 wxIDepersistCode implements the callbacks that will depersist
156 an object into a C++ initialization function.
159 class wxTextOutputStream
;
161 class wxIDepersistCode
: public wxIDepersist
164 wxTextOutputStream
*fp
;
166 wxIDepersistCode(wxTextOutputStream
*out
) : fp(out
) { }
167 virtual void NotifyReader(wxReader
*_Reader
)
171 virtual void AllocateObject(int ObjectID
, wxClassInfo
*ClassInfo
);
172 virtual void CreateObject(int ObjectID
, wxClassInfo
*ClassInfo
, int ParamCount
, wxxVariant
*VariantValues
);
173 virtual void SetProperty(int ObjectID
, wxClassInfo
*ClassInfo
, const wxPropertyInfo
* PropertyInfo
, const wxxVariant
&VariantValue
);
174 virtual void SetConnect(int EventSourceObjectID
,
175 wxClassInfo
*EventSourceClassInfo
,
177 const wxString
&handlerName
,
178 int EventSinkObjectID
) ;
181 #endif // wxUSE_EXTENDED_RTTI