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