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 USE_DYNAMIC_CLASSES
32 class WXDLLEXPORT wxClassInfo
;
33 class WXDLLIMPORT ostream
;
34 class WXDLLEXPORT wxInputStream
;
35 class WXDLLEXPORT wxObjectInputStream
;
36 class WXDLLEXPORT wxObjectOutputStream
;
37 class WXDLLEXPORT wxHashTable
;
38 class WXDLLEXPORT wxObject_Serialize
;
41 * Dynamic object system declarations
44 typedef wxObject
* (*wxObjectConstructorFn
) (void);
46 class WXDLLEXPORT wxClassInfo
49 wxClassInfo(char *cName
, char *baseName1
, char *baseName2
, int sz
, wxObjectConstructorFn fn
);
51 wxObject
*CreateObject(void);
53 inline char *GetClassName(void) const { return m_className
; }
54 inline char *GetBaseClassName1(void) const { return m_baseClassName1
; }
55 inline char *GetBaseClassName2(void) const { return m_baseClassName2
; }
56 inline wxClassInfo
* GetBaseClass1() const { return m_baseInfo1
; }
57 inline wxClassInfo
* GetBaseClass2() const { return m_baseInfo2
; }
58 inline int GetSize(void) const { return m_objectSize
; }
59 inline wxObjectConstructorFn
GetConstructor() const { return m_objectConstructor
; }
60 static inline wxClassInfo
* GetFirst() { return sm_first
; }
61 inline wxClassInfo
* GetNext() const { return m_next
; }
62 bool IsKindOf(wxClassInfo
*info
) const;
64 static wxClassInfo
*FindClass(char *c
);
66 // Initializes parent pointers and hash table for fast searching.
67 static void InitializeClasses(void);
69 // Cleans up hash table used for fast searching.
70 static void CleanUpClasses(void);
74 char* m_baseClassName1
;
75 char* m_baseClassName2
;
77 wxObjectConstructorFn m_objectConstructor
;
79 // Pointers to base wxClassInfos: set in InitializeClasses
80 // called from wx_main.cc
81 wxClassInfo
* m_baseInfo1
;
82 wxClassInfo
* m_baseInfo2
;
84 static wxClassInfo
* sm_first
;
87 static wxHashTable
* sm_classTable
;
90 wxObject
* WXDLLEXPORT
wxCreateDynamicObject(const char *name
);
93 wxObject
* WXDLLEXPORT
wxCreateStoredObject( wxInputStream
& stream
);
96 #define DECLARE_DYNAMIC_CLASS(name) \
98 static wxClassInfo sm_class##name;\
99 wxClassInfo *GetClassInfo() const \
100 { return &name::sm_class##name; }
102 #define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
103 #define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
106 ////// for concrete classes
109 // Single inheritance with one base class
110 #define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
111 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
112 { return new name; }\
113 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
115 // Multiple inheritance with two base classes
116 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
117 wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
118 { return new name; }\
119 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
122 ////// for abstract classes
125 // Single inheritance with one base class
126 #define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
127 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, \
128 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
130 // Multiple inheritance with two base classes
131 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
132 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
134 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
135 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
137 #define CLASSINFO(name) (&name::sm_class##name)
141 // No dynamic class system: so stub out the macros
142 #define DECLARE_DYNAMIC_CLASS(name)
143 #define DECLARE_ABSTRACT_CLASS(name)
144 #define DECLARE_CLASS(name)
145 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
146 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
147 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
148 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
149 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
150 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
154 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
156 // Unfortunately Borland seems to need this include.
159 #include <iostream.h>
165 class WXDLLEXPORT wxObjectRefData
;
167 class WXDLLEXPORT wxObject
171 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
172 static wxClassInfo sm_classwxObject
;
175 virtual ~wxObject(void);
177 virtual wxClassInfo
*GetClassInfo(void) const { return &sm_classwxObject
; }
179 bool IsKindOf(wxClassInfo
*info
) const;
181 #if WXDEBUG && USE_MEMORY_TRACING
182 void * operator new (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
183 void operator delete (void * buf
);
185 // Cause problems for VC++
187 void * operator new[] (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
188 void operator delete[] (void * buf
);
193 #if WXDEBUG || USE_DEBUG_CONTEXT
194 virtual void Dump(ostream
& str
);
198 virtual void StoreObject( wxObjectOutputStream
&stream
);
199 virtual void LoadObject( wxObjectInputStream
&stream
);
202 // make a 'clone' of the object
203 void Ref(const wxObject
& clone
);
205 // destroy a reference
208 inline wxObjectRefData
*GetRefData(void) const { return m_refData
; }
209 inline void SetRefData(wxObjectRefData
*data
) { m_refData
= data
; }
212 wxObjectRefData
* m_refData
;
214 wxObject_Serialize
* m_serialObj
;
222 class WXDLLEXPORT wxObjectRefData
{
224 friend class wxObject
;
227 wxObjectRefData(void);
228 virtual ~wxObjectRefData(void);
230 inline int GetRefCount(void) const { return m_count
; }
235 #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
236 //#ifndef WXDEBUG_NEW
237 //#define WXDEBUG_NEW new(__FILE__,__LINE__)
239 #define new new(__FILE__,__LINE__)