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((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) 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((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) 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((char *) #name, (char *) #basename, \
113 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
115 // Multiple inheritance with two base classes
116 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
117 wxClassInfo name::class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
119 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
120 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
122 #define CLASSINFO(name) (&name::class##name)
126 // No dynamic class system: so stub out the macros
127 #define DECLARE_DYNAMIC_CLASS(name)
128 #define DECLARE_ABSTRACT_CLASS(name)
129 #define DECLARE_CLASS(name)
130 #define IMPLEMENT_DYNAMIC_CLASS(name, basename)
131 #define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
132 #define IMPLEMENT_ABSTRACT_CLASS(name, basename)
133 #define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
134 #define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
135 #define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
139 #define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##className)
141 // Unfortunately Borland seems to need this include.
144 #include <iostream.h>
150 class WXDLLEXPORT wxObjectRefData
;
152 class WXDLLEXPORT wxObject
156 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
157 static wxClassInfo classwxObject
;
160 virtual ~wxObject(void);
162 virtual wxClassInfo
*GetClassInfo(void) { return &classwxObject
; }
164 bool IsKindOf(wxClassInfo
*info
);
166 #if WXDEBUG && USE_MEMORY_TRACING
167 void * operator new (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
168 void operator delete (void * buf
);
170 // Cause problems for VC++
172 void * operator new[] (size_t size
, char * fileName
= NULL
, int lineNum
= 0);
173 void operator delete[] (void * buf
);
178 #if WXDEBUG || USE_DEBUG_CONTEXT
179 virtual void Dump(ostream
& str
);
182 #ifdef USE_STORABLE_CLASSES
183 virtual void StoreObject( wxObjectOutputStream
&stream
);
184 virtual void LoadObject( wxObjectInputStream
&stream
);
187 // make a 'clone' of the object
188 void Ref(const wxObject
& clone
);
190 // destroy a reference
193 inline wxObjectRefData
*GetRefData(void) const { return m_refData
; }
194 inline void SetRefData(wxObjectRefData
*data
) { m_refData
= data
; }
197 wxObjectRefData
*m_refData
;
204 class WXDLLEXPORT wxObjectRefData
{
206 friend class wxObject
;
209 wxObjectRefData(void);
210 virtual ~wxObjectRefData(void);
212 inline int GetRefCount(void) const { return m_count
; }
217 #if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
219 #define WXDEBUG_NEW new(__FILE__,__LINE__)
221 #define new WXDEBUG_NEW