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
48 wxClassInfo(char *cName
, char *baseName1
, char *baseName2
, int sz
, wxObjectConstructorFn fn
);
50 wxObject
*CreateObject(void);
52 inline char *GetClassName(void) const { return m_className
; }
53 inline char *GetBaseClassName1(void) const { return m_baseClassName1
; }
54 inline char *GetBaseClassName2(void) const { return m_baseClassName2
; }
55 inline wxClassInfo
* GetBaseClass1() const { return m_baseInfo1
; }
56 inline wxClassInfo
* GetBaseClass2() const { return m_baseInfo2
; }
57 inline int GetSize(void) const { return m_objectSize
; }
58 inline wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
59 inline wxClassInfo
* GetFirst() const { return sm_first
; }
60 inline wxClassInfo
* GetNext() const { return m_next
; }
61 bool IsKindOf(wxClassInfo
*info
);
63 static wxClassInfo
*FindClass(char *c
);
65 // Initializes parent pointers and hash table for fast searching.
66 static void InitializeClasses(void);
68 // Cleans up hash table used for fast searching.
69 static void CleanUpClasses(void);
73 char* m_baseClassName1
;
74 char* m_baseClassName2
;
76 wxObjectConstructorFn m_objectConstructor
;
78 // Pointers to base wxClassInfos: set in InitializeClasses
79 // called from wx_main.cc
80 wxClassInfo
* m_baseInfo1
;
81 wxClassInfo
* m_baseInfo2
;
83 static wxClassInfo
* sm_first
;
86 static wxHashTable
* sm_classTable
;
89 wxObject
* WXDLLEXPORT
wxCreateDynamicObject(const char *name
);
92 wxObject
* WXDLLEXPORT
wxCreateStoredObject( wxInputStream
& stream
);
95 #define DECLARE_DYNAMIC_CLASS(name) \
97 static wxClassInfo sm_class##name;\
98 wxClassInfo *GetClassInfo() \
99 { return &name::sm_class##name; }
101 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
102 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
105 ////// for concrete classes
108 // Single inheritance with one base class
109 #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
110 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
111 { return new name; }\
112 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
114 // Multiple inheritance with two base classes
115 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
116 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
117 { return new name; }\
118 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
121 ////// for abstract classes
124 // Single inheritance with one base class
125 #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
126 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, \
127 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
129 // Multiple inheritance with two base classes
130 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
131 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
133 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
134 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
136 #define CLASSINFO(name) (&name::sm_class##name)
140 // No dynamic class system: so stub out the macros
141 #define DECLARE_DYNAMIC_CLASS(name)
142 #define DECLARE_ABSTRACT_CLASS(name)
143 #define DECLARE_CLASS(name)
144 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
145 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
146 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
147 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
148 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
149 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
153 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
155 // Unfortunately Borland seems to need this include.
158 #include <iostream.h>
164 class WXDLLEXPORT wxObjectRefData
;
166 class WXDLLEXPORT wxObject
170 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
171 static wxClassInfo sm_classwxObject
;
174 virtual ~wxObject(void);
176 virtual wxClassInfo
*GetClassInfo(void) { return &sm_classwxObject
; }
178 bool IsKindOf(wxClassInfo
*info
);
180 #if WXDEBUG && USE_MEMORY_TRACING
181 void * operator new (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
182 void operator delete (void * buf
);
184 // Cause problems for VC++
186 void * operator new[] (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
187 void operator delete[] (void * buf
);
192 #if WXDEBUG || USE_DEBUG_CONTEXT
193 virtual void Dump(ostream
& str
);
197 virtual void StoreObject( wxObjectOutputStream
&stream
);
198 virtual void LoadObject( wxObjectInputStream
&stream
);
201 // make a 'clone' of the object
202 void Ref(const wxObject
& clone
);
204 // destroy a reference
207 inline wxObjectRefData
*GetRefData(void) const { return m_refData
; }
208 inline void SetRefData(wxObjectRefData
*data
) { m_refData
= data
; }
211 wxObjectRefData
* m_refData
;
213 wxObject_Serialize
* m_serialObj
;
221 class WXDLLEXPORT wxObjectRefData
{
223 friend class wxObject
;
226 wxObjectRefData(void);
227 virtual ~wxObjectRefData(void);
229 inline int GetRefCount(void) const { return m_count
; }
234 #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
236 #define WXDEBUG_NEW new(__FILE__,__LINE__)
238 #define new WXDEBUG_NEW