1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxObject class, plus run-time type information macros
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
21 class WXDLLEXPORT wxObject
;
23 #if USE_DYNAMIC_CLASSES
31 class WXDLLEXPORT wxClassInfo
;
33 class WXDLLIMPORT istream
;
34 class WXDLLIMPORT ostream
;
37 * Dynamic object system declarations
40 typedef wxObject
* (*wxObjectConstructorFn
) (void);
42 #ifdef USE_STORABLE_CLASSES
43 typedef wxObject
* (*wxStorableConstructorFn
) ( istream
&stream
, char *data
);
46 class WXDLLEXPORT wxClassInfo
53 wxObjectConstructorFn objectConstructor
;
55 #ifdef USE_STORABLE_CLASSES
56 wxStorableConstructorFn storableConstructor
;
59 // Pointers to base wxClassInfos: set in InitializeClasses
60 // called from wx_main.cc
61 wxClassInfo
*baseInfo1
;
62 wxClassInfo
*baseInfo2
;
64 static wxClassInfo
*first
;
67 #ifdef USE_STORABLE_CLASSES
68 wxClassInfo(char *cName
, char *baseName1
, char *baseName2
, int sz
, wxObjectConstructorFn fn
,
69 wxStorableConstructorFn stoFn
= NULL
);
71 wxClassInfo(char *cName
, char *baseName1
, char *baseName2
, int sz
, wxObjectConstructorFn fn
);
74 wxObject
*CreateObject(void);
76 #ifdef USE_STORABLE_CLASSES
77 wxObject
* CreateObject( istream
&stream
, char *data
);
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
);
86 static wxClassInfo
*FindClass(char *c
);
87 // Initializes parent pointers for fast searching.
88 static void InitializeClasses(void);
91 wxObject
* WXDLLEXPORT
wxCreateDynamicObject(char *name
);
93 #ifdef USE_STORABLE_CLASSES
94 wxObject
* WXDLLEXPORT
wxCreateStoredObject( char *name
, istream
&stream
, char *data
);
97 #define DECLARE_DYNAMIC_CLASS(name) \
99 static wxClassInfo class##name;\
100 wxClassInfo *GetClassInfo() \
101 { return &name::class##name; }
103 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
104 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
106 #ifdef USE_STORABLE_CLASSES
107 #define DECLARE_STORABLECLASS(name) DECLARE_DYNAMIC_CLASS(name)
111 ////// for concrete classes
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);
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);
127 ////// for storable classes
130 #ifdef USE_STORABLE_CLASSES
132 #define IMPLEMENT_STORABLE_CLASS(name, basename) \
133 wxObject* WXDLLEXPORT_CTORFN wxStorableConstructorFor##name( fstream* 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 );
140 #define IMPLEMENT_STORABLE_CLASS2(name, basename1, basename2) \
141 wxObject* WXDLLEXPORT_CTORFN wxStorableConstructorFor##name( fstream* 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 );
151 ////// for abstract classes
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);
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);
162 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
163 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
165 #define CLASSINFO(name) (&name::class##name)
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
182 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##name)
184 // Unfortunately Borland seems to need this include.
187 #include <iostream.h>
193 class WXDLLEXPORT wxObjectRefData
;
195 class WXDLLEXPORT wxObject
199 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
200 static wxClassInfo classwxObject
;
203 virtual ~wxObject(void);
205 virtual wxClassInfo
*GetClassInfo(void) { return &classwxObject
; }
207 bool IsKindOf(wxClassInfo
*info
);
209 #if DEBUG && USE_MEMORY_TRACING
210 void * operator new (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
211 void operator delete (void * buf
);
213 // Cause problems for VC++
215 void * operator new[] (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
216 void operator delete[] (void * buf
);
221 #if DEBUG || USE_DEBUG_CONTEXT
222 virtual void Dump(ostream
& str
);
225 #ifdef USE_STORABLE_CLASSES
226 virtual void StoreObject( ostream
&WXUNUSED(stream
) ) {};
229 // make a 'clone' of the object
230 void Ref(const wxObject
& clone
);
232 // destroy a reference
235 inline wxObjectRefData
*GetRefData(void) const { return m_refData
; }
236 inline void SetRefData(wxObjectRefData
*data
) { m_refData
= data
; }
239 wxObjectRefData
*m_refData
;
246 class WXDLLEXPORT wxObjectRefData
{
248 friend class wxObject
;
251 wxObjectRefData(void);
252 virtual ~wxObjectRefData(void);
254 inline int GetRefCount(void) const { return m_count
; }
259 #if DEBUG && USE_GLOBAL_MEMORY_OPERATORS
261 #define WXDEBUG_NEW new(__FILE__,__LINE__)
263 #define new WXDEBUG_NEW