| Version: 3.2.8

Public Member Functions | List of all members
wxAnyValueType Class Referenceabstract
Class List by Category » Data Structures

`#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>)
wxAnyValueType
wxAnyValueType is base class for value type functionality for C++ data types used with wxAny.
Definition: any.h:383
wxAnyValueType::ConvertValue
virtual bool ConvertValue(const wxAnyValueBuffer &src, wxAnyValueType *dstType, wxAnyValueBuffer &dst) const =0
Convert value into buffer of different type.
wxAnyValueType::CheckType
bool CheckType() const
Use this template function for checking if wxAnyValueType represents a specific C++ data type.
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:315
wxAnyValueBuffer
Type for buffer within wxAny for holding data.
Definition: any.h:261

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,
wxAnyValueBuffer& buf)
{
// 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>)
wxAnyValueType::DeleteValue
virtual void DeleteValue(wxAnyValueBuffer &buf) const =0
This function is called every time the data in wxAny buffer needs to be freed.
wxAnyValueType::CopyBuffer
virtual void CopyBuffer(const wxAnyValueBuffer &src, wxAnyValueBuffer &dst) const =0
Implement this for buffer-to-buffer copy.
wxAnyValueBuffer::m_ptr
void * m_ptr
Definition: any.h:262

##

Library: wxBase
Category: Data Structures

See also
  wxAny

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

## Constructor & Destructor Documentation

## ◆ wxAnyValueType()

wxAnyValueType::wxAnyValueType | ( |  | ) |

Default constructor.

## ◆ ~wxAnyValueType()

virtual wxAnyValueType::~wxAnyValueType | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

## ◆ CheckType()

template<typename T >

bool wxAnyValueType::CheckType | ( |  | ) | const

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

See also
  wxAny::CheckType()

## ◆ ConvertValue()

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.

## ◆ CopyBuffer()

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

Implement this for buffer-to-buffer copy.

Parameters

  src | This is the source data buffer.
  dst | This is the destination data buffer that is in either uninitialized or freed state.

## ◆ DeleteValue()

virtual void wxAnyValueType::DeleteValue | ( | wxAnyValueBuffer & | buf | ) | const
| pure virtual

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

## ◆ IsSameType()

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

This function is used for internal type matching.