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