Contents Up Previous Next

wxVariant

The wxVariant class represents a container for any type. A variant's value can be changed at run time, possibly to a different type of value.

As standard, wxVariant can store values of type bool, char, double, long, string, string list, time, date, void pointer, list of strings, and list of variants. However, an application can extend wxVariant's capabilities by deriving from the class wxVariantData and using the wxVariantData form of the wxVariant constructor or assignment operator to assign this data to a variant. Actual values for user-defined types will need to be accessed via the wxVariantData object, unlike the case for basic data types where convenience functions such as GetLong can be used.

This class is useful for reducing the programming for certain tasks, such as an editor for different data types, or a remote procedure call protocol.

An optional name member is associated with a wxVariant. This might be used, for example, in CORBA or OLE automation classes, where named parameters are required.

Derived from

wxObject

Include files

<wx/variant.h>

See also

wxVariantData

Members

wxVariant::wxVariant
wxVariant::~wxVariant
wxVariant::Append
wxVariant::ClearList
wxVariant::Convert
wxVariant::GetCount
wxVariant::Delete
wxVariant::GetArrayString
wxVariant::GetBool
wxVariant::GetChar
wxVariant::GetData
wxVariant::GetDateTime
wxVariant::GetDouble
wxVariant::GetLong
wxVariant::GetName
wxVariant::GetString
wxVariant::GetType
wxVariant::GetVoidPtr
wxVariant::GetWxObjectPtr
wxVariant::Insert
wxVariant::IsNull
wxVariant::IsType
wxVariant::IsValueKindOf
wxVariant::MakeNull
wxVariant::MakeString
wxVariant::Member
wxVariant::NullList
wxVariant::SetData
wxVariant::operator =
wxVariant::operator ==
wxVariant::operator !=
wxVariant::operator []
wxVariant::operator char
wxVariant::operator double
wxVariant::operator wxString
wxVariant::operator void*
wxVariant::operator wxDateTime


wxVariant::wxVariant

wxVariant()

Default constructor.

wxVariant(const wxVariant& variant)

Copy constructor.

wxVariant(const char* value, const wxString& name = "")

wxVariant(const wxString& value, const wxString& name = "")

Construction from a string value.

wxVariant(char value, const wxString& name = "")

Construction from a character value.

wxVariant(long value, const wxString& name = "")

Construction from an integer value. You may need to cast to (long) to avoid confusion with other constructors (such as the bool constructor).

wxVariant(bool value, const wxString& name = "")

Construction from a boolean value.

wxVariant(double value, const wxString& name = "")

Construction from a double-precision floating point value.

wxVariant(const wxList& value, const wxString& name = "")

Construction from a list of wxVariant objects. This constructor copies value, the application is still responsible for deleting value and its contents.

wxVariant(const wxStringList& value, const wxString& name = "")

Construction from a list of strings. This constructor copies value, the application is still responsible for deleting value and its contents.

wxVariant(void* value, const wxString& name = "")

Construction from a void pointer.

wxVariant(wxObject* value, const wxString& name = "")

Construction from a wxObject pointer.

wxVariant(wxVariantData* data, const wxString& name = "")

Construction from user-defined data. The variant holds onto the data pointer.

wxVariant(wxDateTime& val, const wxString& name = "")

Construction from a wxDateTime.

wxVariant(wxArrayString& val, const wxString& name = "")

Construction from an array of strings. This constructor copies value and its contents.

wxVariant(DATE_STRUCT* val, const wxString& name = "")

Construction from a odbc date value. Represented internally by a wxDateTime value.

wxVariant(TIME_STRUCT* val, const wxString& name = "")

Construction from a odbc time value. Represented internally by a wxDateTime value.

wxVariant(TIMESTAMP_STRUCT* val, const wxString& name = "")

Construction from a odbc timestamp value. Represented internally by a wxDateTime value.


wxVariant::~wxVariant

~wxVariant()

Destructor.


wxVariant::Append

void Append(const wxVariant& value)

Appends a value to the list.


wxVariant::ClearList

void ClearList()

Deletes the contents of the list.


wxVariant::Convert

bool Convert(long* value) const

bool Convert(bool* value) const

bool Convert(double* value) const

bool Convert(wxString* value) const

bool Convert(char* value) const

bool Convert(wxDateTime* value) const

Retrieves and converts the value of this variant to the type that value is.


wxVariant::GetCount

int GetCount() const

Returns the number of elements in the list.


wxVariant::Delete

bool Delete(int item)

Deletes the zero-based item from the list.


wxVariant::GetArrayString

wxArrayString GetArrayString() const

Returns the string array value.


