]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/object.h
Added WXHTREEITEM
[wxWidgets.git] / include / wx / object.h
... / ...
CommitLineData
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 _WX_OBJECTH__
13#define _WX_OBJECTH__
14
15#ifdef __GNUG__
16#pragma interface "object.h"
17#endif
18
19#include "wx/defs.h"
20#include "wx/memory.h"
21
22class WXDLLEXPORT wxObject;
23
24#if wxUSE_DYNAMIC_CLASSES
25
26#ifdef __GNUWIN32__
27#ifdef GetClassName
28#undef GetClassName
29#endif
30#endif
31
32class WXDLLEXPORT wxClassInfo;
33class WXDLLEXPORT wxInputStream;
34class WXDLLEXPORT wxObjectInputStream;
35class WXDLLEXPORT wxObjectOutputStream;
36class WXDLLEXPORT wxHashTable;
37class WXDLLEXPORT wxObject_Serialize;
38
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
48/*
49 * Dynamic object system declarations
50 */
51
52typedef wxObject * (*wxObjectConstructorFn) (void);
53
54class WXDLLEXPORT wxClassInfo
55{
56 public:
57 wxClassInfo(char *cName, char *baseName1, char *baseName2, int sz, wxObjectConstructorFn fn);
58
59 wxObject *CreateObject(void);
60
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; }
68 static inline wxClassInfo* GetFirst() { return sm_first; }
69 inline wxClassInfo* GetNext() const { return m_next; }
70 bool IsKindOf(wxClassInfo *info) const;
71
72 static wxClassInfo *FindClass(char *c);
73
74 // Initializes parent pointers and hash table for fast searching.
75 static void InitializeClasses(void);
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;
96};
97
98wxObject* WXDLLEXPORT wxCreateDynamicObject(const char *name);
99
100#ifdef wxUSE_SERIAL
101wxObject* WXDLLEXPORT wxCreateStoredObject( wxInputStream& stream );
102#endif
103
104#define DECLARE_DYNAMIC_CLASS(name) \
105 public:\
106 static wxClassInfo sm_class##name;\
107 wxClassInfo *GetClassInfo() const \
108 { return &name::sm_class##name; }
109
110#define DECLARE_ABSTRACT_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
111#define DECLARE_CLASS(name) DECLARE_DYNAMIC_CLASS(name)
112
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; }\
121 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
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; }\
127 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name);
128
129//////
130////// for abstract classes
131//////
132
133// Single inheritance with one base class
134#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
135 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename, \
136 (char *) NULL, (int) sizeof(name), (wxObjectConstructorFn) NULL);
137
138// Multiple inheritance with two base classes
139#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
140 wxClassInfo name::sm_class##name((char *) #name, (char *) #basename1, (char *) #basename2, (int) sizeof(name), (wxObjectConstructorFn) NULL);
141
142#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
143#define IMPLEMENT_CLASS2 IMPLEMENT_ABSTRACT_CLASS2
144
145#define CLASSINFO(name) (&name::sm_class##name)
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
162#define IS_KIND_OF(obj, className) obj->IsKindOf(&className::sm_class##className)
163
164// Unfortunately Borland seems to need this include.
165#ifdef __BORLANDC__
166#if wxUSE_IOSTREAMH
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
180 static wxClassInfo sm_classwxObject;
181
182 wxObject(void);
183 virtual ~wxObject(void);
184
185 virtual wxClassInfo *GetClassInfo(void) const { return &sm_classwxObject; }
186
187 bool IsKindOf(wxClassInfo *info) const;
188
189#if WXDEBUG && wxUSE_MEMORY_TRACING
190 void * operator new (size_t size, char * fileName = NULL, int lineNum = 0);
191 void operator delete (void * buf);
192
193// VC++ 6.0
194#if _MSC_VER >= 1200
195 void operator delete(void *buf, char*, int);
196#endif
197
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
206#if WXDEBUG || wxUSE_DEBUG_CONTEXT
207 virtual void Dump(ostream& str);
208#endif
209
210#ifdef wxUSE_SERIAL
211 virtual void StoreObject( wxObjectOutputStream &stream );
212 virtual void LoadObject( wxObjectInputStream &stream );
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:
225 wxObjectRefData* m_refData;
226#ifdef wxUSE_SERIAL
227 wxObject_Serialize* m_serialObj;
228#endif
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
248#if WXDEBUG && wxUSE_GLOBAL_MEMORY_OPERATORS
249//#ifndef WXDEBUG_NEW
250//#define WXDEBUG_NEW new(__FILE__,__LINE__)
251//#endif
252#define new new(__FILE__,__LINE__)
253#endif
254
255#endif
256 // _WX_OBJECTH__
257
258