wxAny Class Reference
[Data Structures]

#include <wx/any.h>


Detailed Description

The wxAny class represents a container for any type.

Its value can be changed at run time, possibly to a different type of value.

wxAny is a backwards incompatible successor class for wxVariant, essentially doing the same thing in a more modern, template-based manner and with transparent support for any user data type.

Some pseudo-code'ish example of use with arbitrary user data:

    void SomeFunction()
    {
        MyClass myObject;
        wxAny any = myObject;

        // Do something
        // ...

        // Let's do a sanity check to make sure that any still holds
        // data of correct type.
        if ( any.CheckType<MyClass>() )
        {
            // Thank goodness, still a correct type.
            MyClass myObject2 = any.As<MyClass>();
        }
        else
        {
            // Something has gone horribly wrong!
            wxFAIL();
        }
    }

When compared to wxVariant, there are various internal implementation differences as well. For instance, wxAny only allocates separate data object in heap for large (ie. size in bytes more than WX_ANY_VALUE_BUFFER_SIZE) or 'non-movable' data types. Pointers, integers, bools etc. are fitted in the wxAny's own buffer without need for any extra allocation. Use following code to declare your own data type as 'movable':

    #include "wx/meta/movable.h"
    WX_DECLARE_TYPE_MOVABLE(MyClass)

However, you must be aware that 'movable' means such data that can be copied with memcpy() without corrupting program integrity. For instance, movable objects usually cannot contain pointers or references to other data. wxRect, wxPoint, and wxSize are good examples of movable classes.

Note that pointers to any and all classes are already automatically declared as movable data.

Library:  wxBase
Category:  Data Structures
See also:
wxAnyValueType, wxVariant, Caveats When Not Using C++ RTTI

Public Member Functions

 wxAny ()
 Default constructor.
template<typename T >
 wxAny (const T &value)
 Constructs wxAny from data.
 wxAny (const wxAny &any)
 Constructs wxAny from another wxAny.
 ~wxAny ()
 Destructor.
template<typename T >
As () const
 This template function converts wxAny into given type.
template<typename T >
bool CheckType ()
 Use this template function for checking if this wxAny holds a specific C++ data type.
template<typename T >
bool GetAs (T *value) const
 Template function that retrieves and converts the value of this wxAny to the type that T* value is.
const wxAnyValueTypeGetType () const
 Returns the value type as wxAnyValueType instance.
bool IsNull () const
 Tests if wxAny is null (that is, whether there is data).
void MakeNull ()
 Makes wxAny null (that is, clears it).
Assignment operators

template<typename T >
wxAnyoperator= (const T &value)
wxAnyoperator= (const wxAny &any)
Equality operators

bool operator== (signed char value) const
bool operator== (signed short value) const
bool operator== (signed int value) const
bool operator== (signed long value) const
bool operator== (wxLongLong_t value) const
bool operator== (unsigned char value) const
bool operator== (unsigned short value) const
bool operator== (unsigned int value) const
bool operator== (unsigned long value) const
bool operator== (wxULongLong_t value) const
bool operator== (float value) const
bool operator== (double value) const
bool operator== (bool value) const
bool operator== (const char *value) const
bool operator== (const wchar_t *value) const
bool operator== (const wxString &value) const
Inequality operators

bool operator!= (signed char value) const
bool operator!= (signed short value) const
bool operator!= (signed int value) const
bool operator!= (signed long value) const
bool operator!= (wxLongLong_t value) const
bool operator!= (unsigned char value) const
bool operator!= (unsigned short value) const
bool operator!= (unsigned int value) const
bool operator!= (unsigned long value) const
bool operator!= (wxULongLong_t value) const
bool operator!= (float value) const
bool operator!= (double value) const
bool operator!= (bool value) const
bool operator!= (const char *value) const
bool operator!= (const wchar_t *value) const
bool operator!= (const wxString &value) const

