]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
Motif updates
[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
KB
25
26#ifdef __GNUWIN32__
27#ifdef GetClassName
28#undef GetClassName
29#endif
30#endif
31
32class WXDLLEXPORT wxClassInfo;
1678ad78 33class WXDLLEXPORT wxInputStream;
f4a8c29f
GL
34class WXDLLEXPORT wxObjectInputStream;
35class WXDLLEXPORT wxObjectOutputStream;
36class WXDLLEXPORT wxHashTable;
37class WXDLLEXPORT wxObject_Serialize;
c801d85f 38
fbc535ff
JS
39#if wxUSE_IOSTREAMH
40# include <ostream.h>
41#else
42# include <ostream>
43# ifdef _MSC_VER
44 using namespace std;
45# endif
46#endif
47
c801d85f
KB
48/*
49 * Dynamic object system declarations
50 */
51
52typedef wxObject * (*wxObjectConstructorFn) (void);
53
c801d85f
KB
54class WXDLLEXPORT wxClassInfo
55{
56 public:
c801d85f 57 wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn);
c801d85f
KB
58
59 wxObject *CreateObject(void);
60
0c32066b
JS
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; }
856d2e52 68 static inline wxClassInfo* GetFirst() { return sm_first; }
0c32066b 69 inline wxClassInfo* GetNext() const { return m_next; }
8cb50e4b 70 bool IsKindOf(wxClassInfo *info) const;
c801d85f
KB
71
72 static wxClassInfo *FindClass(char *c);
0c32066b
JS
73
74 // Initializes parent pointers and hash table for fast searching.
c801d85f 75 static void InitializeClasses(void);
0c32066b
JS
76
77 // Cleans up hash table used for fast searching.
78 static void CleanUpClasses(void);
79
80public:
81 char* m_className;
82 char* m_baseClassName1;
83 char* m_baseClassName2;
84 int m_objectSize;
85 wxObjectConstructorFn m_objectConstructor;
86
87 // Pointers to base wxClassInfos: set in InitializeClasses
88 // called from wx_main.cc
89 wxClassInfo* m_baseInfo1;
90 wxClassInfo* m_baseInfo2;
91
92 static wxClassInfo* sm_first;
93 wxClassInfo* m_next;
94
95 static wxHashTable* sm_classTable;
c801d85f
KB
96};
97
0c32066b 98wxObject* WXDLLEXPORT wxCreateDynamicObject(const char *name);
c801d85f 99
47d67540 100#ifdef wxUSE_SERIAL
1678ad78 101wxObject* WXDLLEXPORT wxCreateStoredObject( wxInputStream& stream );
c801d85f
KB
102#endif
103
104#define DECLARE_DYNAMIC_CLASS(name) \
105 public:\
0c32066b 106 static wxClassInfo sm_class##name;\
8cb50e4b 107 wxClassInfo *GetClassInfo() const \
0c32066b 108 { return &name::sm_class##name; }
c801d85f
KB
109
110#define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
111#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
112
c801d85f
KB
113//////
114////// for concrete classes
115//////
116
117// Single inheritance with one base class
118#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
119wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
120 { return new name; }\
0c32066b 121 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f
KB
122
123// Multiple inheritance with two base classes
124#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
125wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
126 { return new name; }\
0c32066b 127 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
c801d85f 128
c801d85f
KB
129//////
130////// for abstract classes
131//////
132
133// Single inheritance with one base class
134#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
0c32066b 135 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, \
c67daf87 136 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
c801d85f
KB
137
138// Multiple inheritance with two base classes
139#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
0c32066b 140 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
c801d85f
KB
141
142#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
143#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
144
0c32066b 145#define CLASSINFO(name) (&name::sm_class##name)
c801d85f
KB
146
147#else
148
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
159
160#endif
161
0c32066b 162#define IS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
c801d85f
KB
163
164// Unfortunately Borland seems to need this include.
165#ifdef __BORLANDC__
47d67540 166#if wxUSE_IOSTREAMH
c801d85f
KB
167#include <iostream.h>
168#else
169#include <iostream>
170#endif
171#endif
172
173class WXDLLEXPORT wxObjectRefData;
174
175class WXDLLEXPORT wxObject
176{
177 public:
178
179 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
0c32066b 180 static wxClassInfo sm_classwxObject;
c801d85f
KB
181
182 wxObject(void);
183 virtual ~wxObject(void);
184
8cb50e4b 185 virtual wxClassInfo *GetClassInfo(void) const { return &sm_classwxObject; }
c801d85f 186
8cb50e4b 187 bool IsKindOf(wxClassInfo *info) const;
c801d85f 188
47d67540 189#if WXDEBUG && wxUSE_MEMORY_TRACING
c801d85f
KB
190 void * operator new (size_t size, char * fileName = NULL, int lineNum = 0);
191 void operator delete (void * buf);
192
76626af2
JS
193// VC++ 6.0
194#if _MSC_VER >= 1200
195 void operator delete(void *buf, char*, int);
196#endif
197
c801d85f
KB
198 // Cause problems for VC++
199#ifndef _MSC_VER
200 void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0);
201 void operator delete[] (void * buf);
202#endif
203
204#endif
205
47d67540 206#if WXDEBUG || wxUSE_DEBUG_CONTEXT
c801d85f
KB
207 virtual void Dump(ostream& str);
208#endif
209
47d67540 210#ifdef wxUSE_SERIAL
7a4b9130
GL
211 virtual void StoreObject( wxObjectOutputStream &stream );
212 virtual void LoadObject( wxObjectInputStream &stream );
c801d85f
KB
213#endif
214
215 // make a 'clone' of the object
216 void Ref(const wxObject& clone);
217
218 // destroy a reference
219 void UnRef(void);
220
221 inline wxObjectRefData *GetRefData(void) const { return m_refData; }
222 inline void SetRefData(wxObjectRefData *data) { m_refData = data; }
223
224protected:
0c32066b 225 wxObjectRefData* m_refData;
47d67540 226#ifdef wxUSE_SERIAL
0c32066b 227 wxObject_Serialize* m_serialObj;
f4a8c29f 228#endif
c801d85f
KB
229};
230
231/*
232 * wxObjectData
233 */
234
235class WXDLLEXPORT wxObjectRefData {
236
237 friend class wxObject;
238
239public:
240 wxObjectRefData(void);
241 virtual ~wxObjectRefData(void);
242
243 inline int GetRefCount(void) const { return m_count; }
244private:
245 int m_count;
246};
247
47d67540 248#if WXDEBUG && wxUSE_GLOBAL_MEMORY_OPERATORS
e55ad60e
RR
249//#ifndef WXDEBUG_NEW
250//#define WXDEBUG_NEW new(__FILE__,__LINE__)
251//#endif
252#define new new(__FILE__,__LINE__)
c801d85f
KB
253#endif
254
255#endif
34138703 256 // _WX_OBJECTH__
c801d85f
KB
257
258