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 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "object.h"
21 class WXDLLEXPORT wxObject
;
23 #if USE_DYNAMIC_CLASSES
31 class WXDLLEXPORT wxClassInfo
;
32 class WXDLLEXPORT ostream
;
33 class WXDLLEXPORT wxInputStream
;
34 class WXDLLIMPORT wxObjectInputStream
;
35 class WXDLLIMPORT wxObjectOutputStream
;
38 * Dynamic object system declarations
41 typedef wxObject
* (*wxObjectConstructorFn
) (void);
43 class WXDLLEXPORT wxClassInfo
50 wxObjectConstructorFn objectConstructor
;
52 // Pointers to base wxClassInfos: set in InitializeClasses
53 // called from wx_main.cc
54 wxClassInfo
*baseInfo1
;
55 wxClassInfo
*baseInfo2
;
57 static wxClassInfo
*first
;
60 wxClassInfo(char *cName
, char *baseName1
, char *baseName2
, int sz
, wxObjectConstructorFn fn
);
62 wxObject
*CreateObject(void);
64 inline char *GetClassName(void) const { return className
; }
65 inline char *GetBaseClassName1(void) const { return baseClassName1
; }
66 inline char *GetBaseClassName2(void) const { return baseClassName2
; }
67 inline int GetSize(void) const { return objectSize
; }
68 bool IsKindOf(wxClassInfo
*info
);
70 static wxClassInfo
*FindClass(char *c
);
71 // Initializes parent pointers for fast searching.
72 static void InitializeClasses(void);
75 wxObject
* WXDLLEXPORT
wxCreateDynamicObject(char *name
);
77 #ifdef USE_STORABLE_CLASSES
78 wxObject
* WXDLLEXPORT
wxCreateStoredObject( wxInputStream
& stream
);
81 #define DECLARE_DYNAMIC_CLASS(name) \
83 static wxClassInfo class##name;\
84 wxClassInfo *GetClassInfo() \
85 { return &name::class##name; }
87 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
88 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
91 ////// for concrete classes
94 // Single inheritance with one base class
95 #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
96 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
98 wxClassInfo name::class##name(#name, #basename, NULL, sizeof(name), wxConstructorFor##name);
100 // Multiple inheritance with two base classes
101 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
102 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
103 { return new name; }\
104 wxClassInfo name::class##name(#name, #basename1, #basename2, sizeof(name), wxConstructorFor##name);
107 ////// for abstract classes
110 // Single inheritance with one base class
111 #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
112 wxClassInfo name::class##name(#name, #basename, NULL, sizeof(name), NULL);
114 // Multiple inheritance with two base classes
115 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
116 wxClassInfo name::class##name(#name, #basename1, #basename2, sizeof(name), NULL);
118 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
119 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
121 #define CLASSINFO(name) (&name::class##name)
125 // No dynamic class system: so stub out the macros
126 #define DECLARE_DYNAMIC_CLASS(name)
127 #define DECLARE_ABSTRACT_CLASS(name)
128 #define DECLARE_CLASS(name)
129 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
130 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
131 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
132 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
133 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
134 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
138 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##className)
140 // Unfortunately Borland seems to need this include.
143 #include <iostream.h>
149 class WXDLLEXPORT wxObjectRefData
;
151 class WXDLLEXPORT wxObject
155 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
156 static wxClassInfo classwxObject
;
159 virtual ~wxObject(void);
161 virtual wxClassInfo
*GetClassInfo(void) { return &classwxObject
; }
163 bool IsKindOf(wxClassInfo
*info
);
165 #if WXDEBUG && USE_MEMORY_TRACING
166 void * operator new (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
167 void operator delete (void * buf
);
169 // Cause problems for VC++
171 void * operator new[] (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
172 void operator delete[] (void * buf
);
177 #if WXDEBUG || USE_DEBUG_CONTEXT
178 virtual void Dump(ostream
& str
);
181 #ifdef USE_STORABLE_CLASSES
182 virtual void StoreObject( wxObjectOutputStream
&WXUNUSED(stream
) ) {};
183 virtual void LoadObject( wxObjectInputStream
&WXUNUSED(stream
) ) {};
186 // make a 'clone' of the object
187 void Ref(const wxObject
& clone
);
189 // destroy a reference
192 inline wxObjectRefData
*GetRefData(void) const { return m_refData
; }
193 inline void SetRefData(wxObjectRefData
*data
) { m_refData
= data
; }
196 wxObjectRefData
*m_refData
;
203 class WXDLLEXPORT wxObjectRefData
{
205 friend class wxObject
;
208 wxObjectRefData(void);
209 virtual ~wxObjectRefData(void);
211 inline int GetRefCount(void) const { return m_count
; }
216 #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
218 #define WXDEBUG_NEW new(__FILE__,__LINE__)
220 #define new WXDEBUG_NEW