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