]> git.saurik.com Git - wxWidgets.git/blame - include/wx/object.h
minor changes to registry classes and wxIniConfig added
[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
12#ifndef __OBJECTH__
13#define __OBJECTH__
14
15#ifdef __GNUG__
0d3820b3 16#pragma interface "object.h"
c801d85f
KB
17#endif
18
19#include "wx/defs.h"
20
21class WXDLLEXPORT wxObject;
22
23#if USE_DYNAMIC_CLASSES
24
25#ifdef __GNUWIN32__
26#ifdef GetClassName
27#undef GetClassName
28#endif
29#endif
30
31class WXDLLEXPORT wxClassInfo;
1678ad78
GL
32class WXDLLEXPORT ostream;
33class WXDLLEXPORT wxInputStream;
34class WXDLLIMPORT wxObjectInputStream;
35class WXDLLIMPORT wxObjectOutputStream;
c801d85f
KB
36
37/*
38 * Dynamic object system declarations
39 */
40
41typedef wxObject * (*wxObjectConstructorFn) (void);
42
c801d85f
KB
43class WXDLLEXPORT wxClassInfo
44{
45 public:
46 char *className;
47 char *baseClassName1;
48 char *baseClassName2;
49 int objectSize;
50 wxObjectConstructorFn objectConstructor;
51
c801d85f
KB
52 // Pointers to base wxClassInfos: set in InitializeClasses
53 // called from wx_main.cc
54 wxClassInfo *baseInfo1;
55 wxClassInfo *baseInfo2;
56
57 static wxClassInfo *first;
58 wxClassInfo *next;
59
c801d85f 60 wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn);
c801d85f
KB
61
62 wxObject *CreateObject(void);
63
c801d85f
KB
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);
69
70 static wxClassInfo *FindClass(char *c);
71 // Initializes parent pointers for fast searching.
72 static void InitializeClasses(void);
73};
74
75wxObject* WXDLLEXPORT wxCreateDynamicObject(char *name);
76
77#ifdef USE_STORABLE_CLASSES
1678ad78 78wxObject* WXDLLEXPORT wxCreateStoredObject( wxInputStream& stream );
c801d85f
KB
79#endif
80
81#define DECLARE_DYNAMIC_CLASS(name) \
82 public:\
83 static wxClassInfo class##name;\
84 wxClassInfo *GetClassInfo() \
85 { return &name::class##name; }
86
87#define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
88#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
89
c801d85f
KB
90//////
91////// for concrete classes
92//////
93
94// Single inheritance with one base class
95#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
96wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
97 { return new name; }\
98 wxClassInfo name::class##name(#name, #basename, NULL, sizeof(name), wxConstructorFor##name);
99
100// Multiple inheritance with two base classes
101#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
102wxObject* WXDLLEXPORT_CTORFN wxConstructorFor##name(void) \
103 { return new name; }\
104 wxClassInfo name::class##name(#name, #basename1, #basename2, sizeof(name), wxConstructorFor##name);
105
c801d85f
KB
106//////
107////// for abstract classes
108//////
109
110// Single inheritance with one base class
111#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
112 wxClassInfo name::class##name(#name, #basename, NULL, sizeof(name), NULL);
113
114// Multiple inheritance with two base classes
115#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
116 wxClassInfo name::class##name(#name, #basename1, #basename2, sizeof(name), NULL);
117
118#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
119#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
120
121#define CLASSINFO(name) (&name::class##name)
122
123#else
124
125// No dynamic class system: so stub out the macros
126#define DECLARE_DYNAMIC_CLASS(name)
127#define DECLARE_ABSTRACT_CLASS(name)
128#define DECLARE_CLASS(name)
129#define IMPLEMENT_DYNAMIC_CLASS(name, basename)
130#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)
131#define IMPLEMENT_ABSTRACT_CLASS(name, basename)
132#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)
133#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
134#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
135
136#endif
137
e3e65dac 138#define IS_KIND_OF(obj, className) obj->IsKindOf(&className::class##className)
c801d85f
KB
139
140// Unfortunately Borland seems to need this include.
141#ifdef __BORLANDC__
142#if USE_IOSTREAMH
143#include <iostream.h>
144#else
145#include <iostream>
146#endif
147#endif
148
149class WXDLLEXPORT wxObjectRefData;
150
151class WXDLLEXPORT wxObject
152{
153 public:
154
155 // This is equivalent to using the macro DECLARE_ABSTRACT_CLASS
156 static wxClassInfo classwxObject;
157
158 wxObject(void);
159 virtual ~wxObject(void);
160
161 virtual wxClassInfo *GetClassInfo(void) { return &classwxObject; }
162
163 bool IsKindOf(wxClassInfo *info);
164
b2aef89b 165#if WXDEBUG && USE_MEMORY_TRACING
c801d85f
KB
166 void * operator new (size_t size, char * fileName = NULL, int lineNum = 0);
167 void operator delete (void * buf);
168
169 // Cause problems for VC++
170#ifndef _MSC_VER
171 void * operator new[] (size_t size, char * fileName = NULL, int lineNum = 0);
172 void operator delete[] (void * buf);
173#endif
174
175#endif
176
3e1a3a40 177#if WXDEBUG || USE_DEBUG_CONTEXT
c801d85f
KB
178 virtual void Dump(ostream& str);
179#endif
180
181#ifdef USE_STORABLE_CLASSES
1678ad78
GL
182 virtual void StoreObject( wxObjectOutputStream &WXUNUSED(stream) ) {};
183 virtual void LoadObject( wxObjectInputStream &WXUNUSED(stream) ) {};
c801d85f
KB
184#endif
185
186 // make a 'clone' of the object
187 void Ref(const wxObject& clone);
188
189 // destroy a reference
190 void UnRef(void);
191
192 inline wxObjectRefData *GetRefData(void) const { return m_refData; }
193 inline void SetRefData(wxObjectRefData *data) { m_refData = data; }
194
195protected:
196 wxObjectRefData *m_refData;
197};
198
199/*
200 * wxObjectData
201 */
202
203class WXDLLEXPORT wxObjectRefData {
204
205 friend class wxObject;
206
207public:
208 wxObjectRefData(void);
209 virtual ~wxObjectRefData(void);
210
211 inline int GetRefCount(void) const { return m_count; }
212private:
213 int m_count;
214};
215
b2aef89b 216#if WXDEBUG && USE_GLOBAL_MEMORY_OPERATORS
c801d85f
KB
217#ifndef WXDEBUG_NEW
218#define WXDEBUG_NEW new(__FILE__,__LINE__)
219#endif
220#define new WXDEBUG_NEW
221#endif
222
223#endif
224 // __OBJECTH__
225
226