wxAnyValueType is base class for value type functionality for C++ data types used with wxAny.
Usually the default template will create a satisfactory wxAnyValueType implementation for a data type, but sometimes you may need to add some customization. To do this you will need to add specialized template of wxAnyValueTypeImpl<>. Often your only need may be to add dynamic type conversion which would be done like this:
template<>
class wxAnyValueTypeImpl<MyClass> :
public wxAnyValueTypeImplBase<MyClass>
{
WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<MyClass>)
public:
wxAnyValueTypeImpl() :
wxAnyValueTypeImplBase<MyClass>() { }
virtual ~wxAnyValueTypeImpl() { }
virtual bool ConvertValue(const wxAnyValueBuffer& src,
wxAnyValueType* dstType,
wxAnyValueBuffer& dst) const
{
MyClass value = GetValue(src);
{
wxString s = value.ToString();
wxAnyValueTypeImpl<wxString>::SetValue(s, dst);
}
else
{
return false;
}
}
};
WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<MyClass>)
bool CheckType() const
Use this template function for checking if wxAnyValueType represents a specific C++ data type.
wxAnyValueTypeImplBase<> template, from which we inherit in the above example, contains the bulk of the default wxAnyValueTypeImpl<> template implementation, and as such allows you to easily add some minor customization.
If you need a have complete control over the type interpretation, you will need to derive a class directly from wxAnyValueType, like this:
template <>
{
WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<MyClass>)
public:
{
}
{
}
virtual bool ConvertValue(const wxAnyValueBuffer& src,
wxAnyValueType* dstType,
wxAnyValueBuffer& dst) const
{
}
static void SetValue(const T& value,
wxAnyValueBuffer& buf)
{
}
static const T& GetValue(const wxAnyValueBuffer& buf)
{
}
};
WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<MyClass>)
virtual void DeleteValue(wxAnyValueBuffer &buf) const =0
This function is called every time the data in wxAny buffer needs to be freed.
wxAnyValueType()
Default constructor.
Type for buffer within wxAny for holding data.
Definition any.h:261
void * m_ptr
Definition any.h:262
- See also
- wxAny