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 WXDLLIMPORT ostream
;
33 class WXDLLEXPORT wxInputStream
;
34 class WXDLLEXPORT wxObjectInputStream
;
35 class WXDLLEXPORT wxObjectOutputStream
;
36 class WXDLLEXPORT wxHashTable
;
37 class WXDLLEXPORT wxObject_Serialize
;
40 * Dynamic object system declarations
43 typedef wxObject
* (*wxObjectConstructorFn
) (void);
45 class WXDLLEXPORT wxClassInfo
52 wxObjectConstructorFn objectConstructor
;
54 // Pointers to base wxClassInfos: set in InitializeClasses
55 // called from wx_main.cc
56 wxClassInfo
*baseInfo1
;
57 wxClassInfo
*baseInfo2
;
59 static wxClassInfo
*first
;
62 static wxHashTable classTable
;
64 wxClassInfo(char *cName
, char *baseName1
, char *baseName2
, int sz
, wxObjectConstructorFn fn
);
66 wxObject
*CreateObject(void);
68 inline char *GetClassName(void) const { return className
; }
69 inline char *GetBaseClassName1(void) const { return baseClassName1
; }
70 inline char *GetBaseClassName2(void) const { return baseClassName2
; }
71 inline int GetSize(void) const { return objectSize
; }
72 bool IsKindOf(wxClassInfo
*info
);
74 static wxClassInfo
*FindClass(char *c
);
75 // Initializes parent pointers for fast searching.
76 static void InitializeClasses(void);
79 wxObject
* WXDLLEXPORT
wxCreateDynamicObject(char *name
);
82 wxObject
* WXDLLEXPORT
wxCreateStoredObject( wxInputStream
& stream
);
85 #define DECLARE_DYNAMIC_CLASS(name) \
87 static wxClassInfo class##name;\
88 wxClassInfo *GetClassInfo() \
89 { return &name::class##name; }
91 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
92 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
95 ////// for concrete classes
98 // Single inheritance with one base class
99 #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
100 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
101 { return new name; }\
102 wxClassInfo name::class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
104 // Multiple inheritance with two base classes
105 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
106 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
107 { return new name; }\
108 wxClassInfo name::class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
111 ////// for abstract classes
114 // Single inheritance with one base class
115 #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
116 wxClassInfo name::class##name((char *) #name, (char *) #basename, \
117 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
119 // Multiple inheritance with two base classes
120 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
121 wxClassInfo name::class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
123 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
124 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
126 #define CLASSINFO(name) (&name::class##name)
130 // No dynamic class system: so stub out the macros
131 #define DECLARE_DYNAMIC_CLASS(name)
132 #define DECLARE_ABSTRACT_CLASS(name)
133 #define DECLARE_CLASS(name)
134 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
135 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
136 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
137 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
138 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
139 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
143 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##className)
145 // Unfortunately Borland seems to need this include.
148 #include <iostream.h>
154 class WXDLLEXPORT wxObjectRefData
;
156 class WXDLLEXPORT wxObject
160 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
161 static wxClassInfo classwxObject
;
164 virtual ~wxObject(void);
166 virtual wxClassInfo
*GetClassInfo(void) { return &classwxObject
; }
168 bool IsKindOf(wxClassInfo
*info
);
170 #if WXDEBUG && USE_MEMORY_TRACING
171 void * operator new (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
172 void operator delete (void * buf
);
174 // Cause problems for VC++
176 void * operator new[] (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
177 void operator delete[] (void * buf
);
182 #if WXDEBUG || USE_DEBUG_CONTEXT
183 virtual void Dump(ostream
& str
);
187 virtual void StoreObject( wxObjectOutputStream
&stream
);
188 virtual void LoadObject( wxObjectInputStream
&stream
);
191 // make a 'clone' of the object
192 void Ref(const wxObject
& clone
);
194 // destroy a reference
197 inline wxObjectRefData
*GetRefData(void) const { return m_refData
; }
198 inline void SetRefData(wxObjectRefData
*data
) { m_refData
= data
; }
201 wxObjectRefData
*m_refData
;
203 wxObject_Serialize
*m_serialObj
;
211 class WXDLLEXPORT wxObjectRefData
{
213 friend class wxObject
;
216 wxObjectRefData(void);
217 virtual ~wxObjectRefData(void);
219 inline int GetRefCount(void) const { return m_count
; }
224 #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
226 #define WXDEBUG_NEW new(__FILE__,__LINE__)
228 #define new WXDEBUG_NEW