Coverage Report

Created: 2025-06-13 06:30

/src/wxwidgets/include/wx/rtti.h
Line
Count
Source (jump to first uncovered line)
1
/////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/rtti.h
3
// Purpose:     old RTTI macros (use XTI when possible instead)
4
// Author:      Julian Smart
5
// Modified by: Ron Lee
6
// Created:     01/02/97
7
// Copyright:   (c) 1997 Julian Smart
8
//              (c) 2001 Ron Lee <ron@debian.org>
9
// Licence:     wxWindows licence
10
/////////////////////////////////////////////////////////////////////////////
11
12
#ifndef _WX_RTTIH__
13
#define _WX_RTTIH__
14
15
#include "wx/defs.h"
16
17
#if !wxUSE_EXTENDED_RTTI     // XTI system is meant to replace these macros
18
19
// ----------------------------------------------------------------------------
20
// forward declarations
21
// ----------------------------------------------------------------------------
22
23
class WXDLLIMPEXP_FWD_BASE wxObject;
24
class WXDLLIMPEXP_FWD_BASE wxString;
25
class WXDLLIMPEXP_FWD_BASE wxHashTable;
26
class WXDLLIMPEXP_FWD_BASE wxPluginLibrary;
27
class WXDLLIMPEXP_FWD_BASE wxHashTable_Node;
28
29
#define wxDECLARE_CLASS_INFO_ITERATORS()                                     \
30
class WXDLLIMPEXP_BASE const_iterator                                    \
31
    {                                                                        \
32
    typedef wxHashTable_Node Node;                                       \
33
    public:                                                                  \
34
    typedef const wxClassInfo* value_type;                               \
35
    typedef const value_type& const_reference;                           \
36
    typedef const_iterator itor;                                         \
37
    typedef value_type* ptr_type;                                        \
38
    \
39
    Node* m_node;                                                        \
40
    wxHashTable* m_table;                                                \
41
    public:                                                                  \
42
    typedef const_reference reference_type;                              \
43
    typedef ptr_type pointer_type;                                       \
44
    \
45
    const_iterator(Node* node, wxHashTable* table)                       \
46
0
    : m_node(node), m_table(table) { }                               \
47
0
    const_iterator() : m_node(nullptr), m_table(nullptr) { }                   \
48
    value_type operator*() const;                                        \
49
    itor& operator++();                                                  \
50
    const itor operator++(int);                                          \
51
    bool operator!=(const itor& it) const                                \
52
0
            { return it.m_node != m_node; }                                  \
53
            bool operator==(const itor& it) const                                \
54
0
            { return it.m_node == m_node; }                                  \
55
    };                                                                       \
56
    \
57
    static const_iterator begin_classinfo();                                 \
58
    static const_iterator end_classinfo()
59
60
// Compatibility macro not requiring semicolon after it, don't use.
61
#define DECLARE_CLASS_INFO_ITERATORS() wxDECLARE_CLASS_INFO_ITERATORS();
62
63
// ----------------------------------------------------------------------------
64
// wxClassInfo
65
// ----------------------------------------------------------------------------
66
67
typedef wxObject *(*wxObjectConstructorFn)(void);
68
69
class WXDLLIMPEXP_BASE wxClassInfo
70
{
71
    friend class WXDLLIMPEXP_FWD_BASE wxObject;
72
    friend WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name);
73
public:
74
    wxClassInfo( const wxChar *className,
75
                 const wxClassInfo *baseInfo1,
76
                 const wxClassInfo *baseInfo2,
77
                 int size,
78
                 wxObjectConstructorFn ctor )
79
76
        : m_className(className)
80
76
        , m_objectSize(size)
81
76
        , m_objectConstructor(ctor)
82
76
        , m_baseInfo1(baseInfo1)
83
76
        , m_baseInfo2(baseInfo2)
84
76
        , m_next(sm_first)
85
76
        {
86
76
            sm_first = this;
87
76
            Register();
88
76
        }
89
90
    ~wxClassInfo();
91
92
    wxObject *CreateObject() const
93
0
        { return m_objectConstructor ? (*m_objectConstructor)() : nullptr; }
94
0
    bool IsDynamic() const { return (nullptr != m_objectConstructor); }
95
96
0
    const wxChar       *GetClassName() const { return m_className; }
97
    const wxChar       *GetBaseClassName1() const
