]> git.saurik.com Git - wxWidgets.git/blob - include/wx/xtistrm.h
renamed to WX_DECLARE_LIST_WITH_DECL for consistency
[wxWidgets.git] / include / wx / xtistrm.h
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
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "xtistrm.h"
17 #endif
18
19 #include "wx/wx.h"
20
21 #if wxUSE_EXTENDED_RTTI
22
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
29 // listed below.
30
31 /*
32 Main interface for streaming out an object to XML.
33 */
34
35 void WriteComponent(wxObject *Object, const wxClassInfo *ClassInfo, wxXmlNode *parent, const wxString& nodeName );
36
37 class wxReader;
38 /*
39 Streaming callbacks for depersisting XML to code, or running objects
40 */
41
42 struct wxIDepersist ;
43
44 /*
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.
48 */
49 class wxReader : wxObject
50 {
51 struct wxReaderInternal;
52 wxReaderInternal *Data;
53
54 wxxVariant ReadPropertyValueNoAssign(wxXmlNode *Node,
55 wxClassInfo *ClassInfo,
56 const wxPropertyInfo *& propertyInfo ,
57 wxIDepersist *Callbacks = NULL);
58
59 void ReadPropertyValue(wxXmlNode *Node,
60 wxClassInfo *ClassInfo,
61 int ObjectId ,
62 wxIDepersist *Callbacks = NULL );
63
64 bool genCode; // true if the reader should generate code.
65 // ISSUE: ick!
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.
70 public:
71 wxReader(bool GenerateCode = false);
72 ~wxReader();
73
74 // Reads a component from XML. The return is the object ID, which can
75 // be used in calls to GetObject or GetObjectName.
76 //
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);
80
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.
88
89 wxObject *GetObject(int id);
90 wxString GetObjectName(int id);
91 wxClassInfo *GetObjectClassInfo(int id) ;
92
93 void SetObject(int id, wxObject *Object);
94 void SetObjectName(int id, const wxString &Name, wxClassInfo* ClassInfo);
95
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 ) ; }
101 };
102
103 struct wxIDepersist
104 {
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
108 // wxReader.
109 virtual void NotifyReader(wxReader *Reader) = 0;
110
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,
118 int ParamCount,
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,
126 int eventType ,
127 const wxString &handlerName ,
128 int EventSinkObjectID ) = 0;
129 };
130
131 /*
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.
135 */
136 class wxIDepersistRuntime : public wxIDepersist
137 {
138 wxReader *Reader;
139 public:
140 virtual void NotifyReader(wxReader *_Reader)
141 {
142 Reader = _Reader;
143 }
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,
149 int eventType ,
150 const wxString &handlerName ,
151 int EventSinkObjectID ) ;
152 };
153
154 /*
155 wxIDepersistCode implements the callbacks that will depersist
156 an object into a C++ initialization function.
157 */
158
159 class wxTextOutputStream ;
160
161 class wxIDepersistCode : public wxIDepersist
162 {
163 wxReader *Reader;
164 wxTextOutputStream *fp;
165 public:
166 wxIDepersistCode(wxTextOutputStream *out) : fp(out) { }
167 virtual void NotifyReader(wxReader *_Reader)
168 {
169 Reader = _Reader;
170 }
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,
176 int eventType ,
177 const wxString &handlerName ,
178 int EventSinkObjectID ) ;
179 };
180
181 #endif // wxUSE_EXTENDED_RTTI
182
183 #endif