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.
wxVariant is similar to wxExpr and also to wxPropertyValue. However, wxExpr is efficiency-optimized for a restricted range of data types, whereas wxVariant is less efficient but more extensible. wxPropertyValue may be replaced by wxVariant eventually.
Derived from
Include files
<wx/variant.h>
See also
Members
wxVariant::wxVariant
wxVariant::~wxVariant
wxVariant::Append
wxVariant::ClearList
wxVariant::GetCount
wxVariant::Delete
wxVariant::GetBool
wxVariant::GetChar
wxVariant::GetData
wxVariant::GetDate
wxVariant::GetDouble
wxVariant::GetLong
wxVariant::GetName
wxVariant::GetString
wxVariant::GetTime
wxVariant::GetType
wxVariant::GetVoidPtr
wxVariant::Insert
wxVariant::IsNull
wxVariant::IsType
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 wxDate
wxVariant::operator wxString
wxVariant::operator wxTime
wxVariant::operator void*
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(const wxTime& value, const wxString& name = "")
Construction from a time.
wxVariant(const wxDate& value, const wxString& name = "")
Construction from a date.
wxVariant(void* value, const wxString& name = "")
Construction from a void pointer.
wxVariant(wxVariantData* data, const wxString& name = "")
Construction from user-defined data. The variant holds on to the data pointer.
~wxVariant()
Destructor.
void Append(const wxVariant& value)
Appends a value to the list.
void ClearList()
Deletes the contents of the list.
int GetCount() const
Returns the number of elements in the list.
bool Delete(int item)
Deletes the zero-based item from the list.
bool GetBool() const
Returns the boolean value.
char GetChar() const
Returns the character value.
wxVariantData* GetData() const
Returns a pointer to the internal variant data.
wxDate GetDate() const
Gets the date value.
double GetDouble() const
Returns the floating point value.
long GetLong() const
Returns the integer value.
const wxString& GetName() const
Returns a constant reference to the variant name.
wxString GetString() const
Gets the string value.
wxTime GetTime() const
Gets the time value.
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).
void* GetVoidPtr() const
Gets the void pointer value.
void Insert(const wxVariant& value)
Inserts a value at the front of the list.
bool IsNull() const
Returns TRUE if there is no data associated with this variant, FALSE if there is data.
bool IsType(const wxString& type) const
Returns TRUE if type matches the type of the variant, FALSE otherwise.
void MakeNull()
Makes the variant null by deleting the internal data.
wxString MakeString() const
Makes a string representation of the variant value (for any type).
bool Member(const wxVariant& value) const
Returns TRUE if value matches an element in the list.
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.
void SetData(wxVariantData* data)
Sets the internal variant data, deleting the existing data if there is any.
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 =(const wxDate& value)
void operator =(const wxTime& value)
void operator =(void* value)
void operator =(const wxList& value)
void operator =(const wxStringList& value)
Assignment operators.
bool operator ==(const wxVariant& value)
bool operator ==(const wxString& value)
bool operator ==(const char* value)
bool operator ==(char value)
bool operator ==(const long value)
bool operator ==(const bool value)
bool operator ==(const double value)
bool operator ==(const wxDate& value)
bool operator ==(const wxTime& value)
bool operator ==(void* value)
bool operator ==(const wxList& value)
bool operator ==(const wxStringList& value)
Equality test operators.
bool operator !=(const wxVariant& value)
bool operator !=(const wxString& value)
bool operator !=(const char* value)
bool operator !=(char value)
bool operator !=(const long value)
bool operator !=(const bool value)
bool operator !=(const double value)
bool operator !=(const wxDate& value)
bool operator !=(const wxTime& value)
bool operator !=(void* value)
bool operator !=(const wxList& value)
bool operator !=(const wxStringList& value)
Inequality test operators.
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.
char operator char() const
Operator for implicit conversion to a char, using wxVariant::GetChar.
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.
wxDate operator wxDate() const
Operator for implicit conversion to a wxDate, using wxVariant::GetDate.
wxString operator wxString() const
Operator for implicit conversion to a string, using wxVariant::MakeString.
wxTime operator wxTime() const
Operator for implicit conversion to a wxTime, using wxVariant::GetTime.
void* operator void*() const
Operator for implicit conversion to a pointer to a void, using wxVariant::GetVoidPtr.