wxVariant::GetBool

bool GetBool() const

Returns the boolean value.


wxVariant::GetChar

char GetChar() const

Returns the character value.


wxVariant::GetData

wxVariantData* GetData() const

Returns a pointer to the internal variant data.


wxVariant::GetDateTime

wxDateTime GetDateTime() const

Returns the date value.


wxVariant::GetDouble

double GetDouble() const

Returns the floating point value.


wxVariant::GetLong

long GetLong() const

Returns the integer value.


wxVariant::GetName

const wxString& GetName() const

Returns a constant reference to the variant name.


wxVariant::GetString

wxString GetString() const

Gets the string value.


wxVariant::GetType

wxString GetType() const

Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.

If the variant is null, the value type returned is the string "null" (not the empty string).


wxVariant::GetVoidPtr

void* GetVoidPtr() const

Gets the void pointer value.


wxVariant::GetWxObjectPtr

void* GetWxObjectPtr() const

Gets the wxObject pointer value.


wxVariant::Insert

void Insert(const wxVariant& value)

Inserts a value at the front of the list.


wxVariant::IsNull

bool IsNull() const

Returns true if there is no data associated with this variant, false if there is data.


wxVariant::IsType

bool IsType(const wxString& type) const

Returns true if type matches the type of the variant, false otherwise.


wxVariant::IsValueKindOf

bool IsValueKindOf(const wxClassInfo* type type) const

Returns true if the data is derived from the class described by type, false otherwise.


wxVariant::MakeNull

void MakeNull()

Makes the variant null by deleting the internal data.


wxVariant::MakeString

wxString MakeString() const

Makes a string representation of the variant value (for any type).


wxVariant::Member

bool Member(const wxVariant& value) const

Returns true if value matches an element in the list.


wxVariant::NullList

void NullList()

Makes an empty list. This differs from a null variant which has no data; a null list is of type list, but the number of elements in the list is zero.


wxVariant::SetData

void SetData(wxVariantData* data)

Sets the internal variant data, deleting the existing data if there is any.


wxVariant::operator =

void operator =(const wxVariant& value)

void operator =(wxVariantData* value)

void operator =(const wxString& value)

void operator =(const char* value)

void operator =(char value)

void operator =(const long value)

void operator =(const bool value)

void operator =(const double value)

void operator =(void* value)

void operator =(const wxList& value)

void operator =(const wxStringList& value)

void operator =(const wxDateTime& value)

void operator =(const wxArrayString& value)

void operator =(const DATE_STRUCT* value)

void operator =(const TIME_STRUCT* value)

void operator =(const TIMESTAMP_STRUCT* value)

Assignment operators.


wxVariant::operator ==

bool operator ==(const wxVariant& value) const

bool operator ==(const wxString& value) const

bool operator ==(const char* value) const

bool operator ==(char value) const

bool operator ==(const long value) const

bool operator ==(const bool value) const

bool operator ==(const double value) const

bool operator ==(void* value) const

bool operator ==(const wxList& value) const

bool operator ==(const wxStringList& value) const

bool operator ==(const wxArrayString& value) const

bool operator ==(const wxDateTime& value) const

Equality test operators.


wxVariant::operator !=

bool operator !=(const wxVariant& value) const

bool operator !=(const wxString& value) const

bool operator !=(const char* value) const

bool operator !=(char value) const

bool operator !=(const long value) const

bool operator !=(const bool value) const

bool operator !=(const double value) const

bool operator !=(void* value) const

bool operator !=(const wxList& value) const

bool operator !=(const wxStringList& value) const

bool operator !=(const wxArrayString& value) const

bool operator !=(const wxDateTime& value) const

Inequality test operators.


wxVariant::operator []

wxVariant operator [](size_t idx) const

Returns the value at idx (zero-based).

wxVariant& operator [](size_t idx)

Returns a reference to the value at idx (zero-based). This can be used to change the value at this index.


wxVariant::operator char

char operator char() const

Operator for implicit conversion to a char, using wxVariant::GetChar.


wxVariant::operator double

double operator double() const

Operator for implicit conversion to a double, using wxVariant::GetDouble.

long operator long() const

Operator for implicit conversion to a long, using wxVariant::GetLong.


wxVariant::operator wxString

wxString operator wxString() const

Operator for implicit conversion to a string, using wxVariant::MakeString.


wxVariant::operator void*

void* operator void*() const

Operator for implicit conversion to a pointer to a void, using wxVariant::GetVoidPtr.


wxVariant::operator wxDateTime

void* operator wxDateTime() const

Operator for implicit conversion to a pointer to a wxDateTime, using wxVariant::GetDateTime.