]>
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 | |
3f4a0c5b | 9 | // Licence: wxWindows licence |
c801d85f KB |
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" | |
e55ad60e | 20 | #include "wx/memory.h" |
c801d85f KB |
21 | |
22 | class WXDLLEXPORT wxObject; | |
23 | ||
47d67540 | 24 | #if wxUSE_DYNAMIC_CLASSES |
c801d85f | 25 | |
3f1af920 | 26 | // #ifdef __GNUWIN32__ |
c801d85f KB |
27 | #ifdef GetClassName |
28 | #undef GetClassName | |
29 | #endif | |
3f1af920 JS |
30 | #ifdef GetClassInfo |
31 | #undef GetClassInfo | |
c801d85f | 32 | #endif |
3f1af920 | 33 | // #endif |
c801d85f KB |
34 | |
35 | class WXDLLEXPORT wxClassInfo; | |
1678ad78 | 36 | class WXDLLEXPORT wxInputStream; |
858f7d66 | 37 | class WXDLLEXPORT wxOutputStream; |
f4a8c29f GL |
38 | class WXDLLEXPORT wxObjectInputStream; |
39 | class WXDLLEXPORT wxObjectOutputStream; | |
40 | class WXDLLEXPORT wxHashTable; | |
41 | class WXDLLEXPORT wxObject_Serialize; | |
c801d85f | 42 | |
fbc535ff | 43 | #if wxUSE_IOSTREAMH |
3f4a0c5b VZ |
44 | // N.B. BC++ doesn't have istream.h, ostream.h |
45 | # include <iostream.h> | |
fbc535ff | 46 | #else |
3f4a0c5b VZ |
47 | # include <ostream> |
48 | # if defined(__VISUALC__) || defined(__MWERKS__) | |
49 | using namespace std; | |
50 | # endif | |
fbc535ff JS |
51 | #endif |
52 | ||
c801d85f KB |
53 | /* |
54 | * Dynamic object system declarations | |
55 | */ | |
56 | ||
57 | typedef wxObject * (*wxObjectConstructorFn) (void); | |
58 | ||
c801d85f KB |
59 | class WXDLLEXPORT wxClassInfo |
60 | { | |
61 | public: | |
9d2f3c71 | 62 | wxClassInfo(wxChar *cName, wxChar *baseName1, wxChar *baseName2, int sz, wxObjectConstructorFn fn); |
c801d85f KB |
63 | |
64 | wxObject *CreateObject(void); | |
3f4a0c5b | 65 | |
9d2f3c71 OK |
66 | inline wxChar *GetClassName(void) const { return m_className; } |
67 | inline wxChar *GetBaseClassName1(void) const { return m_baseClassName1; } | |
68 | inline wxChar *GetBaseClassName2(void) const { return m_baseClassName2; } | |
0c32066b JS |
69 | inline wxClassInfo* GetBaseClass1() const { return m_baseInfo1; } |
70 | inline wxClassInfo* GetBaseClass2() const { return m_baseInfo2; } | |
71 | inline int GetSize(void) const { return m_objectSize; } | |
72 | inline wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; } | |
856d2e52 | 73 | static inline wxClassInfo* GetFirst() { return sm_first; } |
0c32066b | 74 | inline wxClassInfo* GetNext() const { return m_next; } |
8cb50e4b | 75 | bool IsKindOf(wxClassInfo *info) const; |
c801d85f | 76 | |
9d2f3c71 | 77 | static wxClassInfo *FindClass(wxChar *c); |
0c32066b JS |
78 | |
79 | // Initializes parent pointers and hash table for fast searching. | |
c801d85f | 80 | static void InitializeClasses(void); |
0c32066b JS |
81 | |
82 | // Cleans up hash table used for fast searching. | |
83 | static void CleanUpClasses(void); | |
84 | ||
85 | public: | |
9d2f3c71 OK |
86 | wxChar* m_className; |
87 | wxChar* m_baseClassName1; | |
88 | wxChar* m_baseClassName2; | |
0c32066b JS |
89 | int m_objectSize; |
90 | wxObjectConstructorFn m_objectConstructor; | |
3f4a0c5b | 91 | |
0c32066b JS |
92 | // Pointers to base wxClassInfos: set in InitializeClasses |
93 | // called from wx_main.cc | |
94 | wxClassInfo* m_baseInfo1; | |
95 | wxClassInfo* m_baseInfo2; | |
96 | ||
97 | static wxClassInfo* sm_first; | |
98 | wxClassInfo* m_next; | |
99 | ||
100 | static wxHashTable* sm_classTable; | |
c801d85f KB |
101 | }; |
102 | ||
9d2f3c71 | 103 | WXDLLEXPORT wxObject* wxCreateDynamicObject(const wxChar *name); |
c801d85f | 104 | |
9838df2c | 105 | #if wxUSE_SERIAL |
184b5d99 | 106 | WXDLLEXPORT wxObject* wxCreateStoredObject( wxInputStream& stream ); |
c801d85f KB |
107 | #endif |
108 | ||
109 | #define DECLARE_DYNAMIC_CLASS(name) \ | |
110 | public:\ | |
0c32066b | 111 | static wxClassInfo sm_class##name;\ |
8cb50e4b | 112 | wxClassInfo *GetClassInfo() const \ |
0c32066b | 113 | { return &name::sm_class##name; } |
c801d85f KB |
114 | |
115 | #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
116 | #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name) | |
117 | ||
c801d85f KB |
118 | ////// |
119 | ////// for concrete classes | |
120 | ////// | |
121 | ||
122 | // Single inheritance with one base class | |
123 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \ | |
124 | wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \ | |
125 | { return new name; }\ | |
9d2f3c71 | 126 | wxClassInfo name::sm_class##name((wxChar *) _T(#name), (wxChar *) _T(#basename), (wxChar *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name); |
c801d85f KB |
127 | |
128 | // Multiple inheritance with two base classes | |
129 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \ | |
130 | wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \ | |
131 | { return new name; }\ | |
9d2f3c71 | 132 | wxClassInfo name::sm_class##name((wxChar *) _T(#name), (wxChar *) _T(#basename1), (wxChar *) _T(#basename2), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name); |
c801d85f | 133 | |
c801d85f KB |
134 | ////// |
135 | ////// for abstract classes | |
136 | ////// | |
137 | ||
138 | // Single inheritance with one base class | |
139 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
9d2f3c71 OK |
140 | wxClassInfo name::sm_class##name((wxChar *) _T(#name), (wxChar *) _T(#basename), \ |
141 | (wxChar *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL); | |
c801d85f KB |
142 | |
143 | // Multiple inheritance with two base classes | |
144 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ | |
9d2f3c71 OK |
145 | wxClassInfo name::sm_class##name((wxChar *) _T(#name), (wxChar *) _T(#basename1), \ |
146 | (wxChar *) _T(#basename2), (int) sizeof(name), (wxObjectConstructorFn) NULL); | |
c801d85f KB |
147 | |
148 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
149 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
150 | ||
0c32066b | 151 | #define CLASSINFO(name) (&name::sm_class##name) |
c801d85f KB |
152 | |
153 | #else | |
154 | ||
155 | // No dynamic class system: so stub out the macros | |
156 | #define DECLARE_DYNAMIC_CLASS(name) | |
157 | #define DECLARE_ABSTRACT_CLASS(name) | |
158 | #define DECLARE_CLASS(name) | |
159 | #define IMPLEMENT_DYNAMIC_CLASS(name, basename) | |
160 | #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) | |
161 | #define IMPLEMENT_ABSTRACT_CLASS(name, basename) | |
162 | #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) | |
163 | #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS | |
164 | #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2 | |
165 | ||
166 | #endif | |
167 | ||
3013b6f4 JS |
168 | #define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className) |
169 | ||
170 | // Just seems a bit nicer-looking (pretend it's not a macro) | |
171 | #define wxIsKindOf(obj, className) obj->IsKindOf(&className::sm_class##className) | |
c801d85f KB |
172 | |
173 | // Unfortunately Borland seems to need this include. | |
174 | #ifdef __BORLANDC__ | |
47d67540 | 175 | #if wxUSE_IOSTREAMH |
c801d85f KB |
176 | #include <iostream.h> |
177 | #else | |
178 | #include <iostream> | |
179 | #endif | |
180 | #endif | |
181 | ||
182 | class WXDLLEXPORT wxObjectRefData; | |
183 | ||
184 | class WXDLLEXPORT wxObject | |
185 | { | |
186 | public: | |
187 | ||
188 | // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS | |
0c32066b | 189 | static wxClassInfo sm_classwxObject; |
c801d85f KB |
190 | |
191 | wxObject(void); | |
192 | virtual ~wxObject(void); | |
193 | ||
8cb50e4b | 194 | virtual wxClassInfo *GetClassInfo(void) const { return &sm_classwxObject; } |
c801d85f | 195 | |
8cb50e4b | 196 | bool IsKindOf(wxClassInfo *info) const; |
c801d85f | 197 | |
ea57084d | 198 | #if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING |
c801d85f KB |
199 | void * operator new (size_t size, char * fileName = NULL, int lineNum = 0); |
200 | void operator delete (void * buf); | |
27198be4 | 201 | |
76626af2 | 202 | // VC++ 6.0 |
3f4a0c5b | 203 | #if defined(__VISUALC__) && (__VISUALC__ >= 1200) |
76626af2 JS |
204 | void operator delete(void *buf, char*, int); |
205 | #endif | |
206 | ||
3f4a0c5b | 207 | // Causes problems for VC++ |
921b3c17 | 208 | #if wxUSE_ARRAY_MEMORY_OPERATORS && !defined(__VISUALC__) && !defined( __MWERKS__) |
c801d85f KB |
209 | void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0); |
210 | void operator delete[] (void * buf); | |
211 | #endif | |
212 | ||
27198be4 SC |
213 | #ifdef __MWERKS__ |
214 | void * operator new[] (size_t size, char * fileName , int lineNum = 0); | |
215 | void operator delete[] (void * buf); | |
216 | #endif | |
217 | ||
3f4a0c5b | 218 | #endif // Debug & memory tracing |
c801d85f | 219 | |
ea57084d | 220 | #if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT |
c801d85f KB |
221 | virtual void Dump(ostream& str); |
222 | #endif | |
223 | ||
9838df2c | 224 | #if wxUSE_SERIAL |
7a4b9130 GL |
225 | virtual void StoreObject( wxObjectOutputStream &stream ); |
226 | virtual void LoadObject( wxObjectInputStream &stream ); | |
c801d85f KB |
227 | #endif |
228 | ||
229 | // make a 'clone' of the object | |
230 | void Ref(const wxObject& clone); | |
231 | ||
232 | // destroy a reference | |
233 | void UnRef(void); | |
234 | ||
235 | inline wxObjectRefData *GetRefData(void) const { return m_refData; } | |
236 | inline void SetRefData(wxObjectRefData *data) { m_refData = data; } | |
237 | ||
238 | protected: | |
0c32066b | 239 | wxObjectRefData* m_refData; |
9838df2c | 240 | #if wxUSE_SERIAL |
0c32066b | 241 | wxObject_Serialize* m_serialObj; |
f4a8c29f | 242 | #endif |
c801d85f KB |
243 | }; |
244 | ||
245 | /* | |
246 | * wxObjectData | |
247 | */ | |
248 | ||
249 | class WXDLLEXPORT wxObjectRefData { | |
250 | ||
251 | friend class wxObject; | |
252 | ||
253 | public: | |
254 | wxObjectRefData(void); | |
255 | virtual ~wxObjectRefData(void); | |
256 | ||
257 | inline int GetRefCount(void) const { return m_count; } | |
258 | private: | |
259 | int m_count; | |
260 | }; | |
261 | ||
7fe7d506 JS |
262 | #ifdef __WXDEBUG__ |
263 | #ifndef WXDEBUG_NEW | |
264 | #define WXDEBUG_NEW new(__FILE__,__LINE__) | |
265 | #endif | |
266 | #else | |
267 | #define WXDEBUG_NEW new | |
268 | #endif | |
269 | ||
270 | // Redefine new to be the debugging version. This doesn't | |
271 | // work with all compilers, in which case you need to | |
272 | // use WXDEBUG_NEW explicitly if you wish to use the debugging version. | |
273 | ||
274 | #if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS | |
e55ad60e | 275 | #define new new(__FILE__,__LINE__) |
c801d85f KB |
276 | #endif |
277 | ||
278 | #endif | |
34138703 | 279 | // _WX_OBJECTH__ |
c801d85f KB |
280 | |
281 |