75#define WXCASTER_HELPER(TYPE) \
76 template<> struct wxany_caster<TYPE> : public wxany_arithmetic_caster<TYPE> \
96#define WXVECCASTER_HELPER(TYPE) \
98 struct wxany_caster<std::vector<TYPE>> : public wxany_avector_caster<TYPE> \
116#undef WXVECCASTER_HELPER
143 return t.as_value(*
this);
159 template<
typename VALUETYPE>
160 WxAny(
const VALUETYPE& value) : content(new _WxHolder<VALUETYPE>(value))
167 WxAny(
const WxAny& other) : content(other.content ? other.content->clone() : nullptr)
176 other.content =
nullptr;
191 std::swap(content, rhs.content);
202 WxAny(rhs).swap(*
this);
220 WxAny(rhs).swap(*
this);
235 const std::type_info&
type()
const
237 return content ? content->type() :
typeid(void);
247 return content ? content->sizeInBytes() : -1;
254 template<
typename VALUETYPE>
const VALUETYPE*
to_ptr()
const
257 return type() ==
typeid(VALUETYPE)
258 ? &
static_cast<_WxHolder<VALUETYPE>*
>(content)->held
268 return content->void_ptr();
277 return content->void_ptr();
287 template<
typename VALUETYPE> VALUETYPE
to_value()
const
297 virtual ~_WxPlaceHolder() =
default;
300 virtual const std::type_info& type()
const = 0;
303 virtual int sizeInBytes()
const = 0;
306 virtual _WxPlaceHolder* clone()
const = 0;
309 virtual const void* void_ptr()
const = 0;
312 virtual void* void_ptr() = 0;
315 template<
typename VALUETYPE>
class _WxHolder :
public _WxPlaceHolder
318 _WxHolder(
const VALUETYPE& value) : held(
value)
323 virtual const std::type_info&
type()
const
325 return typeid(VALUETYPE);
329 virtual int sizeInBytes()
const
331 return sizeof(VALUETYPE);
335 virtual _WxPlaceHolder* clone()
const
337 return new _WxHolder(held);
341 virtual const void* void_ptr()
const
343 return reinterpret_cast<const void*
>(&held);
347 virtual void* void_ptr()
349 return reinterpret_cast<void*
>(&held);
355 _WxPlaceHolder* content;
365template<
typename VALUETYPE>
369 const VALUETYPE* result = operand.template to_ptr<VALUETYPE>();
376 WxExcept wxe(
"wx_access_payload_with_type_check : ");
377 wxe <<
"Attempted to assign '" << operand.
type().name() <<
"' as '"
378 <<
typeid(VALUETYPE).name() <<
"'" << std::endl;
394 const VALUETYPE* result = operand.template to_ptr<VALUETYPE>();
400 throw std::bad_cast();
405#include "detail/wxany.tcc"
Class WxAny is based on the "any" class described in "Valued Conversion", Kevlin Henney,...
Definition: wxany.h:139
~WxAny()
Definition: wxany.h:179
int payloadSizeInBytes() const
Size in bytes for this object's held value.
Definition: wxany.h:245
WxAny(const WxAny &other)
Copy ctor.
Definition: wxany.h:167
WxAny & operator=(const WxAny &rhs)
Assignment operator: use WxAny object to create a new object.
Definition: wxany.h:200
WxAny()
Create empty object.
Definition: wxany.h:150
WxAny(WxAny &&other) noexcept
move ctor
Definition: wxany.h:174
bool empty() const
Is object empty?
Definition: wxany.h:227
WxAny & operator=(const VALUETYPE &rhs)
Assignment operator: use VALUETYPE object to create a new object.
Definition: wxany.h:218
const std::type_info & type() const
Type_info for this object's held value.
Definition: wxany.h:235
void * to_void_ptr()
Convert held object to a void *.
Definition: wxany.h:275
const VALUETYPE * to_ptr() const
Convert the held object to a pointer.
Definition: wxany.h:254
const void * to_void_ptr() const
Convert held object to a const void *.
Definition: wxany.h:266
WxAny & swap(WxAny &rhs)
Swap contents of object with contents of supplied object.
Definition: wxany.h:189
WxAny & operator=(WxAny &&rhs) noexcept
Definition: wxany.h:206
WxAny(const VALUETYPE &value)
Create new WxAny from an object of a given type.
Definition: wxany.h:160
VALUETYPE to_value() const
Extract the data from the WxAny object.
Definition: wxany.h:287
wxm::lib::Except is the class to use for creating and throwing exceptions.
Definition: wxexcept.h:31
VALUETYPE wx_access_payload_with_type_check(const WxAny &operand)
Extract the data from the WxAny object.
Definition: wxany.h:366
value
Definition: bloch_periodic_1D.py:182
type
Definition: sheath.py:84
Base namespace for everything not included in the global namespace.
Definition: field_source.h:8
Helper for casting any arithmetic type to any other arithmetic type.
Definition: wxany.h:27
T as_value(const WxAny &v) const
Helper for casting to a vector of arithmetic types from other vectors of arithmetic types or from a s...
Definition: wxany.h:46
std::vector< T > as_value(const WxAny &v) const
Helper for casting between various types.
Definition: wxany.h:63
T as_value(const WxAny &v) const
Helper for casting to a string type.
Definition: wxany.h:37
std::string as_value(const WxAny &v) const
Helper for casting to a vector of strings.
Definition: wxany.h:55
std::vector< std::string > as_value(const WxAny &v) const
#define WXCASTER_HELPER(TYPE)
Definition: wxany.h:75
#define WXVECCASTER_HELPER(TYPE)
Definition: wxany.h:96