98
0
        { return m_baseInfo1 ? m_baseInfo1->GetClassName() : nullptr; }
99
    const wxChar       *GetBaseClassName2() const
100
0
        { return m_baseInfo2 ? m_baseInfo2->GetClassName() : nullptr; }
101
0
    const wxClassInfo  *GetBaseClass1() const { return m_baseInfo1; }
102
0
    const wxClassInfo  *GetBaseClass2() const { return m_baseInfo2; }
103
0
    int                 GetSize() const { return m_objectSize; }
104
105
    wxObjectConstructorFn      GetConstructor() const
106
0
        { return m_objectConstructor; }
107
0
    static const wxClassInfo  *GetFirst() { return sm_first; }
108
0
    const wxClassInfo         *GetNext() const { return m_next; }
109
    static wxClassInfo        *FindClass(const wxString& className);
110
111
        // Climb upwards through inheritance hierarchy.
112
        // Dual inheritance is catered for.
113
114
    bool IsKindOf(const wxClassInfo *info) const
115
0
    {
116
0
        if ( info == this )
117
0
            return true;
118
119
0
        if ( m_baseInfo1 )
120
0
        {
121
0
            if ( m_baseInfo1->IsKindOf(info) )
122
0
                return true;
123
0
        }
124
125
0
        if ( m_baseInfo2 )
126
0
        {
127
0
            if ( m_baseInfo2->IsKindOf(info) )
128
0
                return true;
129
0
        }
130
131
0
        return false;
132
0
    }
133
134
    wxDECLARE_CLASS_INFO_ITERATORS();
135
136
private:
137
    const wxChar            *m_className;
138
    int                      m_objectSize;
139
    wxObjectConstructorFn    m_objectConstructor;
140
141
        // Pointers to base wxClassInfos
142
143
    const wxClassInfo       *m_baseInfo1;
144
    const wxClassInfo       *m_baseInfo2;
145
146
        // class info object live in a linked list:
147
        // pointers to its head and the next element in it
148
149
    static wxClassInfo      *sm_first;
150
    wxClassInfo             *m_next;
151
152
    static wxHashTable      *sm_classTable;
153
154
protected:
155
    // registers the class
156
    void Register();
157
    void Unregister();
158
159
    wxDECLARE_NO_COPY_CLASS(wxClassInfo);
160
};
161
162
WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name);
163
164
// ----------------------------------------------------------------------------
165
// Dynamic class macros
166
// ----------------------------------------------------------------------------
167
168
#define wxDECLARE_ABSTRACT_CLASS(name)                                        \
169
    public:                                                                   \
170
        wxWARNING_SUPPRESS_MISSING_OVERRIDE()                                 \
171
        virtual wxClassInfo *GetClassInfo() const wxDUMMY_OVERRIDE;           \
172
        wxWARNING_RESTORE_MISSING_OVERRIDE()                                  \
173
        static wxClassInfo ms_classInfo
174
175
#define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(name)                               \
176
    wxDECLARE_NO_ASSIGN_CLASS(name);                                          \
177
    wxDECLARE_DYNAMIC_CLASS(name)
178
179
#define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN_DEF_COPY(name)                      \
180
    wxDECLARE_NO_ASSIGN_DEF_COPY(name);                                       \
181
    wxDECLARE_DYNAMIC_CLASS(name)
182
183
#define wxDECLARE_DYNAMIC_CLASS_NO_COPY(name)                                 \
184
    wxDECLARE_NO_COPY_CLASS(name);                                            \
185
    wxDECLARE_DYNAMIC_CLASS(name)
186
187
#define wxDECLARE_DYNAMIC_CLASS(name)                                         \
188
    wxDECLARE_ABSTRACT_CLASS(name);                                           \
189
    static wxObject* wxCreateObject()
190
191
#define wxDECLARE_CLASS(name)                                                 \
192
    wxDECLARE_ABSTRACT_CLASS(name)
