Version: 3.0.2
wxAnyValueType Class Referenceabstract

#include <wx/any.h>

Detailed Description

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
{
// GetValue() is a static member function implemented
// in wxAnyValueTypeImplBase<>.
MyClass value = GetValue(src);
// TODO: Convert value from src buffer to destination
// type and buffer. If cannot be done, return
// false. This is a simple sample.
if ( dstType->CheckType<wxString>() )
{
wxString s = value.ToString();
wxAnyValueTypeImpl<wxString>::SetValue(s, dst);
}
else
{
return false;
}
}
};
//
// Following must be placed somewhere in your source code
WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<MyClass>)

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 <>
class wxAnyValueTypeImpl<MyClass> : public wxAnyValueType
{
WX_DECLARE_ANY_VALUE_TYPE(wxAnyValueTypeImpl<MyClass>)
public:
virtual void DeleteValue(wxAnyValueBuffer& buf) const
{
// TODO: Free the data in buffer
// It is important to clear the buffer like this
// at the end of DeleteValue().
buf.m_ptr = NULL;
}
virtual void CopyBuffer(const wxAnyValueBuffer& src,
wxAnyValueBuffer& dst) const
{
// TODO: Copy value from one buffer to another.
// dst is already uninitialized and does not
// need to be freed.
}
virtual bool ConvertValue(const wxAnyValueBuffer& src,
wxAnyValueType* dstType,
wxAnyValueBuffer& dst) const
{
// TODO: Convert value from src buffer to destination
// type and buffer.
}
//
// Following static functions must be implemented
//
static void SetValue(const T& value,
{
// TODO: Store value into buf.
}
static const T& GetValue(const wxAnyValueBuffer& buf)
{
// TODO: Return reference to value stored in buffer.
}
};
//
// Following must be placed somewhere in your source code
WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl<MyClass>)

Library:  wxBase
Category:  Data Structures
See Also
wxAny

Public Member Functions

 wxAnyValueType ()
 Default constructor.
 
virtual ~wxAnyValueType ()
 Destructor.
 
template<typename T >
bool CheckType () const
 Use this template function for checking if wxAnyValueType represents a specific C++ data type.
 
virtual bool ConvertValue (const wxAnyValueBuffer &src, wxAnyValueType *dstType, wxAnyValueBuffer &dst) const =0
 Convert value into buffer of different type.
 
virtual void CopyBuffer (const wxAnyValueBuffer &src, wxAnyValueBuffer &dst) const =0
 Implement this for buffer-to-buffer copy.
 
virtual void DeleteValue (wxAnyValueBuffer &buf) const =0
 This function is called every time the data in wxAny buffer needs to be freed.
 
virtual bool IsSameType (const wxAnyValueType *otherType) const =0
 This function is used for internal type matching.
 

Constructor & Destructor Documentation

wxAnyValueType::wxAnyValueType ( )

Default constructor.

virtual wxAnyValueType::~wxAnyValueType ( )
virtual

Destructor.

Member Function Documentation

template<typename T >
bool wxAnyValueType::CheckType ( ) const

Use this template function for checking if wxAnyValueType represents a specific C++ data type.

Remarks
This template function does not work on some older compilers (such as Visual C++ 6.0). For full compiler compatibility please use wxANY_VALUE_TYPE_CHECK_TYPE(valueTypePtr, T) macro instead.
See Also
wxAny::CheckType()
virtual bool wxAnyValueType::ConvertValue ( const wxAnyValueBuffer src,
wxAnyValueType dstType,
wxAnyValueBuffer dst 
) const
pure virtual

Convert value into buffer of different type.

Return false if not possible.

virtual void wxAnyValueType::CopyBuffer ( const wxAnyValueBuffer src,
wxAnyValueBuffer dst 
) const
pure virtual

Implement this for buffer-to-buffer copy.

Parameters
srcThis is the source data buffer.
dstThis is the destination data buffer that is in either uninitialized or freed state.
virtual void wxAnyValueType::DeleteValue ( wxAnyValueBuffer buf) const
pure virtual

This function is called every time the data in wxAny buffer needs to be freed.

virtual bool wxAnyValueType::IsSameType ( const wxAnyValueType otherType) const
pure virtual

This function is used for internal type matching.