List of all members.


Constructor & Destructor Documentation

wxAny::wxAny (  ) 

Default constructor.

It seeds the object with a null value.

template<typename T >
wxAny::wxAny ( const T &  value  )  [inline]

Constructs wxAny from data.

wxAny::wxAny ( const wxAny any  ) 

Constructs wxAny from another wxAny.

wxAny::~wxAny (  ) 

Destructor.


Member Function Documentation

template<typename T >
T wxAny::As (  )  const [inline]

This template function converts wxAny into given type.

No dynamic conversion is performed, so if the type is incorrect an assertion failure will occur in debug builds, and a bogus value is returned in release ones.

Remarks:
This template function may not work properly with Visual C++ 6. For full compiler compatibility, please use wxANY_AS(any, T) macro instead.
template<typename T >
bool wxAny::CheckType (  )  [inline]

Use this template function for checking if this wxAny holds a specific C++ data type.

Remarks:
This template function may not work properly with Visual C++ 6. For full compiler compatibility, please use wxANY_CHECK_TYPE(any, T) macro instead.
See also:
wxAnyValueType::CheckType()
template<typename T >
bool wxAny::GetAs ( T *  value  )  const [inline]

Template function that retrieves and converts the value of this wxAny to the type that T* value is.

Returns:
Returns true if conversion was successful.
const wxAnyValueType* wxAny::GetType (  )  const

Returns the value type as wxAnyValueType instance.

Remarks:
You cannot reliably test whether two wxAnys are of same value type by simply comparing return values of wxAny::GetType(). Instead use wxAnyValueType::CheckType<T>() template function.
bool wxAny::IsNull (  )  const

Tests if wxAny is null (that is, whether there is data).

void wxAny::MakeNull (  ) 

Makes wxAny null (that is, clears it).

bool wxAny::operator!= ( const wxString value  )  const
bool wxAny::operator!= ( const wchar_t *  value  )  const
bool wxAny::operator!= ( const char *  value  )  const
bool wxAny::operator!= ( bool  value  )  const
bool wxAny::operator!= ( double  value  )  const
bool wxAny::operator!= ( float  value  )  const
bool wxAny::operator!= ( wxULongLong_t  value  )  const
bool wxAny::operator!= ( unsigned long  value  )  const
bool wxAny::operator!= ( unsigned int  value  )  const
bool wxAny::operator!= ( unsigned short  value  )  const
bool wxAny::operator!= ( unsigned char  value  )  const
bool wxAny::operator!= ( wxLongLong_t  value  )  const
bool wxAny::operator!= ( signed long  value  )  const
bool wxAny::operator!= ( signed int  value  )  const
bool wxAny::operator!= ( signed short  value  )  const
bool wxAny::operator!= ( signed char  value  )  const
wxAny& wxAny::operator= ( const wxAny any  ) 
template<typename T >
wxAny& wxAny::operator= ( const T &  value  )  [inline]
bool wxAny::operator== ( const wxString value  )  const
bool wxAny::operator== ( const wchar_t *  value  )  const
bool wxAny::operator== ( const char *  value  )  const
bool wxAny::operator== ( bool  value  )  const
bool wxAny::operator== ( double  value  )  const
bool wxAny::operator== ( float  value  )  const
bool wxAny::operator== ( wxULongLong_t  value  )  const
bool wxAny::operator== ( unsigned long  value  )  const
bool wxAny::operator== ( unsigned int  value  )  const
bool wxAny::operator== ( unsigned short  value  )  const
bool wxAny::operator== ( unsigned char  value  )  const
bool wxAny::operator== ( wxLongLong_t  value  )  const
bool wxAny::operator== ( signed long  value  )  const
bool wxAny::operator== ( signed int  value  )  const
bool wxAny::operator== ( signed short  value  )  const
bool wxAny::operator== ( signed char  value  )  const
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines



wxWidgets logo

[ top ]