]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: object.h | |
3 | // Purpose: wxObject class, plus run-time type information macros | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
34138703 JS |
12 | #ifndef _WX_OBJECTH__ |
13 | #define _WX_OBJECTH__ | |
c801d85f KB |
14 | |
15 | #ifdef __GNUG__ | |
0d3820b3 | 16 | #pragma interface "object.h" |
c801d85f KB |
17 | #endif |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | class WXDLLEXPORT wxObject; | |
22 | ||
23 | #if USE_DYNAMIC_CLASSES | |
24 | ||
25 | #ifdef __GNUWIN32__ | |
26 | #ifdef GetClassName | |
27 | #undef GetClassName | |
28 | #endif | |
29 | #endif | |
30 | ||
31 | class WXDLLEXPORT wxClassInfo; | |
f4a8c29f | 32 | class WXDLLIMPORT ostream; |
1678ad78 | 33 | class WXDLLEXPORT wxInputStream; |
f4a8c29f GL |
34 | class WXDLLEXPORT wxObjectInputStream; |
35 | class WXDLLEXPORT wxObjectOutputStream; | |
36 | class WXDLLEXPORT wxHashTable; | |
37 | class WXDLLEXPORT wxObject_Serialize; | |
c801d85f KB |
38 | |
39 | /* | |
40 | * Dynamic object system declarations | |
41 | */ | |
42 | ||
43 | typedef wxObject * (*wxObjectConstructorFn) (void); | |
44 | ||
c801d85f KB |
45 | class WXDLLEXPORT wxClassInfo |
46 | { | |
47 | public: | |
48 | char *className; | |
49 | char *baseClassName1; | |
50 | char *baseClassName2; | |
51 | int objectSize; | |
52 | wxObjectConstructorFn objectConstructor; | |
53 | ||
c801d85f KB |
54 | // Pointers to base wxClassInfos: set in InitializeClasses |
55 | // called from wx_main.cc | |
56 | wxClassInfo *baseInfo1; | |
57 | wxClassInfo *baseInfo2; | |
58 | ||
59 | static wxClassInfo *first; | |
60 | wxClassInfo *next; | |
61 | ||
f4a8c29f GL |
62 | static wxHashTable classTable; |
63 | ||
c801d85f | 64 | wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn); |
c801d85f KB |
65 | |
66 | wxObject *CreateObject(void); | |
67 | ||
c801d85f KB |
68 | inline char *GetClassName(void) const { return className; } |
69 | inline char *GetBaseClassName1(void) const { return baseClassName1; } | |
70 | inline char *GetBaseClassName2(void) const { return baseClassName2; } | |
71 | inline int GetSize(void) const { return objectSize; } | |
72 | bool IsKindOf(wxClassInfo *info); | |
73 | ||
74 | static wxClassInfo *FindClass(char *c); | |
75 | // Initializes parent pointers for fast searching. | |
76 | static void InitializeClasses(void); | |
77 | }; | |
78 | ||
79 | wxObject* WXDLLEXPORT wxCreateDynamicObject(char *name); | |
80 | ||
8429bec1 | 81 | #ifdef USE_SERIAL |
1678ad78 | 82 | wxObject* WXDLLEXPORT wxCreateStoredObject( wxInputStream& stream ); |
c801d85f KB |
83 | #endif |
84 | ||
85 | #define DECLARE_DYNAMIC_CLASS(name) \ | |
86 | public:\ | |
87 | static wxClassInfo class##name;\ | |
88 | wxClassInfo *GetClassInfo() \ | |
89 | { return &name::class##name; } | |
90 | ||
91 | #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
92 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
93 | ||
c801d85f KB |
94 | ////// |
95 | ////// for concrete classes | |
96 | ////// | |
97 | ||
98 | // Single inheritance with one base class | |
99 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \ | |
100 | wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \ | |
101 | { return new name; }\ | |
c67daf87 | 102 | wxClassInfo name::class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name); |
c801d85f KB |
103 | |
104 | // Multiple inheritance with two base classes | |
105 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \ | |
106 | wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \ | |
107 | { return new name; }\ | |
c67daf87 | 108 | wxClassInfo name::class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name); |
c801d85f | 109 | |
c801d85f KB |
110 | ////// |
111 | ////// for abstract classes | |
112 | ////// | |
113 | ||
114 | // Single inheritance with one base class | |
115 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
c67daf87 UR |
116 | wxClassInfo name::class##name((char *) #name, (char *) #basename, \ |
117 | (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL); | |
c801d85f KB |
118 | |
119 | // Multiple inheritance with two base classes | |
120 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ | |
c67daf87 | 121 | wxClassInfo name::class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL); |
c801d85f KB |
122 | |
123 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
124 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
125 | ||
126 | #define CLASSINFO(name) (&name::class##name) | |
127 | ||
128 | #else | |
129 | ||
130 | // No dynamic class system: so stub out the macros | |
131 | #define DECLARE_DYNAMIC_CLASS(name) | |
132 | #define DECLARE_ABSTRACT_CLASS(name) | |
133 | #define DECLARE_CLASS(name) | |
134 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) | |
135 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) | |
136 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) | |
137 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) | |
138 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
139 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
140 | ||
141 | #endif | |
142 | ||
e3e65dac | 143 | #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##className) |
c801d85f KB |
144 | |
145 | // Unfortunately Borland seems to need this include. | |
146 | #ifdef __BORLANDC__ | |
147 | #if USE_IOSTREAMH | |
148 | #include <iostream.h> | |
149 | #else | |
150 | #include <iostream> | |
151 | #endif | |
152 | #endif | |
153 | ||
154 | class WXDLLEXPORT wxObjectRefData; | |
155 | ||
156 | class WXDLLEXPORT wxObject | |
157 | { | |
158 | public: | |
159 | ||
160 | // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS | |
161 | static wxClassInfo classwxObject; | |
162 | ||
163 | wxObject(void); | |
164 | virtual ~wxObject(void); | |
165 | ||
166 | virtual wxClassInfo *GetClassInfo(void) { return &classwxObject; } | |
167 | ||
168 | bool IsKindOf(wxClassInfo *info); | |
169 | ||
b2aef89b | 170 | #if WXDEBUG && USE_MEMORY_TRACING |
c801d85f KB |
171 | void * operator new (size_t size, char * fileName = NULL, int lineNum = 0); |
172 | void operator delete (void * buf); | |
173 | ||
174 | // Cause problems for VC++ | |
175 | #ifndef _MSC_VER | |
176 | void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0); | |
177 | void operator delete[] (void * buf); | |
178 | #endif | |
179 | ||
180 | #endif | |
181 | ||
3e1a3a40 | 182 | #if WXDEBUG || USE_DEBUG_CONTEXT |
c801d85f KB |
183 | virtual void Dump(ostream& str); |
184 | #endif | |
185 | ||
8429bec1 | 186 | #ifdef USE_SERIAL |
7a4b9130 GL |
187 | virtual void StoreObject( wxObjectOutputStream &stream ); |
188 | virtual void LoadObject( wxObjectInputStream &stream ); | |
c801d85f KB |
189 | #endif |
190 | ||
191 | // make a 'clone' of the object | |
192 | void Ref(const wxObject& clone); | |
193 | ||
194 | // destroy a reference | |
195 | void UnRef(void); | |
196 | ||
197 | inline wxObjectRefData *GetRefData(void) const { return m_refData; } | |
198 | inline void SetRefData(wxObjectRefData *data) { m_refData = data; } | |
199 | ||
200 | protected: | |
201 | wxObjectRefData *m_refData; | |
bcf1fa6b | 202 | #ifdef USE_SERIAL |
f4a8c29f GL |
203 | wxObject_Serialize *m_serialObj; |
204 | #endif | |
c801d85f KB |
205 | }; |
206 | ||
207 | /* | |
208 | * wxObjectData | |
209 | */ | |
210 | ||
211 | class WXDLLEXPORT wxObjectRefData { | |
212 | ||
213 | friend class wxObject; | |
214 | ||
215 | public: | |
216 | wxObjectRefData(void); | |
217 | virtual ~wxObjectRefData(void); | |
218 | ||
219 | inline int GetRefCount(void) const { return m_count; } | |
220 | private: | |
221 | int m_count; | |
222 | }; | |
223 | ||
b2aef89b | 224 | #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS |
c801d85f KB |
225 | #ifndef WXDEBUG_NEW |
226 | #define WXDEBUG_NEW new(__FILE__,__LINE__) | |
227 | #endif | |
228 | #define new WXDEBUG_NEW | |
229 | #endif | |
230 | ||
231 | #endif | |
34138703 | 232 | // _WX_OBJECTH__ |
c801d85f KB |
233 | |
234 |