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"
20 #include "wx/memory.h"
22 class WXDLLEXPORT wxObject
;
24 #if wxUSE_DYNAMIC_CLASSES
32 class WXDLLEXPORT wxClassInfo
;
33 class WXDLLEXPORT wxInputStream
;
34 class WXDLLEXPORT wxObjectInputStream
;
35 class WXDLLEXPORT wxObjectOutputStream
;
36 class WXDLLEXPORT wxHashTable
;
37 class WXDLLEXPORT wxObject_Serialize
;
49 * Dynamic object system declarations
52 typedef wxObject
* (*wxObjectConstructorFn
) (void);
54 class WXDLLEXPORT wxClassInfo
57 wxClassInfo(char *cName
, char *baseName1
, char *baseName2
, int sz
, wxObjectConstructorFn fn
);
59 wxObject
*CreateObject(void);
61 inline char *GetClassName(void) const { return m_className
; }
62 inline char *GetBaseClassName1(void) const { return m_baseClassName1
; }
63 inline char *GetBaseClassName2(void) const { return m_baseClassName2
; }
64 inline wxClassInfo
* GetBaseClass1() const { return m_baseInfo1
; }
65 inline wxClassInfo
* GetBaseClass2() const { return m_baseInfo2
; }
66 inline int GetSize(void) const { return m_objectSize
; }
67 inline wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
68 static inline wxClassInfo
* GetFirst() { return sm_first
; }
69 inline wxClassInfo
* GetNext() const { return m_next
; }
70 bool IsKindOf(wxClassInfo
*info
) const;
72 static wxClassInfo
*FindClass(char *c
);
74 // Initializes parent pointers and hash table for fast searching.
75 static void InitializeClasses(void);
77 // Cleans up hash table used for fast searching.
78 static void CleanUpClasses(void);
82 char* m_baseClassName1
;
83 char* m_baseClassName2
;
85 wxObjectConstructorFn m_objectConstructor
;
87 // Pointers to base wxClassInfos: set in InitializeClasses
88 // called from wx_main.cc
89 wxClassInfo
* m_baseInfo1
;
90 wxClassInfo
* m_baseInfo2
;
92 static wxClassInfo
* sm_first
;
95 static wxHashTable
* sm_classTable
;
98 wxObject
* WXDLLEXPORT
wxCreateDynamicObject(const char *name
);
101 wxObject
* WXDLLEXPORT
wxCreateStoredObject( wxInputStream
& stream
);
104 #define DECLARE_DYNAMIC_CLASS(name) \
106 static wxClassInfo sm_class##name;\
107 wxClassInfo *GetClassInfo() const \
108 { return &name::sm_class##name; }
110 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
111 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
114 ////// for concrete classes
117 // Single inheritance with one base class
118 #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
119 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
120 { return new name; }\
121 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
123 // Multiple inheritance with two base classes
124 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
125 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
126 { return new name; }\
127 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
130 ////// for abstract classes
133 // Single inheritance with one base class
134 #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
135 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, \
136 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
138 // Multiple inheritance with two base classes
139 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
140 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
142 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
143 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
145 #define CLASSINFO(name) (&name::sm_class##name)
149 // No dynamic class system: so stub out the macros
150 #define DECLARE_DYNAMIC_CLASS(name)
151 #define DECLARE_ABSTRACT_CLASS(name)
152 #define DECLARE_CLASS(name)
153 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
154 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
155 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
156 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
157 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
158 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
162 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
164 // Unfortunately Borland seems to need this include.
167 #include <iostream.h>
173 class WXDLLEXPORT wxObjectRefData
;
175 class WXDLLEXPORT wxObject
179 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
180 static wxClassInfo sm_classwxObject
;
183 virtual ~wxObject(void);
185 virtual wxClassInfo
*GetClassInfo(void) const { return &sm_classwxObject
; }
187 bool IsKindOf(wxClassInfo
*info
) const;
189 #if WXDEBUG && wxUSE_MEMORY_TRACING
190 void * operator new (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
191 void operator delete (void * buf
);
195 void operator delete(void *buf
, char*, int);
198 // Cause problems for VC++
200 void * operator new[] (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
201 void operator delete[] (void * buf
);
206 #if WXDEBUG || wxUSE_DEBUG_CONTEXT
207 virtual void Dump(ostream
& str
);
211 virtual void StoreObject( wxObjectOutputStream
&stream
);
212 virtual void LoadObject( wxObjectInputStream
&stream
);
215 // make a 'clone' of the object
216 void Ref(const wxObject
& clone
);
218 // destroy a reference
221 inline wxObjectRefData
*GetRefData(void) const { return m_refData
; }
222 inline void SetRefData(wxObjectRefData
*data
) { m_refData
= data
; }
225 wxObjectRefData
* m_refData
;
227 wxObject_Serialize
* m_serialObj
;
235 class WXDLLEXPORT wxObjectRefData
{
237 friend class wxObject
;
240 wxObjectRefData(void);
241 virtual ~wxObjectRefData(void);
243 inline int GetRefCount(void) const { return m_count
; }
248 #if WXDEBUG && wxUSE_GLOBAL_MEMORY_OPERATORS
249 //#ifndef WXDEBUG_NEW
250 //#define WXDEBUG_NEW new(__FILE__,__LINE__)
252 #define new new(__FILE__,__LINE__)