193
194
195
// common part of the macros below
196
#define wxIMPLEMENT_CLASS_COMMON(name, basename, baseclsinfo2, func)          \
197
    wxClassInfo name::ms_classInfo(wxT(#name),                                \
198
            &basename::ms_classInfo,                                          \
199
            baseclsinfo2,                                                     \
200
            (int) sizeof(name),                                               \
201
            func);                                                            \
202
                                                                              \
203
    wxClassInfo *name::GetClassInfo() const                                   \
204
0
        { return &name::ms_classInfo; }
Unexecuted instantiation: wxConfigBase::GetClassInfo() const
Unexecuted instantiation: wxFileConfig::GetClassInfo() const
Unexecuted instantiation: wxFontMapperModule::GetClassInfo() const
Unexecuted instantiation: wxModule::GetClassInfo() const
Unexecuted instantiation: wxMemoryInputStream::GetClassInfo() const
Unexecuted instantiation: wxMemoryOutputStream::GetClassInfo() const
Unexecuted instantiation: wxStreamBase::GetClassInfo() const
Unexecuted instantiation: wxInputStream::GetClassInfo() const
Unexecuted instantiation: wxOutputStream::GetClassInfo() const
Unexecuted instantiation: wxCountingOutputStream::GetClassInfo() const
Unexecuted instantiation: wxFilterInputStream::GetClassInfo() const
Unexecuted instantiation: wxFilterOutputStream::GetClassInfo() const
Unexecuted instantiation: wxFilterClassFactoryBase::GetClassInfo() const
Unexecuted instantiation: wxFilterClassFactory::GetClassInfo() const
Unexecuted instantiation: wxTranslationsModule::GetClassInfo() const
Unexecuted instantiation: wxURI::GetClassInfo() const
Unexecuted instantiation: wxXLocaleModule::GetClassInfo() const
Unexecuted instantiation: wxZipEntry::GetClassInfo() const
Unexecuted instantiation: wxZipClassFactory::GetClassInfo() const
Unexecuted instantiation: wxZlibClassFactory::GetClassInfo() const
Unexecuted instantiation: wxGzipClassFactory::GetClassInfo() const
Unexecuted instantiation: wxTimerUnixModule::GetClassInfo() const
Unexecuted instantiation: wxThreadModule::GetClassInfo() const
Unexecuted instantiation: wxEvtHandler::GetClassInfo() const
Unexecuted instantiation: wxEvent::GetClassInfo() const
Unexecuted instantiation: wxIdleEvent::GetClassInfo() const
Unexecuted instantiation: wxThreadEvent::GetClassInfo() const
Unexecuted instantiation: wxAnyValueTypeGlobalsManager::GetClassInfo() const
Unexecuted instantiation: wxArchiveEntry::GetClassInfo() const
Unexecuted instantiation: wxArchiveClassFactory::GetClassInfo() const
Unexecuted instantiation: wxDateTimeHolidaysModule::GetClassInfo() const
Unexecuted instantiation: wxLocaleModule::GetClassInfo() const
Unexecuted instantiation: wxProcess::GetClassInfo() const
Unexecuted instantiation: wxProcessEvent::GetClassInfo() const
Unexecuted instantiation: wxVariant::GetClassInfo() const
Unexecuted instantiation: wxFDIODispatcherModule::GetClassInfo() const
Unexecuted instantiation: wxTimerEvent::GetClassInfo() const
205
206
#define wxIMPLEMENT_CLASS_COMMON1(name, basename, func)                       \
207
    wxIMPLEMENT_CLASS_COMMON(name, basename, nullptr, func)
208
209
#define wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, func)           \
210
    wxIMPLEMENT_CLASS_COMMON(name, basename1, &basename2::ms_classInfo, func)
211
212
// -----------------------------------
213
// for concrete classes
214
// -----------------------------------
215
216
    // Single inheritance with one base class
217
#define wxIMPLEMENT_DYNAMIC_CLASS(name, basename)                             \
218
    wxIMPLEMENT_CLASS_COMMON1(name, basename, name::wxCreateObject)           \
219
    wxObject* name::wxCreateObject()                                          \
220
0
        { return new name; }
Unexecuted instantiation: wxFontMapperModule::wxCreateObject()
Unexecuted instantiation: wxMemoryOutputStream::wxCreateObject()
Unexecuted instantiation: wxCountingOutputStream::wxCreateObject()
Unexecuted instantiation: wxTranslationsModule::wxCreateObject()
Unexecuted instantiation: wxXLocaleModule::wxCreateObject()
Unexecuted instantiation: wxZipEntry::wxCreateObject()
Unexecuted instantiation: wxZipClassFactory::wxCreateObject()
Unexecuted instantiation: wxZlibClassFactory::wxCreateObject()
Unexecuted instantiation: wxGzipClassFactory::wxCreateObject()
Unexecuted instantiation: wxTimerUnixModule::wxCreateObject()
Unexecuted instantiation: wxThreadModule::wxCreateObject()
Unexecuted instantiation: wxEvtHandler::wxCreateObject()
Unexecuted instantiation: wxIdleEvent::wxCreateObject()
Unexecuted instantiation: wxThreadEvent::wxCreateObject()
Unexecuted instantiation: wxAnyValueTypeGlobalsManager::wxCreateObject()
Unexecuted instantiation: wxDateTimeHolidaysModule::wxCreateObject()
Unexecuted instantiation: wxLocaleModule::wxCreateObject()
Unexecuted instantiation: wxProcess::wxCreateObject()
Unexecuted instantiation: wxProcessEvent::wxCreateObject()
Unexecuted instantiation: wxVariant::wxCreateObject()
Unexecuted instantiation: wxFDIODispatcherModule::wxCreateObject()
221
222
    // Multiple inheritance with two base classes
223
#define wxIMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2)                \
224
    wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2,                     \
225
                              name::wxCreateObject)                           \
