Coverage Report

Created: 2025-06-13 06:30

/src/wxwidgets/include/wx/any.h
Line
Count
Source (jump to first uncovered line)
1
/////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/any.h
3
// Purpose:     wxAny class
4
// Author:      Jaakko Salli
5
// Created:     07/05/2009
6
// Copyright:   (c) wxWidgets team
7
// Licence:     wxWindows licence
8
/////////////////////////////////////////////////////////////////////////////
9
10
#ifndef _WX_ANY_H_
11
#define _WX_ANY_H_
12
13
#include "wx/defs.h"
14
15
#if wxUSE_ANY
16
17
#include <new> // for placement new
18
#include "wx/string.h"
19
#include "wx/meta/if.h"
20
#include "wx/typeinfo.h"
21
#include "wx/list.h"
22
23
// Size of the wxAny value buffer.
24
enum
25
{
26
    WX_ANY_VALUE_BUFFER_SIZE = 16
27
};
28
29
union wxAnyValueBuffer
30
{
31
    union Alignment
32
    {
33
        wxInt64 m_int64;
34
        long double m_longDouble;
35
        void ( *m_funcPtr )(void);
36
        void ( wxAnyValueBuffer::*m_mFuncPtr )(void);
37
    } m_alignment;
38
39
    void*   m_ptr;
40
    wxByte  m_buffer[WX_ANY_VALUE_BUFFER_SIZE];
41
42
    wxAnyValueBuffer()
43
0
    {
44
0
        m_ptr = nullptr;
45
0
    }
46
};
47
48
//
49
// wxAnyValueType is base class for value type functionality for C++ data
50
// types used with wxAny. Usually the default template (wxAnyValueTypeImpl<>)
51
// will create a satisfactory wxAnyValueType implementation for a data type.
52
//
53
class WXDLLIMPEXP_BASE wxAnyValueType
54
{
55
    WX_DECLARE_ABSTRACT_TYPEINFO(wxAnyValueType)
56
public:
57
    /**
58
        Default constructor.
59
    */
60
    wxAnyValueType()
61
32
    {
62
32
    }
63
64
    /**
65
        Destructor.
66
    */
67
    virtual ~wxAnyValueType()
68
0
    {
69
0
    }
70
71
    /**
72
        This function is used for internal type matching.
73
    */
74
    virtual bool IsSameType(const wxAnyValueType* otherType) const = 0;
75
76
    /**
77
        This function is called every time the data in wxAny
78
        buffer needs to be freed.
79
    */
80
    virtual void DeleteValue(wxAnyValueBuffer& buf) const = 0;
81
82
    /**
83
        Implement this for buffer-to-buffer copy.
84
85
        @param src
86
            This is the source data buffer.
87
88
        @param dst
89
            This is the destination data buffer that is in either
90
            uninitialized or freed state.
91
    */
92
    virtual void CopyBuffer(const wxAnyValueBuffer& src,
93
                            wxAnyValueBuffer& dst) const = 0;
94
95
    /**
96
        Convert value into buffer of different type. Return false if
97
        not possible.
98
    */
99
    virtual bool ConvertValue(const wxAnyValueBuffer& src,
100
                              wxAnyValueType* dstType,
101
                              wxAnyValueBuffer& dst) const = 0;
102
103
    /**
104
        Use this template function for checking if wxAnyValueType represents
105
        a specific C++ data type.
106
107
        @see wxAny::CheckType()
108
    */
109
    template <typename T>
110
    bool CheckType() const;
111
112
#if wxUSE_EXTENDED_RTTI
113
    virtual const wxTypeInfo* GetTypeInfo() const = 0;
114
#endif
115
private:
116
};
117
118
119
//
120
// We need to allocate wxAnyValueType instances in heap, and need to use
121
// scoped ptr to properly deallocate them in dynamic library use cases.
122
// Here we have a minimal specialized scoped ptr implementation to deal
123
// with various compiler-specific problems with template class' static
124
// member variable of template type with explicit constructor which
125
// is initialized in global scope.
126
//
127
class wxAnyValueTypeScopedPtr
128
{
129
public:
130
32
    wxAnyValueTypeScopedPtr(wxAnyValueType* ptr) : m_ptr(ptr) { }
131
0
    ~wxAnyValueTypeScopedPtr() { delete m_ptr; }
132
2
    wxAnyValueType* get() const { return m_ptr; }
133
private:
134
    wxAnyValueType* m_ptr;
135
};
136
137
138
// Deprecated macro for checking the type which was originally introduced for
139
// MSVC6 compatibility and is not needed any longer now that this compiler is
140
// not supported any more.
141
#define wxANY_VALUE_TYPE_CHECK_TYPE(valueTypePtr, T) \
142
0
    wxAnyValueTypeImpl<T>::IsSameClass(valueTypePtr)
143
144
145
/**
146
    Helper macro for defining user value types.
147
148
    Even though C++ RTTI would be fully available to use, we'd have to
149
    facilitate sub-type system which allows, for instance, wxAny with
150
    signed short '15' to be treated equal to wxAny with signed long long '15'.
151
    Having sm_instance is important here.
152
153
    NB: We really need to have wxAnyValueType instances allocated
154
        in heap. They are stored as static template member variables,
155
        and with them we just can't be too careful (eg. not allocating
156
        them in heap broke the type identification in GCC).
157
*/
158
#define WX_DECLARE_ANY_VALUE_TYPE(CLS) \
159
    friend class wxAny; \
160
    WX_DECLARE_TYPEINFO_INLINE(CLS) \
161
public: \
162
    static bool IsSameClass(const wxAnyValueType* otherType) \
163
0
    { \
164
0
        return AreSameClasses(*sm_instance.get(), *otherType); \
165
0
    } \
Unexecuted instantiation: wxAnyValueTypeImplInt::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImplUint::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImplwxString::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImplConstCharPtr::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImplConstWchar_tPtr::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<bool>::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImplDouble::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<wxDateTime>::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImplVariantData::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<wxAnyNullValue>::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<wxVariant>::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<wxUniChar>::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<wxObject*>::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<void*>::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<wxArrayString>::IsSameClass(wxAnyValueType const*)
Unexecuted instantiation: wxAnyValueTypeImpl<wxAnyList>::IsSameClass(wxAnyValueType const*)
166
    virtual bool IsSameType(const wxAnyValueType* otherType) const override \
167
0
    { \
168
0
        return IsSameClass(otherType); \
169
0
    } \
Unexecuted instantiation: wxAnyValueTypeImplInt::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImplUint::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImplwxString::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImplConstCharPtr::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImplConstWchar_tPtr::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<bool>::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImplDouble::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxDateTime>::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImplVariantData::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxAnyNullValue>::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxVariant>::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxUniChar>::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxObject*>::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<void*>::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxArrayString>::IsSameType(wxAnyValueType const*) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxAnyList>::IsSameType(wxAnyValueType const*) const
170
private: \
171
    static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b) \
172
0
    { \
173
0
        return wxTypeId(a) == wxTypeId(b); \
174
0
    } \
