]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
Made wxGTK dcps.cpp generic.
[wxWidgets.git] / include / wx / object.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: object.h
3// Purpose: wxObject class, plus run-time type information macros
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_OBJECTH__
13#define _WX_OBJECTH__
c801d85f
KB
14
15#ifdef __GNUG__
0d3820b3 16#pragma interface "object.h"
c801d85f
KB
17#endif
18
19#include "wx/defs.h"
e55ad60e 20#include "wx/memory.h"
c801d85f
KB
21
22class WXDLLEXPORT wxObject;
23
47d67540 24#if wxUSE_DYNAMIC_CLASSES
c801d85f 25
3f1af920 26// #ifdef __GNUWIN32__
c801d85f
KB
27#ifdef GetClassName
28#undef GetClassName
29#endif
3f1af920
JS
30#ifdef GetClassInfo
31#undef GetClassInfo
c801d85f 32#endif
3f1af920 33// #endif
c801d85f
KB
34
35class WXDLLEXPORT wxClassInfo;
1678ad78 36class WXDLLEXPORT wxInputStream;
f4a8c29f
GL
37class WXDLLEXPORT wxObjectInputStream;
38class WXDLLEXPORT wxObjectOutputStream;
39class WXDLLEXPORT wxHashTable;
40class WXDLLEXPORT wxObject_Serialize;
c801d85f 41
fbc535ff 42#if wxUSE_IOSTREAMH
4b5f3fe6
JS
43// N.B. BC++ doesn't have istream.h, ostream.h
44# include <iostream.h>
fbc535ff
JS
45#else
46# include <ostream>
47# ifdef _MSC_VER
48 using namespace std;
49# endif
50#endif
51
c801d85f
KB
52/*
53 * Dynamic object system declarations
54 */
55
56typedef wxObject * (*wxObjectConstructorFn) (void);
57
c801d85f
KB
58class WXDLLEXPORT wxClassInfo
59{
60 public:
c801d85f 61 wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn);
c801d85f
KB
62
63 wxObject *CreateObject(void);
64
0c32066b
JS
65 inline char *GetClassName(void) const { return m_className; }
66 inline char *GetBaseClassName1(void) const { return m_baseClassName1; }
67 inline char *GetBaseClassName2(void) const { return m_baseClassName2; }
68 inline wxClassInfo* GetBaseClass1() const { return m_baseInfo1; }
69 inline wxClassInfo* GetBaseClass2() const { return m_baseInfo2; }
70 inline int GetSize(void) const { return m_objectSize; }
71 inline wxObjectConstructorFn GetConstructor() const { return m_objectConstructor; }
856d2e52 72 static inline wxClassInfo* GetFirst() { return sm_first; }
0c32066b 73 inline wxClassInfo* GetNext() const { return m_next; }
8cb50e4b 74 bool IsKindOf(wxClassInfo *info) const;
c801d85f
KB
75
76 static wxClassInfo *FindClass(char *c);
0c32066b
JS
77
78 // Initializes parent pointers and hash table for fast searching.
c801d85f 79 static void InitializeClasses(void);
0c32066b
JS
80
81 // Cleans up hash table used for fast searching.
82 static void CleanUpClasses(void);
83
84public:
85 char* m_className;
86 char* m_baseClassName1;
87 char* m_baseClassName2;
88 int m_objectSize;
89 wxObjectConstructorFn m_objectConstructor;
90
91 // Pointers to base wxClassInfos: set in InitializeClasses
92 // called from wx_main.cc
93 wxClassInfo* m_baseInfo1;
94 wxClassInfo* m_baseInfo2;
95
96 static wxClassInfo* sm_first;
97 wxClassInfo* m_next;
98
99 static wxHashTable* sm_classTable;
c801d85f
KB
100};
101
184b5d99 102WXDLLEXPORT wxObject* wxCreateDynamicObject(const char *name);
c801d85f 103
47d67540 104#ifdef wxUSE_SERIAL
184b5d99 105WXDLLEXPORT wxObject* wxCreateStoredObject( wxInputStream& stream );
c801d85f
KB
106#endif
107
108#define DECLARE_DYNAMIC_CLASS(name) \
109 public:\
0c32066b 110 static wxClassInfo sm_class##name;\
8cb50e4b 111 wxClassInfo *GetClassInfo() const \
0c32066b 112 { return &name::sm_class##name; }
c801d85f
KB
113
114#define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
115#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
116
c801d85f
KB
117//////
118////// for concrete classes
119//////
120
121// Single inheritance with one base class
122#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
123wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
124 { return new name; }\
0c32066b 125 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f
KB
126
127// Multiple inheritance with two base classes
128#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
129wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
130 { return new name; }\
0c32066b 131 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f 132
c801d85f
KB
133//////
134////// for abstract classes
135//////
136
137// Single inheritance with one base class
138#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
0c32066b 139 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, \
c67daf87 140 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
c801d85f
KB
141
142// Multiple inheritance with two base classes
143#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
0c32066b 144 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
c801d85f
KB
145
146#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
147#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
148
0c32066b 149#define CLASSINFO(name) (&name::sm_class##name)
c801d85f
KB
150
151#else
152
153// No dynamic class system: so stub out the macros
154#define DECLARE_DYNAMIC_CLASS(name)
155#define DECLARE_ABSTRACT_CLASS(name)
156#define DECLARE_CLASS(name)
157#define IMPLEMENT_DYNAMIC_CLASS(name, basename)
158#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
159#define IMPLEMENT_ABSTRACT_CLASS(name, basename)
160#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
161#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
162#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
163
164#endif
165
3013b6f4
JS
166#define wxIS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
167
168// Just seems a bit nicer-looking (pretend it's not a macro)
169#define wxIsKindOf(obj, className) obj->IsKindOf(&className::sm_class##className)
c801d85f
KB
170
171// Unfortunately Borland seems to need this include.
172#ifdef __BORLANDC__
47d67540 173#if wxUSE_IOSTREAMH
c801d85f
KB
174#include <iostream.h>
175#else
176#include <iostream>
177#endif
178#endif
179
180class WXDLLEXPORT wxObjectRefData;
181
182class WXDLLEXPORT wxObject
183{
184 public:
185
186 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
0c32066b 187 static wxClassInfo sm_classwxObject;
c801d85f
KB
188
189 wxObject(void);
190 virtual ~wxObject(void);
191
8cb50e4b 192 virtual wxClassInfo *GetClassInfo(void) const { return &sm_classwxObject; }
c801d85f 193
8cb50e4b 194 bool IsKindOf(wxClassInfo *info) const;
c801d85f 195
ea57084d 196#if defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING
c801d85f
KB
197 void * operator new (size_t size, char * fileName = NULL, int lineNum = 0);
198 void operator delete (void * buf);
27198be4 199
76626af2
JS
200// VC++ 6.0
201#if _MSC_VER >= 1200
202 void operator delete(void *buf, char*, int);
203#endif
204
c801d85f 205 // Cause problems for VC++
5dcf05ae
JS
206// #ifndef _MSC_VER
207#if !defined(_MSC_VER) && wxUSE_ARRAY_MEMORY_OPERATORS
c801d85f
KB
208 void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0);
209 void operator delete[] (void * buf);
210#endif
211
5dcf05ae 212/*
27198be4
SC
213#ifdef __MWERKS__
214 void * operator new[] (size_t size, char * fileName , int lineNum = 0);
215 void operator delete[] (void * buf);
216#endif
5dcf05ae 217*/
27198be4 218
c801d85f
KB
219#endif
220
ea57084d 221#if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT
c801d85f
KB
222 virtual void Dump(ostream& str);
223#endif
224
47d67540 225#ifdef wxUSE_SERIAL
7a4b9130
GL
226 virtual void StoreObject( wxObjectOutputStream &stream );
227 virtual void LoadObject( wxObjectInputStream &stream );
c801d85f
KB
228#endif
229
230 // make a 'clone' of the object
231 void Ref(const wxObject& clone);
232
233 // destroy a reference
234 void UnRef(void);
235
236 inline wxObjectRefData *GetRefData(void) const { return m_refData; }
237 inline void SetRefData(wxObjectRefData *data) { m_refData = data; }
238
239protected:
0c32066b 240 wxObjectRefData* m_refData;
47d67540 241#ifdef wxUSE_SERIAL
0c32066b 242 wxObject_Serialize* m_serialObj;
f4a8c29f 243#endif
c801d85f
KB
244};
245
246/*
247 * wxObjectData
248 */
249
250class WXDLLEXPORT wxObjectRefData {
251
252 friend class wxObject;
253
254public:
255 wxObjectRefData(void);
256 virtual ~wxObjectRefData(void);
257
258 inline int GetRefCount(void) const { return m_count; }
259private:
260 int m_count;
261};
262
7fe7d506
JS
263#ifdef __WXDEBUG__
264#ifndef WXDEBUG_NEW
265#define WXDEBUG_NEW new(__FILE__,__LINE__)
266#endif
267#else
268#define WXDEBUG_NEW new
269#endif
270
271// Redefine new to be the debugging version. This doesn't
272// work with all compilers, in which case you need to
273// use WXDEBUG_NEW explicitly if you wish to use the debugging version.
274
275#if defined(__WXDEBUG__) && wxUSE_GLOBAL_MEMORY_OPERATORS && wxUSE_DEBUG_NEW_ALWAYS
e55ad60e 276#define new new(__FILE__,__LINE__)
c801d85f
KB
277#endif
278
279#endif
34138703 280 // _WX_OBJECTH__
c801d85f
KB
281
282