226
    wxObject* name::wxCreateObject()                                          \
227
        { return new name; }
228
229
// -----------------------------------
230
// for abstract classes
231
// -----------------------------------
232
233
    // Single inheritance with one base class
234
#define wxIMPLEMENT_ABSTRACT_CLASS(name, basename)                            \
235
    wxIMPLEMENT_CLASS_COMMON1(name, basename, nullptr)
236
237
    // Multiple inheritance with two base classes
238
#define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2)               \
239
    wxIMPLEMENT_CLASS_COMMON2(name, basename1, basename2, nullptr)
240
241
// -----------------------------------
242
// XTI-compatible macros
243
// -----------------------------------
244
245
#include "wx/flags.h"
246
247
// these macros only do something when wxUSE_EXTENDED_RTTI=1
248
// (and in that case they are defined by xti.h); however to avoid
249
// to be forced to wrap these macros (in user's source files) with
250
//
251
//  #if wxUSE_EXTENDED_RTTI
252
//  ...
253
//  #endif
254
//
255
// blocks, we define them here as empty.
256
257
#define wxEMPTY_PARAMETER_VALUE /**/
258
259
#define wxBEGIN_ENUM( e ) wxEMPTY_PARAMETER_VALUE
260
#define wxENUM_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
261
#define wxEND_ENUM( e ) wxEMPTY_PARAMETER_VALUE
262
263
#define wxIMPLEMENT_SET_STREAMING(SetName,e) wxEMPTY_PARAMETER_VALUE
264
265
#define wxBEGIN_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
266
#define wxFLAGS_MEMBER( v ) wxEMPTY_PARAMETER_VALUE
267
#define wxEND_FLAGS( e ) wxEMPTY_PARAMETER_VALUE
268
269
#define wxCOLLECTION_TYPE_INFO( element, collection ) wxEMPTY_PARAMETER_VALUE
270
271
#define wxHANDLER(name,eventClassType) wxEMPTY_PARAMETER_VALUE
272
#define wxBEGIN_HANDLERS_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
273
#define wxEND_HANDLERS_TABLE() wxEMPTY_PARAMETER_VALUE
274
275
#define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
276
    wxIMPLEMENT_DYNAMIC_CLASS( name, basename )
277
#define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback ) \
278
    wxIMPLEMENT_DYNAMIC_CLASS( name, basename )
279
280
#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
281
    wxIMPLEMENT_DYNAMIC_CLASS( name, basename)
282
283
#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename,  \
284
                                                             unit, toString,    \
285
                                                             fromString ) wxEMPTY_PARAMETER_VALUE
286
#define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) wxEMPTY_PARAMETER_VALUE
287
#define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) wxEMPTY_PARAMETER_VALUE
288
289
#define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2 )
290
291
#define wxCONSTRUCTOR_0(klass) \
292
    wxEMPTY_PARAMETER_VALUE
293
#define wxCONSTRUCTOR_DUMMY(klass) \
294
    wxEMPTY_PARAMETER_VALUE
295
#define wxDIRECT_CONSTRUCTOR_0(klass) \
296
    wxEMPTY_PARAMETER_VALUE
297
#define wxCONSTRUCTOR_1(klass,t0,v0) \
298
    wxEMPTY_PARAMETER_VALUE
299
#define wxDIRECT_CONSTRUCTOR_1(klass,t0,v0) \
300
    wxEMPTY_PARAMETER_VALUE
