]> git.saurik.com Git - wxWidgets.git/blob - include/wx/object.h
fixed duplicate definition
[wxWidgets.git] / include / wx / object.h
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
12 #ifndef __OBJECTH__
13 #define __OBJECTH__
14
15 #ifdef __GNUG__
16 #pragma interface "object.h"
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;
32
33 class WXDLLIMPORT istream;
34 class WXDLLIMPORT ostream;
35
36 /*
37 * Dynamic object system declarations
38 */
39
40 typedef wxObject * (*wxObjectConstructorFn) (void);
41
42 #ifdef USE_STORABLE_CLASSES
43 typedef wxObject* (*wxStorableConstructorFn) ( istream &stream, char *data );
44 #endif
45
46 class WXDLLEXPORT wxClassInfo
47 {
48 public:
49 char *className;
50 char *baseClassName1;
51 char *baseClassName2;
52 int objectSize;
53 wxObjectConstructorFn objectConstructor;
54
55 #ifdef USE_STORABLE_CLASSES
56 wxStorableConstructorFn storableConstructor;
57 #endif
58
59 // Pointers to base wxClassInfos: set in InitializeClasses
60 // called from wx_main.cc
61 wxClassInfo *baseInfo1;
62 wxClassInfo *baseInfo2;
63
64 static wxClassInfo *first;
65 wxClassInfo *next;
66
67 #ifdef USE_STORABLE_CLASSES
68 wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn,
69 wxStorableConstructorFn stoFn = NULL );
70 #else
71 wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn);
72 #endif
73
74 wxObject *CreateObject(void);
75
76 #ifdef USE_STORABLE_CLASSES
77 wxObject* CreateObject( istream &stream, char *data );
78 #endif
79
80 inline char *GetClassName(void) const { return className; }
81 inline char *GetBaseClassName1(void) const { return baseClassName1; }
82 inline char *GetBaseClassName2(void) const { return baseClassName2; }
83 inline int GetSize(void) const { return objectSize; }
84 bool IsKindOf(wxClassInfo *info);
85
86 static wxClassInfo *FindClass(char *c);
87 // Initializes parent pointers for fast searching.
88 static void InitializeClasses(void);
89 };
90
91 wxObject* WXDLLEXPORT wxCreateDynamicObject(char *name);
92
93 #ifdef USE_STORABLE_CLASSES
94 wxObject* WXDLLEXPORT wxCreateStoredObject( char *name, istream &stream, char *data );
95 #endif
96
97 #define DECLARE_DYNAMIC_CLASS(name) \
98 public:\
99 static wxClassInfo class##name;\
100 wxClassInfo *GetClassInfo() \
101 { return &name::class##name; }
102
103 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
104 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
105
106 #ifdef USE_STORABLE_CLASSES
107 #define DECLARE_STORABLECLASS(name) DECLARE_DYNAMIC_CLASS(name)
108 #endif
109
110 //////
111 ////// for concrete classes
112 //////
113
114 // Single inheritance with one base class
115 #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
116 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
117 { return new name; }\
118 wxClassInfo name::class##name(#name, #basename, NULL, sizeof(name), wxConstructorFor##name);
119
120 // Multiple inheritance with two base classes
121 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
122 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
123 { return new name; }\
124 wxClassInfo name::class##name(#name, #basename1, #basename2, sizeof(name), wxConstructorFor##name);
125
126 //////
127 ////// for storable classes
128 //////
129
130 #ifdef USE_STORABLE_CLASSES
131
132 #define IMPLEMENT_STORABLE_CLASS(name, basename) \
133 wxObject* WXDLLEXPORT_CTORFN wxStorableConstructorFor##name( istream* stream, char* data )\
134 { return new name( stream, data ); }\
135 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void)\
136 { return new name; }\
137 wxClassInfo name::class##name(#name, #basename, NULL, sizeof(name), wxConstructorFor##name,\
138 wxStorableConstructorFor##name );
139
140 #define IMPLEMENT_STORABLE_CLASS2(name, basename1, basename2) \
141 wxObject* WXDLLEXPORT_CTORFN wxStorableConstructorFor##name( istream* stream, char* data )\
142 { return new name( stream, data ); }\
143 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void)\
144 { return new name; }\
145 wxClassInfo name::class##name(#name, #basename1, basename2, sizeof(name), wxConstructorFor##name,\
146 wxStorableConstructorFor##name );
147
148 #endif
149
150 //////
151 ////// for abstract classes
152 //////
153
154 // Single inheritance with one base class
155 #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
156 wxClassInfo name::class##name(#name, #basename, NULL, sizeof(name), NULL);
157
158 // Multiple inheritance with two base classes
159 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
160 wxClassInfo name::class##name(#name, #basename1, #basename2, sizeof(name), NULL);
161
162 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
163 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
164
165 #define CLASSINFO(name) (&name::class##name)
166
167 #else
168
169 // No dynamic class system: so stub out the macros
170 #define DECLARE_DYNAMIC_CLASS(name)
171 #define DECLARE_ABSTRACT_CLASS(name)
172 #define DECLARE_CLASS(name)
173 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
174 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
175 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
176 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
177 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
178 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
179
180 #endif
181
182 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##name)
183
184 // Unfortunately Borland seems to need this include.
185 #ifdef __BORLANDC__
186 #if USE_IOSTREAMH
187 #include <iostream.h>
188 #else
189 #include <iostream>
190 #endif
191 #endif
192
193 class WXDLLEXPORT wxObjectRefData;
194
195 class WXDLLEXPORT wxObject
196 {
197 public:
198
199 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
200 static wxClassInfo classwxObject;
201
202 wxObject(void);
203 virtual ~wxObject(void);
204
205 virtual wxClassInfo *GetClassInfo(void) { return &classwxObject; }
206
207 bool IsKindOf(wxClassInfo *info);
208
209 #if WXDEBUG && USE_MEMORY_TRACING
210 void * operator new (size_t size, char * fileName = NULL, int lineNum = 0);
211 void operator delete (void * buf);
212
213 // Cause problems for VC++
214 #ifndef _MSC_VER
215 void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0);
216 void operator delete[] (void * buf);
217 #endif
218
219 #endif
220
221 #if WXDEBUG || USE_DEBUG_CONTEXT
222 virtual void Dump(ostream& str);
223 #endif
224
225 #ifdef USE_STORABLE_CLASSES
226 virtual void StoreObject( ostream &WXUNUSED(stream) ) {};
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:
239 wxObjectRefData *m_refData;
240 };
241
242 /*
243 * wxObjectData
244 */
245
246 class WXDLLEXPORT wxObjectRefData {
247
248 friend class wxObject;
249
250 public:
251 wxObjectRefData(void);
252 virtual ~wxObjectRefData(void);
253
254 inline int GetRefCount(void) const { return m_count; }
255 private:
256 int m_count;
257 };
258
259 #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
260 #ifndef WXDEBUG_NEW
261 #define WXDEBUG_NEW new(__FILE__,__LINE__)
262 #endif
263 #define new WXDEBUG_NEW
264 #endif
265
266 #endif
267 // __OBJECTH__
268
269