Unexecuted instantiation: wxAnyValueTypeImplInt::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImplUint::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImplwxString::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImplConstCharPtr::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImplConstWchar_tPtr::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<bool>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImplDouble::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<wxDateTime>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImplVariantData::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<wxAnyNullValue>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<wxVariant>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<wxUniChar>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<wxObject*>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<void*>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<wxArrayString>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
Unexecuted instantiation: wxAnyValueTypeImpl<wxAnyList>::AreSameClasses(wxAnyValueType const&, wxAnyValueType const&)
175
    static wxAnyValueTypeScopedPtr sm_instance; \
176
public: \
177
    static wxAnyValueType* GetInstance() \
178
2
    { \
179
2
        return sm_instance.get(); \
180
2
    }
Unexecuted instantiation: wxAnyValueTypeImplInt::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImplUint::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImplwxString::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImplConstCharPtr::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImplConstWchar_tPtr::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImpl<bool>::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImplDouble::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImpl<wxDateTime>::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImplVariantData::GetInstance()
wxAnyValueTypeImpl<wxAnyNullValue>::GetInstance()
Line
Count
Source
178
2
    { \
179
2
        return sm_instance.get(); \
180
2
    }
Unexecuted instantiation: wxAnyValueTypeImpl<wxUniChar>::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImpl<wxObject*>::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImpl<void*>::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImpl<wxArrayString>::GetInstance()
Unexecuted instantiation: wxAnyValueTypeImpl<wxAnyList>::GetInstance()
181
182
183
#define WX_IMPLEMENT_ANY_VALUE_TYPE(CLS) \
184
wxAnyValueTypeScopedPtr CLS::sm_instance(new CLS());
185
186
187
/**
188
    Following are helper classes for the wxAnyValueTypeImplBase.
189
*/
190
namespace wxPrivate
191
{
192
193
template<typename T>
194
class wxAnyValueTypeOpsInplace
195
{
196
public:
197
    static void DeleteValue(wxAnyValueBuffer& buf)
198
0
    {
199
0
        GetValue(buf).~T();
200
0
    }
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<long long>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<unsigned long long>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<char const*>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wchar_t const*>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<bool>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<double>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxDateTime>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxVariantData*>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxUniChar>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxObject*>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<void*>::DeleteValue(wxAnyValueBuffer&)
201
202
    static void SetValue(const T& value,
203
                         wxAnyValueBuffer& buf)
204
0
    {
205
        // Use placement new, taking care to avoid running into problems with
206
        // "new" redefinition in wx/msw/msvcrt.h.
207
#ifdef WXDEBUG_NEW
208
    #undef new
209
#endif
210
211
0
        void* const place = buf.m_buffer;
212
0
        ::new(place) T(value);
213
214
#ifdef WXDEBUG_NEW
215
    #define new WXDEBUG_NEW
216
#endif
217
0
    }
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<char const*>::SetValue(char const* const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wchar_t const*>::SetValue(wchar_t const* const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<long long>::SetValue(long long const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<unsigned long long>::SetValue(unsigned long long const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<bool>::SetValue(bool const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<double>::SetValue(double const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxDateTime>::SetValue(wxDateTime const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxVariantData*>::SetValue(wxVariantData* const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxUniChar>::SetValue(wxUniChar const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxObject*>::SetValue(wxObject* const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<void*>::SetValue(void* const&, wxAnyValueBuffer&)
218
219
    static const T& GetValue(const wxAnyValueBuffer& buf)
220
0
    {
221
        // Use a union to avoid undefined behaviour (and gcc -Wstrict-alias
222
        // warnings about it) which would occur if we just casted a wxByte
223
        // pointer to a T one.
224
0
        union
225
0
        {
226
0
            const T* ptr;
227
0
            const wxByte *buf;
228
0
        } u;
229
0
        u.buf = buf.m_buffer;
230
231
0
        return *u.ptr;
232
0
    }
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<char const*>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wchar_t const*>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<bool>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<long long>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<unsigned long long>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<double>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxDateTime>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxVariantData*>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxUniChar>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<wxObject*>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsInplace<void*>::GetValue(wxAnyValueBuffer const&)
233
};
234
235
236
template<typename T>
237
class wxAnyValueTypeOpsGeneric
238
{
239
public:
240
    template<typename T2>
241
    class DataHolder
242
    {
243
    public:
244
        DataHolder(const T2& value)
245
0
            : m_value(value)
246
0
        {
247
0
        }
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxString>::DataHolder<wxString>::DataHolder(wxString const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxVariant>::DataHolder<wxVariant>::DataHolder(wxVariant const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxArrayString>::DataHolder<wxArrayString>::DataHolder(wxArrayString const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxAnyList>::DataHolder<wxAnyList>::DataHolder(wxAnyList const&)
248
0
        virtual ~DataHolder() = default;
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxString>::DataHolder<wxString>::~DataHolder()
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxVariant>::DataHolder<wxVariant>::~DataHolder()
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxArrayString>::DataHolder<wxArrayString>::~DataHolder()
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxAnyList>::DataHolder<wxAnyList>::~DataHolder()
249
250
        T2   m_value;
251
    private:
252
        wxDECLARE_NO_COPY_CLASS(DataHolder);
253
    };
254
255
    static void DeleteValue(wxAnyValueBuffer& buf)
256
0
    {
257
0
        DataHolder<T>* holder = static_cast<DataHolder<T>*>(buf.m_ptr);
258
0
        delete holder;
259
0
    }
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxString>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxVariant>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxArrayString>::DeleteValue(wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxAnyList>::DeleteValue(wxAnyValueBuffer&)
260
261
    static void SetValue(const T& value,
262
                         wxAnyValueBuffer& buf)
263
0
    {
264
0
        DataHolder<T>* holder = new DataHolder<T>(value);
265
0
        buf.m_ptr = holder;
266
0
    }
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxString>::SetValue(wxString const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxVariant>::SetValue(wxVariant const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxArrayString>::SetValue(wxArrayString const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxAnyList>::SetValue(wxAnyList const&, wxAnyValueBuffer&)
267
268
    static const T& GetValue(const wxAnyValueBuffer& buf)
269
0
    {
270
0
        DataHolder<T>* holder = static_cast<DataHolder<T>*>(buf.m_ptr);
271
0
        return holder->m_value;
272
0
    }
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxString>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxVariant>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxArrayString>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxPrivate::wxAnyValueTypeOpsGeneric<wxAnyList>::GetValue(wxAnyValueBuffer const&)
273
};
274
275
276
template <typename T>
277
struct wxAnyAsImpl;
278
279
} // namespace wxPrivate
280
281
282
/**
283
    Intermediate template for the generic value type implementation.
284
    We can derive from this same value type for multiple actual types
285
    (for instance, we can have wxAnyValueTypeImplInt for all signed
286
    integer types), and also easily implement specialized templates
287
    with specific dynamic type conversion.
288
*/
289
template<typename T>
290
class wxAnyValueTypeImplBase : public wxAnyValueType
291
{
292
    typedef typename wxIf< sizeof(T) <= WX_ANY_VALUE_BUFFER_SIZE,
293
                           wxPrivate::wxAnyValueTypeOpsInplace<T>,
294
                           wxPrivate::wxAnyValueTypeOpsGeneric<T> >::value
295
            Ops;
296
297
public:
298
30
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wxVariantData*>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<long long>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<unsigned long long>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<bool>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<double>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wxString>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<char const*>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wchar_t const*>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wxDateTime>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wxVariant>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wxUniChar>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wxObject*>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<void*>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wxArrayString>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
wxAnyValueTypeImplBase<wxAnyList>::wxAnyValueTypeImplBase()
Line
Count
Source
298
2
    wxAnyValueTypeImplBase() : wxAnyValueType() { }
299
    virtual ~wxAnyValueTypeImplBase() = default;
300
301
    virtual void DeleteValue(wxAnyValueBuffer& buf) const override
302
0
    {
303
0
        Ops::DeleteValue(buf);
304
0
    }
Unexecuted instantiation: wxAnyValueTypeImplBase<long long>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<unsigned long long>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxString>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<char const*>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wchar_t const*>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<bool>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<double>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxDateTime>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxVariantData*>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxVariant>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxUniChar>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxObject*>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<void*>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxArrayString>::DeleteValue(wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxAnyList>::DeleteValue(wxAnyValueBuffer&) const
305
306
    virtual void CopyBuffer(const wxAnyValueBuffer& src,
307
                            wxAnyValueBuffer& dst) const override
308
0
    {
309
0
        Ops::SetValue(Ops::GetValue(src), dst);
310
0
    }
Unexecuted instantiation: wxAnyValueTypeImplBase<long long>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<unsigned long long>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxString>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<char const*>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wchar_t const*>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<bool>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<double>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxDateTime>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxVariantData*>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxVariant>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxUniChar>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxObject*>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<void*>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxArrayString>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplBase<wxAnyList>::CopyBuffer(wxAnyValueBuffer const&, wxAnyValueBuffer&) const
311
312
    /**
313
        It is important to reimplement this in any specialized template
314
        classes that inherit from wxAnyValueTypeImplBase.
315
    */
316
    static void SetValue(const T& value,
317
                         wxAnyValueBuffer& buf)
318
0
    {
319
0
        Ops::SetValue(value, buf);
320
0
    }
Unexecuted instantiation: wxAnyValueTypeImplBase<char const*>::SetValue(char const* const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wchar_t const*>::SetValue(wchar_t const* const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxString>::SetValue(wxString const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<unsigned long long>::SetValue(unsigned long long const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<double>::SetValue(double const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<bool>::SetValue(bool const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<long long>::SetValue(long long const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxUniChar>::SetValue(wxUniChar const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxObject*>::SetValue(wxObject* const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<void*>::SetValue(void* const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxDateTime>::SetValue(wxDateTime const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxArrayString>::SetValue(wxArrayString const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxAnyList>::SetValue(wxAnyList const&, wxAnyValueBuffer&)
321
322
    /**
323
        It is important to reimplement this in any specialized template
324
        classes that inherit from wxAnyValueTypeImplBase.
325
    */
326
    static const T& GetValue(const wxAnyValueBuffer& buf)
327
0
    {
328
0
        return Ops::GetValue(buf);
329
0
    }
Unexecuted instantiation: wxAnyValueTypeImplBase<wxString>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<char const*>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wchar_t const*>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<bool>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxVariant>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<long long>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<unsigned long long>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<double>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxUniChar>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxObject*>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<void*>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxDateTime>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxArrayString>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImplBase<wxAnyList>::GetValue(wxAnyValueBuffer const&)
330
#if wxUSE_EXTENDED_RTTI
331
    virtual const wxTypeInfo* GetTypeInfo() const
332
    {
333
        return wxGetTypeInfo((T*)nullptr);
334
    }
335
#endif
336
};
337
338
339
/*
340
    Generic value type template. Note that bulk of the implementation
341
    resides in wxAnyValueTypeImplBase.
342
*/
343
template<typename T>
344
class wxAnyValueTypeImpl : public wxAnyValueTypeImplBase<T>
345
{
346
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<T>)
347
public:
348
12
    wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<T>() { }
wxAnyValueTypeImpl<wxVariant>::wxAnyValueTypeImpl()
Line
Count
Source
348
2
    wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<T>() { }
wxAnyValueTypeImpl<wxUniChar>::wxAnyValueTypeImpl()
Line
Count
Source
348
2
    wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<T>() { }
wxAnyValueTypeImpl<wxObject*>::wxAnyValueTypeImpl()
Line
Count
Source
348
2
    wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<T>() { }
wxAnyValueTypeImpl<void*>::wxAnyValueTypeImpl()
Line
Count
Source
348
2
    wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<T>() { }
wxAnyValueTypeImpl<wxArrayString>::wxAnyValueTypeImpl()
Line
Count
Source
348
2
    wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<T>() { }
wxAnyValueTypeImpl<wxAnyList>::wxAnyValueTypeImpl()
Line
Count
Source
348
2
    wxAnyValueTypeImpl() : wxAnyValueTypeImplBase<T>() { }
349
    virtual ~wxAnyValueTypeImpl() = default;
350
351
    virtual bool ConvertValue(const wxAnyValueBuffer& src,
352
                              wxAnyValueType* dstType,
353
                              wxAnyValueBuffer& dst) const override
354
0
    {
355
0
        wxUnusedVar(src);
356
0
        wxUnusedVar(dstType);
357
0
        wxUnusedVar(dst);
358
0
        return false;
359
0
    }
Unexecuted instantiation: wxAnyValueTypeImpl<wxVariant>::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxUniChar>::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxObject*>::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImpl<void*>::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxArrayString>::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImpl<wxAnyList>::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
360
};
361
362
template<typename T>
363
wxAnyValueTypeScopedPtr wxAnyValueTypeImpl<T>::sm_instance = new wxAnyValueTypeImpl<T>();
364
365
366
//
367
// Helper macro for using same base value type implementation for multiple
368
// actual C++ data types.
369
//
370
#define _WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \
371
template<> \
372
class wxAnyValueTypeImpl<T> : public wxAnyValueTypeImpl##CLSTYPE \
373
{ \
374
    typedef wxAnyBase##CLSTYPE##Type UseDataType; \
375
public: \
376
0
    wxAnyValueTypeImpl() : wxAnyValueTypeImpl##CLSTYPE() { } \
Unexecuted instantiation: wxAnyValueTypeImpl<long>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<int>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<short>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<signed char>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<long long>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned long>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned int>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned short>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned char>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned long long>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<float>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<double>::wxAnyValueTypeImpl()
377
    virtual ~wxAnyValueTypeImpl() = default; \
378
    static void SetValue(const T& value, wxAnyValueBuffer& buf) \
379
0
    { \
380
0
        void* voidPtr = reinterpret_cast<void*>(&buf.m_buffer[0]); \
381
0
        UseDataType* dptr = reinterpret_cast<UseDataType*>(voidPtr); \
382
0
        *dptr = static_cast<UseDataType>(value); \
383
0
    } \
Unexecuted instantiation: wxAnyValueTypeImpl<long>::SetValue(long const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<int>::SetValue(int const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<short>::SetValue(short const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<signed char>::SetValue(signed char const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<long long>::SetValue(long long const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned long>::SetValue(unsigned long const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned int>::SetValue(unsigned int const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned short>::SetValue(unsigned short const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned char>::SetValue(unsigned char const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned long long>::SetValue(unsigned long long const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<float>::SetValue(float const&, wxAnyValueBuffer&)
Unexecuted instantiation: wxAnyValueTypeImpl<double>::SetValue(double const&, wxAnyValueBuffer&)
384
    static T GetValue(const wxAnyValueBuffer& buf) \
385
0
    { \
386
0
        const void* voidPtr = \
387
0
            reinterpret_cast<const void*>(&buf.m_buffer[0]); \
388
0
        const UseDataType* sptr = \
389
0
            reinterpret_cast<const UseDataType*>(voidPtr); \
390
0
        return static_cast<T>(*sptr); \
391
0
    }
Unexecuted instantiation: wxAnyValueTypeImpl<long>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<int>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<short>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<signed char>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<long long>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned long>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned int>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned short>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned char>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<unsigned long long>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<float>::GetValue(wxAnyValueBuffer const&)
Unexecuted instantiation: wxAnyValueTypeImpl<double>::GetValue(wxAnyValueBuffer const&)
392
393
#if wxUSE_EXTENDED_RTTI
394
#define WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \
395
_WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE)\
396
    virtual const wxTypeInfo* GetTypeInfo() const  \
397
    { \
398
        return wxGetTypeInfo((T*)nullptr); \
399
    } \
400
};
401
#else
402
#define WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \
403
_WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE)\
404
};
405
#endif
406
407
//
408
//  Integer value types
409
//
410
411
typedef wxLongLong_t wxAnyBaseIntType;
412
typedef wxULongLong_t wxAnyBaseUintType;
413
414
class WXDLLIMPEXP_BASE wxAnyValueTypeImplInt :
415
    public wxAnyValueTypeImplBase<wxAnyBaseIntType>
416
{
417
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplInt)
418
public:
419
    wxAnyValueTypeImplInt() :
420
2
        wxAnyValueTypeImplBase<wxAnyBaseIntType>() { }
421
    virtual ~wxAnyValueTypeImplInt() = default;
422
423
    virtual bool ConvertValue(const wxAnyValueBuffer& src,
424
                              wxAnyValueType* dstType,
425
                              wxAnyValueBuffer& dst) const override;
426
};
427
428
429
class WXDLLIMPEXP_BASE wxAnyValueTypeImplUint :
430
    public wxAnyValueTypeImplBase<wxAnyBaseUintType>
431
{
432
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplUint)
433
public:
434
    wxAnyValueTypeImplUint() :
435
2
        wxAnyValueTypeImplBase<wxAnyBaseUintType>() { }
436
    virtual ~wxAnyValueTypeImplUint() = default;
437
438
    virtual bool ConvertValue(const wxAnyValueBuffer& src,
439
                              wxAnyValueType* dstType,
440
                              wxAnyValueBuffer& dst) const override;
441
};
442
443
444
WX_ANY_DEFINE_SUB_TYPE(signed long, Int)
445
WX_ANY_DEFINE_SUB_TYPE(signed int, Int)
446
WX_ANY_DEFINE_SUB_TYPE(signed short, Int)
447
WX_ANY_DEFINE_SUB_TYPE(signed char, Int)
448
WX_ANY_DEFINE_SUB_TYPE(wxLongLong_t, Int)
449
450
WX_ANY_DEFINE_SUB_TYPE(unsigned long, Uint)
451
WX_ANY_DEFINE_SUB_TYPE(unsigned int, Uint)
452
WX_ANY_DEFINE_SUB_TYPE(unsigned short, Uint)
453
WX_ANY_DEFINE_SUB_TYPE(unsigned char, Uint)
454
WX_ANY_DEFINE_SUB_TYPE(wxULongLong_t, Uint)
455
456
457
//
458
// This macro is used in header, but then in source file we must have:
459
// WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl##TYPENAME)
460
//
461
#define _WX_ANY_DEFINE_CONVERTIBLE_TYPE(T, TYPENAME, CONVFUNC, GV) \
462
class WXDLLIMPEXP_BASE wxAnyValueTypeImpl##TYPENAME : \
463
    public wxAnyValueTypeImplBase<T> \
464
{ \
465
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl##TYPENAME) \
466
public: \
467
    wxAnyValueTypeImpl##TYPENAME() : \
468
6
        wxAnyValueTypeImplBase<T>() { } \
wxAnyValueTypeImplwxString::wxAnyValueTypeImplwxString()
Line
Count
Source
468
2
        wxAnyValueTypeImplBase<T>() { } \
wxAnyValueTypeImplConstCharPtr::wxAnyValueTypeImplConstCharPtr()
Line
Count
Source
468
2
        wxAnyValueTypeImplBase<T>() { } \
wxAnyValueTypeImplConstWchar_tPtr::wxAnyValueTypeImplConstWchar_tPtr()
Line
Count
Source
468
2
        wxAnyValueTypeImplBase<T>() { } \
469
    virtual ~wxAnyValueTypeImpl##TYPENAME() = default; \
470
    virtual bool ConvertValue(const wxAnyValueBuffer& src, \
471
                              wxAnyValueType* dstType, \
472
                              wxAnyValueBuffer& dst) const override \
473
0
    { \
474
0
        GV value = GetValue(src); \
475
0
        return CONVFUNC(value, dstType, dst); \
476
0
    } \
Unexecuted instantiation: wxAnyValueTypeImplwxString::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplConstCharPtr::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
Unexecuted instantiation: wxAnyValueTypeImplConstWchar_tPtr::ConvertValue(wxAnyValueBuffer const&, wxAnyValueType*, wxAnyValueBuffer&) const
477
}; \
478
template<> \
479
class wxAnyValueTypeImpl<T> : public wxAnyValueTypeImpl##TYPENAME \
480
{ \
481
public: \
482
0
    wxAnyValueTypeImpl() : wxAnyValueTypeImpl##TYPENAME() { } \
Unexecuted instantiation: wxAnyValueTypeImpl<wxString>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<char const*>::wxAnyValueTypeImpl()
Unexecuted instantiation: wxAnyValueTypeImpl<wchar_t const*>::wxAnyValueTypeImpl()
483
    virtual ~wxAnyValueTypeImpl() = default; \
484
};
485
486
#define WX_ANY_DEFINE_CONVERTIBLE_TYPE(T, TYPENAME, CONVFUNC, BT) \
487
_WX_ANY_DEFINE_CONVERTIBLE_TYPE(T, TYPENAME, CONVFUNC, BT) \
488
489
#define WX_ANY_DEFINE_CONVERTIBLE_TYPE_BASE(T, TYPENAME, CONVFUNC) \
490
_WX_ANY_DEFINE_CONVERTIBLE_TYPE(T, TYPENAME, \
491
                                CONVFUNC, const T&) \
492
493
//
494
// String value type
495
//
496
497
// Convert wxString to destination wxAny value type
498
extern WXDLLIMPEXP_BASE bool wxAnyConvertString(const wxString& value,
499
                                                wxAnyValueType* dstType,
500
                                                wxAnyValueBuffer& dst);
501
502
WX_ANY_DEFINE_CONVERTIBLE_TYPE_BASE(wxString, wxString, wxAnyConvertString)
503
#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING
504
WX_ANY_DEFINE_CONVERTIBLE_TYPE(const char*, ConstCharPtr,
505
                               wxAnyConvertString, wxString)
506
#endif
507
WX_ANY_DEFINE_CONVERTIBLE_TYPE(const wchar_t*, ConstWchar_tPtr,
508
                               wxAnyConvertString, wxString)
509
510
//
511
// Bool value type
512
//
513
template<>
514
class WXDLLIMPEXP_BASE wxAnyValueTypeImpl<bool> :
515
    public wxAnyValueTypeImplBase<bool>
516
{
517
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<bool>)
518
public:
519
    wxAnyValueTypeImpl() :
520
2
        wxAnyValueTypeImplBase<bool>() { }
521
    virtual ~wxAnyValueTypeImpl() = default;
522
523
    virtual bool ConvertValue(const wxAnyValueBuffer& src,
524
                              wxAnyValueType* dstType,
525
                              wxAnyValueBuffer& dst) const override;
526
};
527
528
//
529
// Floating point value type
530
//
531
class WXDLLIMPEXP_BASE wxAnyValueTypeImplDouble :
532
    public wxAnyValueTypeImplBase<double>
533
{
534
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplDouble)
535
public:
536
    wxAnyValueTypeImplDouble() :
537
2
        wxAnyValueTypeImplBase<double>() { }
538
    virtual ~wxAnyValueTypeImplDouble() = default;
539
540
    virtual bool ConvertValue(const wxAnyValueBuffer& src,
541
                              wxAnyValueType* dstType,
542
                              wxAnyValueBuffer& dst) const override;
543
};
544
545
// WX_ANY_DEFINE_SUB_TYPE requires this
546
typedef double wxAnyBaseDoubleType;
547
548
WX_ANY_DEFINE_SUB_TYPE(float, Double)
549
WX_ANY_DEFINE_SUB_TYPE(double, Double)
550
551
552
//
553
// Defines a dummy wxAnyValueTypeImpl<> with given export
554
// declaration. This is needed if a class is used with
555
// wxAny in both user shared library and application.
556
//
557
#define wxDECLARE_ANY_TYPE(CLS, DECL) \
558
template<> \
559
class DECL wxAnyValueTypeImpl<CLS> : \
560
    public wxAnyValueTypeImplBase<CLS> \
561
{ \
562
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<CLS>) \
563
public: \
564
    wxAnyValueTypeImpl() : \
565
2
        wxAnyValueTypeImplBase<CLS>() { } \
566
    virtual ~wxAnyValueTypeImpl() = default; \
567
 \
568
    virtual bool ConvertValue(const wxAnyValueBuffer& src, \
569
                              wxAnyValueType* dstType, \
570
                              wxAnyValueBuffer& dst) const override \
571
0
    { \
572
0
        wxUnusedVar(src); \
573
0
        wxUnusedVar(dstType); \
574
0
        wxUnusedVar(dst); \
575
0
        return false; \
576
0
    } \
577
};
578
579
580
// Make sure some of wx's own types get the right wxAnyValueType export
581
// (this is needed only for types that are referred to from wxBase.
582
// currently we may not use any of these types from there, but let's
583
// use the macro on at least one to make sure it compiles since we can't
584
// really test it properly in unit tests since a separate DLL would
585
// be needed).
586
#if wxUSE_DATETIME
587
    #include "wx/datetime.h"
588
    wxDECLARE_ANY_TYPE(wxDateTime, WXDLLIMPEXP_BASE)
589
#endif
590
591
//#include "wx/object.h"
592
//wxDECLARE_ANY_TYPE(wxObject*, WXDLLIMPEXP_BASE)
593
594
//#include "wx/arrstr.h"
595
//wxDECLARE_ANY_TYPE(wxArrayString, WXDLLIMPEXP_BASE)
596
597
598
#if wxUSE_VARIANT
599
600
class WXDLLIMPEXP_FWD_BASE wxAnyToVariantRegistration;
601
602
// Because of header inter-dependencies, cannot include this earlier
603
#include "wx/variant.h"
604
605
//
606
// wxVariantData* data type implementation. For cases when appropriate
607
// wxAny<->wxVariant conversion code is missing.
608
//
609
610
class WXDLLIMPEXP_BASE wxAnyValueTypeImplVariantData :
611
    public wxAnyValueTypeImplBase<wxVariantData*>
612
{
613
    WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImplVariantData)
614
public:
615
    wxAnyValueTypeImplVariantData() :
616
2
        wxAnyValueTypeImplBase<wxVariantData*>() { }
617
    virtual ~wxAnyValueTypeImplVariantData() = default;
618
619
    virtual void DeleteValue(wxAnyValueBuffer& buf) const override
620
0
    {
621
0
        wxVariantData* data = static_cast<wxVariantData*>(buf.m_ptr);
622
0
        if ( data )
623
0
            data->DecRef();
624
0
    }
625
626
    virtual void CopyBuffer(const wxAnyValueBuffer& src,
627
                            wxAnyValueBuffer& dst) const override
628
0
    {
629
0
        wxVariantData* data = static_cast<wxVariantData*>(src.m_ptr);
630
0
        if ( data )
631
0
            data->IncRef();
632
0
        dst.m_ptr = data;
633
0
    }
634
635
    static void SetValue(wxVariantData* value,
636
                         wxAnyValueBuffer& buf)
637
0
    {
638
0
        value->IncRef();
639
0
        buf.m_ptr = value;
640
0
    }
641
642
    static wxVariantData* GetValue(const wxAnyValueBuffer& buf)
643
0
    {
644
0
        return static_cast<wxVariantData*>(buf.m_ptr);
645
0
    }
646
647
    virtual bool ConvertValue(const wxAnyValueBuffer& src,
648
                              wxAnyValueType* dstType,
649
                              wxAnyValueBuffer& dst) const override
650
0
    {
651
0
        wxUnusedVar(src);
652
0
        wxUnusedVar(dstType);
653
0
        wxUnusedVar(dst);
654
0
        return false;
655
0
    }
656
};
657
658
template<>
659
class wxAnyValueTypeImpl<wxVariantData*> :
660
    public wxAnyValueTypeImplVariantData
661
{
662
public:
663
0
    wxAnyValueTypeImpl() : wxAnyValueTypeImplVariantData() { }
664
    virtual ~wxAnyValueTypeImpl() = default;
665
};
666
667
#endif // wxUSE_VARIANT
668
669
670
/*
671
    Let's define a discrete Null value so we don't have to really
672
    ever check if wxAny.m_type pointer is null or not. This is an
673
    optimization, mostly. Implementation of this value type is
674
    "hidden" in the source file.
675
*/
676
extern WXDLLIMPEXP_DATA_BASE(wxAnyValueType*) wxAnyNullValueType;
677
678
679
//
680
// We need to implement custom signed/unsigned int equals operators
681
// for signed/unsigned (eg. wxAny(128UL) == 128L) comparisons to work.
682
#define WXANY_IMPLEMENT_INT_EQ_OP(TS, TUS) \
683
0
bool operator==(TS value) const \
684
0
{ \
685
0
    if ( wxAnyValueTypeImpl<TS>::IsSameClass(m_type) ) \
686
0
        return (value == static_cast<TS> \
687
0
                (wxAnyValueTypeImpl<TS>::GetValue(m_buffer))); \
688
0
    if ( wxAnyValueTypeImpl<TUS>::IsSameClass(m_type) ) \
689
0
        return (value == static_cast<TS> \
690
0
                (wxAnyValueTypeImpl<TUS>::GetValue(m_buffer))); \
691
0
    return false; \
692
0
} \
Unexecuted instantiation: wxAny::operator==(signed char) const
Unexecuted instantiation: wxAny::operator==(short) const
Unexecuted instantiation: wxAny::operator==(int) const
Unexecuted instantiation: wxAny::operator==(long) const
Unexecuted instantiation: wxAny::operator==(long long) const
693
0
bool operator==(TUS value) const \
694
0
{ \
695
0
    if ( wxAnyValueTypeImpl<TUS>::IsSameClass(m_type) ) \
696
0
        return (value == static_cast<TUS> \
697
0
                (wxAnyValueTypeImpl<TUS>::GetValue(m_buffer))); \
698
0
    if ( wxAnyValueTypeImpl<TS>::IsSameClass(m_type) ) \
699
0
        return (value == static_cast<TUS> \
700
0
                (wxAnyValueTypeImpl<TS>::GetValue(m_buffer))); \
701
0
    return false; \
702
0
}
Unexecuted instantiation: wxAny::operator==(unsigned char) const
Unexecuted instantiation: wxAny::operator==(unsigned short) const
Unexecuted instantiation: wxAny::operator==(unsigned int) const
Unexecuted instantiation: wxAny::operator==(unsigned long) const
Unexecuted instantiation: wxAny::operator==(unsigned long long) const
703
704
705
#if wxUSE_VARIANT
706
707
// Note that the following functions are implemented outside wxAny class
708
// so that it can reside entirely in header and lack the export declaration.
709
710
// Helper function used to associate wxAnyValueType with a wxVariantData.
711
extern WXDLLIMPEXP_BASE void
712
wxPreRegisterAnyToVariant(wxAnyToVariantRegistration* reg);
713
714
// This function performs main wxAny to wxVariant conversion duties.
715
extern WXDLLIMPEXP_BASE bool
716
wxConvertAnyToVariant(const wxAny& any, wxVariant* variant);
717
718
#endif // wxUSE_VARIANT
719
720
//
721
// The wxAny class represents a container for any type. A variant's value
722
// can be changed at run time, possibly to a different type of value.
723
//
724
// As standard, wxAny can store value of almost any type, in a fairly
725
// optimal manner even.
726
//
727
class wxAny
728
{
729
public:
730
    /**
731
        Default constructor.
732
    */
733
    wxAny()
734
0
    {
735
0
        m_type = wxAnyNullValueType;
736
0
    }
737
738
    /**
739
        Destructor.
740
    */
741
    ~wxAny()
742
0
    {
743
0
        m_type->DeleteValue(m_buffer);
744
0
    }
745
746
    //@{
747
    /**
748
        Various constructors.
749
    */
750
    template<typename T>
751
    wxAny(const T& value)
752
0
    {
753
0
        m_type = wxAnyValueTypeImpl<T>::sm_instance.get();
754
0
        wxAnyValueTypeImpl<T>::SetValue(value, m_buffer);
755
0
    }
756
757
    // These two constructors are needed to deal with string literals
758
#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING
759
    wxAny(const char* value)
760
0
    {
761
0
        m_type = wxAnyValueTypeImpl<const char*>::sm_instance.get();
762
0
        wxAnyValueTypeImpl<const char*>::SetValue(value, m_buffer);
763
0
    }
764
#endif
765
    wxAny(const wchar_t* value)
766
0
    {
767
0
        m_type = wxAnyValueTypeImpl<const wchar_t*>::sm_instance.get();
768
0
        wxAnyValueTypeImpl<const wchar_t*>::SetValue(value, m_buffer);
769
0
    }
770
771
    wxAny(const wxAny& any)
772
0
    {
773
0
        m_type = wxAnyNullValueType;
774
0
        AssignAny(any);
775
0
    }
776
777
#if wxUSE_VARIANT
778
    wxAny(const wxVariant& variant)
779
0
    {
780
0
        m_type = wxAnyNullValueType;
781
0
        AssignVariant(variant);
782
0
    }
783
#endif
784
785
    //@}
786
787
    /**
788
        Use this template function for checking if this wxAny holds
789
        a specific C++ data type.
790
791
        @see wxAnyValueType::CheckType()
792
    */
793
    template <typename T>
794
    bool CheckType() const
795
    {
796
        return m_type->CheckType<T>();
797
    }
798
799
    /**
800
        Returns the value type as wxAnyValueType instance.
801
802
        @remarks You cannot reliably test whether two wxAnys are of
803
                 same value type by simply comparing return values
804
                 of wxAny::GetType(). Instead, use wxAny::HasSameType().
805
806
        @see HasSameType()
807
    */
808
    const wxAnyValueType* GetType() const
809
0
    {
810
0
        return m_type;
811
0
    }
812
813
    /**
814
        Returns @true if this and another wxAny have the same
815
        value type.
816
    */
817
    bool HasSameType(const wxAny& other) const
818
0
    {
819
0
        return GetType()->IsSameType(other.GetType());
820
0
    }
821
822
    /**
823
        Tests if wxAny is null (that is, whether there is no data).
824
    */
825
    bool IsNull() const
826
0
    {
827
0
        return (m_type == wxAnyNullValueType);
828
0
    }
829
830
    /**
831
        Makes wxAny null (that is, clears it).
832
    */
833
    void MakeNull()
834
0
    {
835
0
        m_type->DeleteValue(m_buffer);
836
0
        m_type = wxAnyNullValueType;
837
0
    }
838
839
    //@{
840
    /**
841
        Assignment operators.
842
    */
843
    template<typename T>
844
    wxAny& operator=(const T &value)
845
0
    {
846
0
        m_type->DeleteValue(m_buffer);
847
0
        m_type = wxAnyValueTypeImpl<T>::sm_instance.get();
848
0
        wxAnyValueTypeImpl<T>::SetValue(value, m_buffer);
849
0
        return *this;
850
0
    }
Unexecuted instantiation: wxAny& wxAny::operator=<long>(long const&)
Unexecuted instantiation: wxAny& wxAny::operator=<double>(double const&)
Unexecuted instantiation: wxAny& wxAny::operator=<bool>(bool const&)
Unexecuted instantiation: wxAny& wxAny::operator=<wxUniChar>(wxUniChar const&)
Unexecuted instantiation: wxAny& wxAny::operator=<wxString>(wxString const&)
Unexecuted instantiation: wxAny& wxAny::operator=<wxObject*>(wxObject* const&)
Unexecuted instantiation: wxAny& wxAny::operator=<void*>(void* const&)
Unexecuted instantiation: wxAny& wxAny::operator=<wxDateTime>(wxDateTime const&)
Unexecuted instantiation: wxAny& wxAny::operator=<wxArrayString>(wxArrayString const&)
Unexecuted instantiation: wxAny& wxAny::operator=<long long>(long long const&)
Unexecuted instantiation: wxAny& wxAny::operator=<unsigned long long>(unsigned long long const&)
Unexecuted instantiation: wxAny& wxAny::operator=<wxAnyList>(wxAnyList const&)
851
852
    wxAny& operator=(const wxAny &any)
853
0
    {
854
0
        if (this != &any)
855
0
            AssignAny(any);
856
0
        return *this;
857
0
    }
858
859
#if wxUSE_VARIANT
860
    wxAny& operator=(const wxVariant &variant)
861
0
    {
862
0
        AssignVariant(variant);
863
0
        return *this;
864
0
    }
865
#endif
866
867
    // These two operators are needed to deal with string literals
868
#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING
869
    wxAny& operator=(const char* value)
870
0
    {
871
0
        Assign(value);
872
0
        return *this;
873
0
    }
874
#endif
875
    wxAny& operator=(const wchar_t* value)
876
0
    {
877
0
        Assign(value);
878
0
        return *this;
879
0
    }
880
881
    //@{
882
    /**
883
        Equality operators.
884
    */
885
    bool operator==(const wxString& value) const
886
0
    {
887
0
        wxString value2;
888
0
        if ( !GetAs(&value2) )
889
0
            return false;
890
0
        return value == value2;
891
0
    }
892
893
#ifndef wxNO_IMPLICIT_WXSTRING_ENCODING
894
    bool operator==(const char* value) const
895
0
        { return (*this) == wxString(value); }
896
#endif // wxNO_IMPLICIT_WXSTRING_ENCODING
897
    bool operator==(const wchar_t* value) const
898
0
        { return (*this) == wxString(value); }
899
900
    //
901
    // We need to implement custom signed/unsigned int equals operators
902
    // for signed/unsigned (eg. wxAny(128UL) == 128L) comparisons to work.
903
    WXANY_IMPLEMENT_INT_EQ_OP(signed char, unsigned char)
904
    WXANY_IMPLEMENT_INT_EQ_OP(signed short, unsigned short)
905
    WXANY_IMPLEMENT_INT_EQ_OP(signed int, unsigned int)
906
    WXANY_IMPLEMENT_INT_EQ_OP(signed long, unsigned long)
907
    WXANY_IMPLEMENT_INT_EQ_OP(wxLongLong_t, wxULongLong_t)
908
909
    wxGCC_WARNING_SUPPRESS(float-equal)
910
911
    bool operator==(float value) const
912
0
    {
913
0
        if ( !wxAnyValueTypeImpl<float>::IsSameClass(m_type) )
914
0
            return false;
915
0
916
0
        return value ==
917
0
            static_cast<float>
918
0
                (wxAnyValueTypeImpl<float>::GetValue(m_buffer));
919
0
    }
920
921
    bool operator==(double value) const
922
0
    {
923
0
        if ( !wxAnyValueTypeImpl<double>::IsSameClass(m_type) )
924
0
            return false;
925
0
926
0
        return value ==
927
0
            static_cast<double>
928
0
                (wxAnyValueTypeImpl<double>::GetValue(m_buffer));
929
0
    }
930
931
    wxGCC_WARNING_RESTORE(float-equal)
932
933
    bool operator==(bool value) const
934
0
    {
935
0
        if ( !wxAnyValueTypeImpl<bool>::IsSameClass(m_type) )
936
0
            return false;
937
0
938
0
        return value == (wxAnyValueTypeImpl<bool>::GetValue(m_buffer));
939
0
    }
940
941
    //@}
942
943
    //@{
944
    /**
945
        Inequality operators (implement as template).
946
    */
947
    template<typename T>
948
    bool operator!=(const T& value) const
949
        { return !((*this) == value); }
950
    //@}
951
952
    /**
953
        This template function converts wxAny into given type. In most cases
954
        no type conversion is performed, so if the type is incorrect an
955
        assertion failure will occur.
956
957
        @remarks For convenience, conversion is done when T is wxString. This
958
                 is useful when a string literal (which are treated as
959
                 const char* and const wchar_t*) has been assigned to wxAny.
960
    */
961
    template <typename T>
962
    T As(T* = nullptr) const
963
0
    {
964
0
        return wxPrivate::wxAnyAsImpl<T>::DoAs(*this);
965
0
    }
Unexecuted instantiation: wxVariant wxAny::As<wxVariant>(wxVariant*) const
Unexecuted instantiation: double wxAny::As<double>(double*) const
Unexecuted instantiation: bool wxAny::As<bool>(bool*) const
Unexecuted instantiation: wxUniChar wxAny::As<wxUniChar>(wxUniChar*) const
Unexecuted instantiation: wxString wxAny::As<wxString>(wxString*) const
Unexecuted instantiation: char const* wxAny::As<char const*>(char const**) const
Unexecuted instantiation: wchar_t const* wxAny::As<wchar_t const*>(wchar_t const**) const
Unexecuted instantiation: wxObject* wxAny::As<wxObject*>(wxObject**) const
Unexecuted instantiation: void* wxAny::As<void*>(void**) const
Unexecuted instantiation: wxDateTime wxAny::As<wxDateTime>(wxDateTime*) const
Unexecuted instantiation: wxArrayString wxAny::As<wxArrayString>(wxArrayString*) const
Unexecuted instantiation: long long wxAny::As<long long>(long long*) const
Unexecuted instantiation: unsigned long long wxAny::As<unsigned long long>(unsigned long long*) const
Unexecuted instantiation: wxAnyList wxAny::As<wxAnyList>(wxAnyList*) const
966
967
    // Semi private helper: get the value without coercion, for all types.
968
    template <typename T>
969
    T RawAs() const
970
0
    {
971
0
        if ( !wxAnyValueTypeImpl<T>::IsSameClass(m_type) )
972
0
        {
973
0
            wxFAIL_MSG("Incorrect or non-convertible data type");
974
0
        }
975
976
0
        return static_cast<T>(wxAnyValueTypeImpl<T>::GetValue(m_buffer));
977
0
    }
Unexecuted instantiation: wxVariant wxAny::RawAs<wxVariant>() const
Unexecuted instantiation: double wxAny::RawAs<double>() const
Unexecuted instantiation: bool wxAny::RawAs<bool>() const
Unexecuted instantiation: wxUniChar wxAny::RawAs<wxUniChar>() const
Unexecuted instantiation: char const* wxAny::RawAs<char const*>() const
Unexecuted instantiation: wchar_t const* wxAny::RawAs<wchar_t const*>() const
Unexecuted instantiation: wxObject* wxAny::RawAs<wxObject*>() const
Unexecuted instantiation: void* wxAny::RawAs<void*>() const
Unexecuted instantiation: wxDateTime wxAny::RawAs<wxDateTime>() const
Unexecuted instantiation: wxArrayString wxAny::RawAs<wxArrayString>() const
Unexecuted instantiation: long long wxAny::RawAs<long long>() const
Unexecuted instantiation: unsigned long long wxAny::RawAs<unsigned long long>() const
Unexecuted instantiation: wxAnyList wxAny::RawAs<wxAnyList>() const
978
979
#if wxUSE_EXTENDED_RTTI
980
    const wxTypeInfo* GetTypeInfo() const
981
    {
982
        return m_type->GetTypeInfo();
983
    }
984
#endif
985
    /**
986
        Template function that retrieves and converts the value of this
987
        variant to the type that T* value is.
988
989
        @return Returns @true if conversion was successful.
990
    */
991
    template<typename T>
992
    bool GetAs(T* value) const
993
0
    {
994
0
        if ( !wxAnyValueTypeImpl<T>::IsSameClass(m_type) )
995
0
        {
996
0
            wxAnyValueType* otherType =
997
0
                wxAnyValueTypeImpl<T>::sm_instance.get();
998
0
            wxAnyValueBuffer temp_buf;
999
1000
0
            if ( !m_type->ConvertValue(m_buffer, otherType, temp_buf) )
1001
0
                return false;
1002
1003
0
            *value =
1004
0
                static_cast<T>(wxAnyValueTypeImpl<T>::GetValue(temp_buf));
1005
0
            otherType->DeleteValue(temp_buf);
1006
1007
0
            return true;
1008
0
        }
1009
0
        *value = static_cast<T>(wxAnyValueTypeImpl<T>::GetValue(m_buffer));
1010
0
        return true;
1011
0
    }
Unexecuted instantiation: bool wxAny::GetAs<wxString>(wxString*) const
Unexecuted instantiation: bool wxAny::GetAs<long long>(long long*) const
Unexecuted instantiation: bool wxAny::GetAs<wxVariantData*>(wxVariantData**) const
1012
1013
#if wxUSE_VARIANT
1014
    // GetAs() wxVariant specialization
1015
    bool GetAs(wxVariant* value) const
1016
0
    {
1017
0
        return wxConvertAnyToVariant(*this, value);
1018
0
    }
1019
#endif
1020
1021
private:
1022
#ifdef wxNO_IMPLICIT_WXSTRING_ENCODING
1023
    wxAny(const char*);  // Disabled
1024
    wxAny& operator=(const char *&value); // Disabled
1025
    wxAny& operator=(const char value[]); // Disabled
1026
    wxAny& operator==(const char *value); // Disabled
1027
#endif
1028
1029
    // Assignment functions
1030
    void AssignAny(const wxAny& any)
1031
0
    {
1032
        // Must delete value - CopyBuffer() never does that
1033
0
        m_type->DeleteValue(m_buffer);
1034
1035
0
        wxAnyValueType* newType = any.m_type;
1036
1037
0
        if ( !newType->IsSameType(m_type) )
1038
0
            m_type = newType;
1039
1040
0
        newType->CopyBuffer(any.m_buffer, m_buffer);
1041
0
    }
1042
1043
#if wxUSE_VARIANT
1044
    void AssignVariant(const wxVariant& variant)
1045
0
    {
1046
0
        wxVariantData* data = variant.GetData();
1047
1048
0
        if ( data && data->GetAsAny(this) )
1049
0
            return;
1050
1051
0
        m_type->DeleteValue(m_buffer);
1052
1053
0
        if ( variant.IsNull() )
1054
0
        {
1055
            // Init as Null
1056
0
            m_type = wxAnyNullValueType;
1057
0
        }
1058
0
        else
1059
0
        {
1060
            // If everything else fails, wrap the whole wxVariantData
1061
0
            m_type = wxAnyValueTypeImpl<wxVariantData*>::sm_instance.get();
1062
0
            wxAnyValueTypeImpl<wxVariantData*>::SetValue(data, m_buffer);
1063
0
        }
1064
0
    }
1065
#endif
1066
1067
    template<typename T>
1068
    void Assign(const T &value)
1069
0
    {
1070
0
        m_type->DeleteValue(m_buffer);
1071
0
        m_type = wxAnyValueTypeImpl<T>::sm_instance.get();
1072
0
        wxAnyValueTypeImpl<T>::SetValue(value, m_buffer);
1073
0
    }
Unexecuted instantiation: void wxAny::Assign<char const*>(char const* const&)
Unexecuted instantiation: void wxAny::Assign<wchar_t const*>(wchar_t const* const&)
1074
1075
    // Data
1076
    wxAnyValueBuffer    m_buffer;
1077
    wxAnyValueType*     m_type;
1078
};
1079
1080
1081
namespace wxPrivate
1082
{
1083
1084
// Dispatcher for template wxAny::As() implementation which is different for
1085
// wxString and all the other types: the generic implementation check if the
1086
// value is of the right type and returns it.
1087
template <typename T>
1088
struct wxAnyAsImpl
1089
{
1090
    static T DoAs(const wxAny& any)
1091
0
    {
1092
0
        return any.RawAs<T>();
1093
0
    }
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<wxVariant>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<double>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<bool>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<wxUniChar>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<char const*>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<wchar_t const*>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<wxObject*>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<void*>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<wxDateTime>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<wxArrayString>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<long long>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<unsigned long long>::DoAs(wxAny const&)
Unexecuted instantiation: wxPrivate::wxAnyAsImpl<wxAnyList>::DoAs(wxAny const&)
1094
};
1095
1096
// Specialization for wxString does coercion.
1097
template <>
1098
struct wxAnyAsImpl<wxString>
1099
{
1100
    static wxString DoAs(const wxAny& any)
1101
0
    {
1102
0
        wxString value;
1103
0
        if ( !any.GetAs(&value) )
1104
0
        {
1105
0
            wxFAIL_MSG("Incorrect or non-convertible data type");
1106
0
        }
1107
0
        return value;
1108
0
    }
1109
};
1110
1111
}
1112
1113
// See comment for wxANY_VALUE_TYPE_CHECK_TYPE.
1114
#define wxANY_CHECK_TYPE(any, T) \
1115
0
    wxANY_VALUE_TYPE_CHECK_TYPE((any).GetType(), T)
1116
1117
1118
// This macro shouldn't be used any longer for the same reasons as
1119
// wxANY_VALUE_TYPE_CHECK_TYPE(), just call As() directly.
1120
#define wxANY_AS(any, T) \
1121
    (any).As(static_cast<T*>(nullptr))
1122
1123
1124
template<typename T>
1125
inline bool wxAnyValueType::CheckType() const
1126
{
1127
    return wxAnyValueTypeImpl<T>::IsSameClass(this);
1128
}
1129
1130
WX_DECLARE_LIST_WITH_DECL(wxAny, wxAnyList, class WXDLLIMPEXP_BASE);
1131
1132
#endif // wxUSE_ANY
1133
1134
#endif // _WX_ANY_H_