301
#define wxCONSTRUCTOR_2(klass,t0,v0,t1,v1) \
302
    wxEMPTY_PARAMETER_VALUE
303
#define wxDIRECT_CONSTRUCTOR_2(klass,t0,v0,t1,v1) \
304
    wxEMPTY_PARAMETER_VALUE
305
#define wxCONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
306
    wxEMPTY_PARAMETER_VALUE
307
#define wxDIRECT_CONSTRUCTOR_3(klass,t0,v0,t1,v1,t2,v2) \
308
    wxEMPTY_PARAMETER_VALUE
309
#define wxCONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
310
    wxEMPTY_PARAMETER_VALUE
311
#define wxDIRECT_CONSTRUCTOR_4(klass,t0,v0,t1,v1,t2,v2,t3,v3) \
312
    wxEMPTY_PARAMETER_VALUE
313
#define wxCONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
314
    wxEMPTY_PARAMETER_VALUE
315
#define wxDIRECT_CONSTRUCTOR_5(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4) \
316
    wxEMPTY_PARAMETER_VALUE
317
#define wxCONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
318
    wxEMPTY_PARAMETER_VALUE
319
#define wxDIRECT_CONSTRUCTOR_6(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5) \
320
    wxEMPTY_PARAMETER_VALUE
321
#define wxCONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
322
    wxEMPTY_PARAMETER_VALUE
323
#define wxDIRECT_CONSTRUCTOR_7(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6) \
324
    wxEMPTY_PARAMETER_VALUE
325
#define wxCONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
326
    wxEMPTY_PARAMETER_VALUE
327
#define wxDIRECT_CONSTRUCTOR_8(klass,t0,v0,t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6,t7,v7) \
328
    wxEMPTY_PARAMETER_VALUE
329
330
#define wxSETTER( property, Klass, valueType, setterMethod ) wxEMPTY_PARAMETER_VALUE
331
#define wxGETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
332
#define wxADDER( property, Klass, valueType, addermethod ) wxEMPTY_PARAMETER_VALUE
333
#define wxCOLLECTION_GETTER( property, Klass, valueType, gettermethod ) wxEMPTY_PARAMETER_VALUE
334
335
#define wxBEGIN_PROPERTIES_TABLE(theClass) wxEMPTY_PARAMETER_VALUE
336
#define wxEND_PROPERTIES_TABLE() wxEMPTY_PARAMETER_VALUE
337
#define wxHIDE_PROPERTY( pname ) wxEMPTY_PARAMETER_VALUE
338
339
#define wxPROPERTY( pname, type, setter, getter, defaultValue, flags, help, group) \
340
    wxEMPTY_PARAMETER_VALUE
341
342
#define wxPROPERTY_FLAGS( pname, flags, type, setter, getter,defaultValue,    \
343
                          pflags, help, group) wxEMPTY_PARAMETER_VALUE
344
345
#define wxREADONLY_PROPERTY( pname, type, getter,defaultValue, flags, help, group) \
346
    wxGETTER( pname, class_t, type, getter ) wxEMPTY_PARAMETER_VALUE
347
348
#define wxREADONLY_PROPERTY_FLAGS( pname, flags, type, getter,defaultValue,    \
349
                                   pflags, help, group)  wxEMPTY_PARAMETER_VALUE
350
351
#define wxPROPERTY_COLLECTION( pname, colltype, addelemtype, adder, getter,    \
352
                               flags, help, group )  wxEMPTY_PARAMETER_VALUE
353
354
#define wxREADONLY_PROPERTY_COLLECTION( pname, colltype, addelemtype, getter,   \
355
                                        flags, help, group) wxEMPTY_PARAMETER_VALUE
356
#define wxEVENT_PROPERTY( name, eventType, eventClass ) wxEMPTY_PARAMETER_VALUE
357
358
#define wxEVENT_RANGE_PROPERTY( name, eventType, lastEventType, eventClass ) wxEMPTY_PARAMETER_VALUE
359
360
#define wxIMPLEMENT_PROPERTY(name, type) wxEMPTY_PARAMETER_VALUE
361
362
#define wxEMPTY_HANDLERS_TABLE(name) wxEMPTY_PARAMETER_VALUE
363
364
#endif // !wxUSE_EXTENDED_RTTI
365
#endif // _WX_RTTIH__