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