2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: variant.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxVariant
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxVariant
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
The wxVariant class represents a container for any type. A variant's value
|
2008-04-22 04:57:43 -04:00
|
|
|
can be changed at run time, possibly to a different type of value.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
@note As of wxWidgets 2.9.1, wxAny has become the preferred variant class.
|
|
|
|
While most controls still use wxVariant in their interface, you
|
|
|
|
can start using wxAny in your code because of an implicit conversion
|
|
|
|
layer. See below for more information.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
As standard, wxVariant can store values of type bool, wxChar, double, long,
|
2008-04-28 04:26:04 -04:00
|
|
|
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.
|
|
|
|
|
|
|
|
Pointers to any wxObject derived class can also easily be stored in a
|
|
|
|
wxVariant. wxVariant will then use wxWidgets' built-in RTTI system to set
|
|
|
|
the type name (returned by GetType()) and to perform type-safety checks at
|
|
|
|
runtime.
|
|
|
|
|
|
|
|
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.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
An optional name member is associated with a wxVariant. This might be used,
|
2008-04-28 04:26:04 -04:00
|
|
|
for example, in CORBA or OLE automation classes, where named parameters are
|
|
|
|
required.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
Note that as of wxWidgets 2.7.1, wxVariant is
|
|
|
|
@ref overview_refcount "reference counted". Additionally, the convenience
|
|
|
|
macros DECLARE_VARIANT_OBJECT() and IMPLEMENT_VARIANT_OBJECT() were added
|
|
|
|
so that adding (limited) support for conversion to and from wxVariant can
|
|
|
|
be very easily implemented without modifying either wxVariant or the class
|
|
|
|
to be stored by wxVariant. Since assignment operators cannot be declared
|
|
|
|
outside the class, the shift left operators are used like this:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
// in the header file
|
2008-04-22 04:57:43 -04:00
|
|
|
DECLARE_VARIANT_OBJECT(MyClass)
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
// in the implementation file
|
|
|
|
IMPLEMENT_VARIANT_OBJECT(MyClass)
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
// in the user code
|
|
|
|
wxVariant variant;
|
|
|
|
MyClass value;
|
|
|
|
variant << value;
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
// or
|
|
|
|
value << variant;
|
2008-03-08 08:52:38 -05:00
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
For this to work, MyClass must derive from wxObject, implement the
|
|
|
|
@ref overview_rtti "wxWidgets RTTI system" and support the assignment
|
|
|
|
operator and equality operator for itself. Ideally, it should also be
|
|
|
|
reference counted to make copying operations cheap and fast. This can be
|
|
|
|
most easily implemented using the reference counting support offered by
|
|
|
|
wxObject itself. By default, wxWidgets already implements the shift
|
|
|
|
operator conversion for a few of its drawing related classes:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
IMPLEMENT_VARIANT_OBJECT(wxColour)
|
|
|
|
IMPLEMENT_VARIANT_OBJECT(wxImage)
|
|
|
|
IMPLEMENT_VARIANT_OBJECT(wxIcon)
|
|
|
|
IMPLEMENT_VARIANT_OBJECT(wxBitmap)
|
|
|
|
@endcode
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
Note that as of wxWidgets 2.9.0, wxVariantData no longer inherits from
|
|
|
|
wxObject and wxVariant no longer uses the type-unsafe wxList class for list
|
2008-03-08 08:52:38 -05:00
|
|
|
operations but the type-safe wxVariantList class. Also, wxVariantData now
|
2008-04-28 04:26:04 -04:00
|
|
|
supports the wxVariantData::Clone() function for implementing the Unshare()
|
|
|
|
function. wxVariantData::Clone() is implemented automatically by
|
|
|
|
IMPLEMENT_VARIANT_OBJECT().
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
Since wxVariantData no longer derives from wxObject, any code that tests
|
|
|
|
the type of the data using wxDynamicCast() will require adjustment. You can
|
|
|
|
use the macro wxDynamicCastVariantData() with the same arguments as
|
|
|
|
wxDynamicCast(), to use C++ RTTI type information instead of wxWidgets
|
|
|
|
RTTI.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
@section variant_wxanyconversion wxVariant to wxAny Conversion Layer
|
|
|
|
|
|
|
|
wxAny is a more modern, template-based variant class. It is not
|
|
|
|
directly compatible with wxVariant, but there is a transparent conversion
|
|
|
|
layer.
|
|
|
|
|
|
|
|
Following is an example how to use these conversions with wxPropertyGrid's
|
|
|
|
property class wxPGProperty (which currently uses wxVariants both
|
|
|
|
internally and in the public API):
|
|
|
|
|
|
|
|
@code
|
|
|
|
// Get property value as wxAny instead of wxVariant
|
|
|
|
wxAny value = property->GetValue();
|
|
|
|
|
|
|
|
// Do something with it
|
|
|
|
DoSomethingWithString(value.As<wxString>());
|
|
|
|
|
|
|
|
// Write back new value to property
|
|
|
|
value = "New Value";
|
|
|
|
property->SetValue(value);
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
Some caveats:
|
|
|
|
@li In wxAny, there are no separate types for handling integers of
|
|
|
|
different sizes, so converting wxAny with 'long long' value
|
|
|
|
will yield wxVariant of "long" type when the value is small
|
|
|
|
enough to fit in without overflow. Otherwise, variant type
|
|
|
|
"longlong" is used. Also note that wxAny holding unsigned integer
|
|
|
|
will always be converted to "ulonglong" wxVariant type.
|
|
|
|
|
|
|
|
@li Unlike wxVariant, wxAny does not store a (rarely needed) name string.
|
|
|
|
|
|
|
|
@li Because of implicit conversion of wxVariant to wxAny, wxAny cannot
|
|
|
|
usually contain value of type wxVariant. In other words,
|
|
|
|
any.CheckType<wxVariant>() can never return @true.
|
|
|
|
|
|
|
|
Supplied conversion functions will automatically work with all
|
|
|
|
built-in wxVariant types, and also with all user-specified types generated
|
|
|
|
using IMPLEMENT_VARIANT_OBJECT(). For hand-built wxVariantData classes,
|
|
|
|
you will need to use supplied macros in a following manner:
|
|
|
|
|
|
|
|
@code
|
|
|
|
|
|
|
|
// Declare wxVariantData for data type Foo
|
|
|
|
class wxVariantDataFoo: public wxVariantData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// interface
|
|
|
|
// ...
|
|
|
|
|
|
|
|
DECLARE_WXANY_CONVERSION()
|
|
|
|
protected:
|
|
|
|
// data storage etc
|
|
|
|
// ...
|
|
|
|
};
|
|
|
|
|
|
|
|
IMPLEMENT_TRIVIAL_WXANY_CONVERSION(Foo, wxVariantDataFoo)
|
|
|
|
|
|
|
|
@endcode
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
|
|
|
@category{data}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
@see wxVariantData, wxAny
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxVariant : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-04-22 04:57:43 -04:00
|
|
|
Default constructor.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
wxVariant();
|
2008-10-13 09:24:43 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Constructs a variant directly with a wxVariantData object. wxVariant
|
|
|
|
will take ownership of the wxVariantData and will not increase its
|
|
|
|
reference count.
|
2008-04-22 04:57:43 -04:00
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(wxVariantData* data, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Constructs a variant from another variant by increasing the reference
|
|
|
|
count.
|
2008-04-22 04:57:43 -04:00
|
|
|
*/
|
2008-03-08 09:43:31 -05:00
|
|
|
wxVariant(const wxVariant& variant);
|
2008-10-13 09:24:43 -04:00
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant by converting it from wxAny.
|
|
|
|
*/
|
|
|
|
wxVariant(const wxAny& any);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a wide string literal.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(const wxChar* value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a string.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(const wxString& value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a wide char.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(wxChar value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a long.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(long value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a bool.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(bool value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a double.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(double value, const wxString& name = wxEmptyString);
|
|
|
|
|
2009-06-15 18:43:27 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a wxLongLong.
|
|
|
|
*/
|
|
|
|
wxVariant(wxLongLong value, const wxString& name = wxEmptyString);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Constructs a variant from a wxULongLong.
|
|
|
|
*/
|
|
|
|
wxVariant(wxULongLong value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a list of variants
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(const wxVariantList& value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a void pointer.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(void* value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a pointer to an wxObject
|
|
|
|
derived class.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
wxVariant(wxObject* value, const wxString& name = wxEmptyString);
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a wxDateTime.
|
|
|
|
*/
|
2008-10-28 10:29:36 -04:00
|
|
|
wxVariant(const wxDateTime& val, const wxString& name = wxEmptyString);
|
2008-10-13 09:24:43 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Constructs a variant from a wxArrayString.
|
|
|
|
*/
|
2008-10-28 10:29:36 -04:00
|
|
|
wxVariant(const wxArrayString& val, const wxString& name = wxEmptyString);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
2008-04-28 04:26:04 -04:00
|
|
|
|
|
|
|
@note wxVariantData's destructor is protected, so wxVariantData cannot
|
|
|
|
usually be deleted. Instead, wxVariantData::DecRef() should be
|
|
|
|
called. See @ref overview_refcount_destruct
|
|
|
|
"reference-counted object destruction" for more info.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxVariant();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
@name List Functionality
|
2008-04-22 04:57:43 -04:00
|
|
|
*/
|
|
|
|
//@{
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Returns the value at @a idx (zero-based).
|
|
|
|
*/
|
2008-04-28 04:26:04 -04:00
|
|
|
wxVariant operator [](size_t idx) const;
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns a reference to the value at @a idx (zero-based). This can be
|
|
|
|
used to change the value at this index.
|
2008-04-22 04:57:43 -04:00
|
|
|
*/
|
2008-04-28 04:26:04 -04:00
|
|
|
wxVariant& operator [](size_t idx);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Appends a value to the list.
|
|
|
|
*/
|
|
|
|
void Append(const wxVariant& value);
|
2008-04-28 04:26:04 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Makes the variant null by deleting the internal data and set the name
|
|
|
|
to wxEmptyString.
|
|
|
|
*/
|
|
|
|
void Clear();
|
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Deletes the contents of the list.
|
|
|
|
*/
|
|
|
|
void ClearList();
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Deletes the zero-based @a item from the list.
|
|
|
|
*/
|
|
|
|
bool Delete(size_t item);
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
|
|
|
Returns the number of elements in the list.
|
|
|
|
*/
|
|
|
|
size_t GetCount() const;
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns a reference to the wxVariantList class used by wxVariant if
|
|
|
|
this wxVariant is currently a list of variants.
|
2008-04-22 04:57:43 -04:00
|
|
|
*/
|
|
|
|
wxVariantList& GetList() const;
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-04-22 04:57:43 -04:00
|
|
|
Inserts a value at the front of the list.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-04-22 04:57:43 -04:00
|
|
|
void Insert(const wxVariant& value);
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
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.
|
2008-04-22 04:57:43 -04:00
|
|
|
*/
|
|
|
|
void NullList();
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-04-22 04:57:43 -04:00
|
|
|
//@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
//@{
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Retrieves and converts the value of this variant to the type that
|
|
|
|
@a value is.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool Convert(long* value) const;
|
2008-04-28 04:26:04 -04:00
|
|
|
bool Convert(bool* value) const;
|
|
|
|
bool Convert(double* value) const;
|
|
|
|
bool Convert(wxString* value) const;
|
|
|
|
bool Convert(wxChar* value) const;
|
2009-06-15 18:43:27 -04:00
|
|
|
bool Convert(wxLongLong* value) const;
|
|
|
|
bool Convert(wxULongLong* value) const;
|
2008-04-28 04:26:04 -04:00
|
|
|
bool Convert(wxDateTime* value) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
/**
|
|
|
|
Converts wxVariant into wxAny.
|
|
|
|
*/
|
|
|
|
wxAny GetAny() const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns the string array value.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxArrayString GetArrayString() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the boolean value.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool GetBool() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the character value.
|
|
|
|
*/
|
2008-10-28 10:29:36 -04:00
|
|
|
wxUniChar GetChar() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns a pointer to the internal variant data. To take ownership of
|
|
|
|
this data, you must call its wxVariantData::IncRef() method. When you
|
|
|
|
stop using it, wxVariantData::DecRef() must be called as well.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxVariantData* GetData() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the date value.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxDateTime GetDateTime() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the floating point value.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
double GetDouble() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the integer value.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
long GetLong() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-06-15 18:43:27 -04:00
|
|
|
/**
|
|
|
|
Returns the signed 64-bit integer value.
|
|
|
|
*/
|
|
|
|
wxLongLong GetLongLong() const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns a constant reference to the variant name.
|
|
|
|
*/
|
2008-10-28 10:29:36 -04:00
|
|
|
const wxString& GetName() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the string value.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetString() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns the value type as a string.
|
|
|
|
|
|
|
|
The built-in types are:
|
|
|
|
- "bool"
|
|
|
|
- "char"
|
|
|
|
- "datetime"
|
|
|
|
- "double"
|
|
|
|
- "list"
|
|
|
|
- "long"
|
2009-06-15 18:43:27 -04:00
|
|
|
- "longlong"
|
2008-04-28 04:26:04 -04:00
|
|
|
- "string"
|
2009-06-15 18:43:27 -04:00
|
|
|
- "ulonglong"
|
2008-04-28 04:26:04 -04:00
|
|
|
- "arrstring"
|
|
|
|
- "void*"
|
|
|
|
|
|
|
|
If the variant is null, the value type returned is the string "null"
|
|
|
|
(not the empty string).
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString GetType() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-06-15 18:43:27 -04:00
|
|
|
/**
|
|
|
|
Returns the unsigned 64-bit integer value.
|
|
|
|
*/
|
|
|
|
wxULongLong GetULongLong() const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Gets the void pointer value.
|
2009-01-25 08:19:44 -05:00
|
|
|
|
|
|
|
Notice that this method can be used for null objects (i.e. those for
|
|
|
|
which IsNull() returns @true) and will return @NULL for them.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* GetVoidPtr() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the wxObject pointer value.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxObject* GetWxObjectPtr() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns @true if there is no data associated with this variant, @false
|
|
|
|
if there is data.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsNull() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns @true if @a type matches the type of the variant, @false
|
|
|
|
otherwise.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsType(const wxString& type) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns @true if the data is derived from the class described by
|
|
|
|
@a type, @false otherwise.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-04-28 04:26:04 -04:00
|
|
|
bool IsValueKindOf(const wxClassInfo* type) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Makes the variant null by deleting the internal data.
|
|
|
|
*/
|
|
|
|
void MakeNull();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Makes a string representation of the variant value (for any type).
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString MakeString() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-09 08:33:59 -04:00
|
|
|
Returns @true if @a value matches an element in the list.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool Member(const wxVariant& value) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Sets the internal variant data, deleting the existing data if there is
|
|
|
|
any.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetData(wxVariantData* data);
|
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Makes sure that any data associated with this variant is not shared
|
|
|
|
with other variants. For this to work, wxVariantData::Clone() must be
|
|
|
|
implemented for the data types you are working with.
|
|
|
|
wxVariantData::Clone() is implemented for all the default data types.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
bool Unshare();
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Inequality test operator.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool operator !=(const wxVariant& value) const;
|
2008-04-28 04:26:04 -04:00
|
|
|
bool operator !=(const wxString& value) const;
|
|
|
|
bool operator !=(const wxChar* value) const;
|
|
|
|
bool operator !=(wxChar value) const;
|
2008-11-13 16:32:53 -05:00
|
|
|
bool operator !=(long value) const;
|
|
|
|
bool operator !=(bool value) const;
|
|
|
|
bool operator !=(double value) const;
|
2009-06-15 18:43:27 -04:00
|
|
|
bool operator !=(wxLongLong value) const;
|
|
|
|
bool operator !=(wxULongLong value) const;
|
2008-04-28 04:26:04 -04:00
|
|
|
bool operator !=(void* value) const;
|
|
|
|
bool operator !=(wxObject* value) const;
|
|
|
|
bool operator !=(const wxVariantList& value) const;
|
|
|
|
bool operator !=(const wxArrayString& value) const;
|
|
|
|
bool operator !=(const wxDateTime& value) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Assignment operator, using @ref overview_refcount "reference counting"
|
|
|
|
if possible.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void operator =(const wxVariant& value);
|
2008-03-08 09:43:31 -05:00
|
|
|
void operator =(wxVariantData* value);
|
|
|
|
void operator =(const wxString& value);
|
|
|
|
void operator =(const wxChar* value);
|
|
|
|
void operator =(wxChar value);
|
2008-11-13 16:32:53 -05:00
|
|
|
void operator =(long value);
|
|
|
|
void operator =(bool value);
|
|
|
|
void operator =(double value);
|
2009-06-15 18:43:27 -04:00
|
|
|
bool operator =(wxLongLong value) const;
|
|
|
|
bool operator =(wxULongLong value) const;
|
2008-03-08 09:43:31 -05:00
|
|
|
void operator =(void* value);
|
|
|
|
void operator =(wxObject* value);
|
|
|
|
void operator =(const wxVariantList& value);
|
|
|
|
void operator =(const wxDateTime& value);
|
|
|
|
void operator =(const wxArrayString& value);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Equality test operator.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool operator ==(const wxVariant& value) const;
|
2008-04-28 04:26:04 -04:00
|
|
|
bool operator ==(const wxString& value) const;
|
|
|
|
bool operator ==(const wxChar* value) const;
|
|
|
|
bool operator ==(wxChar value) const;
|
2008-11-13 16:32:53 -05:00
|
|
|
bool operator ==(long value) const;
|
|
|
|
bool operator ==(bool value) const;
|
|
|
|
bool operator ==(double value) const;
|
2009-06-15 18:43:27 -04:00
|
|
|
bool operator ==(wxLongLong value) const;
|
|
|
|
bool operator ==(wxULongLong value) const;
|
2008-04-28 04:26:04 -04:00
|
|
|
bool operator ==(void* value) const;
|
|
|
|
bool operator ==(wxObject* value) const;
|
|
|
|
bool operator ==(const wxVariantList& value) const;
|
|
|
|
bool operator ==(const wxArrayString& value) const;
|
|
|
|
bool operator ==(const wxDateTime& value) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
2009-06-15 18:43:27 -04:00
|
|
|
Operators for implicit conversion, using appropriate getter member
|
|
|
|
function.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
double operator double() const;
|
2008-04-28 04:26:04 -04:00
|
|
|
long operator long() const;
|
2009-06-15 18:43:27 -04:00
|
|
|
wxLongLong operator wxLongLong() const;
|
|
|
|
wxULongLong operator wxULongLong() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Operator for implicit conversion to a pointer to a void, using
|
|
|
|
GetVoidPtr().
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* operator void*() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Operator for implicit conversion to a wxChar, using GetChar().
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
char operator wxChar() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Operator for implicit conversion to a pointer to a wxDateTime, using
|
|
|
|
GetDateTime().
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
void* operator wxDateTime() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Operator for implicit conversion to a string, using MakeString().
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxString operator wxString() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxVariantData
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
The wxVariantData class is used to implement a new type for wxVariant.
|
2008-03-08 08:52:38 -05:00
|
|
|
Derive from wxVariantData, and override the pure virtual functions.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
wxVariantData is @ref overview_refcount "reference counted", but you don't
|
2008-04-28 04:26:04 -04:00
|
|
|
normally have to care about this, as wxVariant manages the count
|
|
|
|
automatically. However, in case your application needs to take ownership of
|
|
|
|
wxVariantData, be aware that the object is created with a reference count
|
|
|
|
of 1, and passing it to wxVariant will not increase this. In other words,
|
|
|
|
IncRef() needs to be called only if you both take ownership of
|
|
|
|
wxVariantData and pass it to a wxVariant. Also note that the destructor is
|
|
|
|
protected, so you can never explicitly delete a wxVariantData instance.
|
|
|
|
Instead, DecRef() will delete the object automatically when the reference
|
|
|
|
count reaches zero.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxbase}
|
2008-04-28 04:26:04 -04:00
|
|
|
@category{data}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
@see wxVariant, wxGetVariantCast()
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-06-16 21:32:40 -04:00
|
|
|
class wxVariantData : public wxObjectRefData
|
2008-03-08 08:52:38 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Default constructor.
|
|
|
|
*/
|
|
|
|
wxVariantData();
|
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
This function can be overridden to clone the data. You must implement
|
|
|
|
this function in order for wxVariant::Unshare() to work for your data.
|
|
|
|
This function is implemented for all built-in data types.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual wxVariantData* Clone() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Decreases reference count. If the count reaches zero, the object is
|
|
|
|
automatically deleted.
|
2008-04-28 04:26:04 -04:00
|
|
|
|
|
|
|
@note The destructor of wxVariantData is protected, so delete cannot be
|
|
|
|
used as normal. Instead, DecRef() should be called.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void DecRef();
|
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Returns @true if this object is equal to @a data.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
virtual bool Eq(wxVariantData& data) const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
/**
|
|
|
|
Converts value to wxAny, if possible. Return @true if successful.
|
|
|
|
*/
|
|
|
|
virtual bool GetAny(wxAny* any) const;
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns the string type of the data.
|
|
|
|
*/
|
2008-10-13 09:24:43 -04:00
|
|
|
virtual wxString GetType() const = 0;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
If the data is a wxObject returns a pointer to the objects wxClassInfo
|
2008-04-28 04:26:04 -04:00
|
|
|
structure, if the data isn't a wxObject the method returns @NULL.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual wxClassInfo* GetValueClassInfo();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Increases reference count. Note that initially wxVariantData has
|
|
|
|
reference count of 1.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void IncRef();
|
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Reads the data from @a stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-28 10:29:36 -04:00
|
|
|
virtual bool Read(istream& stream);
|
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
/**
|
|
|
|
Reads the data from @a string.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual bool Read(wxString& string);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Writes the data to @a stream.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual bool Write(ostream& stream) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-04-28 04:26:04 -04:00
|
|
|
Writes the data to @a string.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual bool Write(wxString& string) const;
|
2008-03-08 08:52:38 -05:00
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-04-28 04:26:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Global functions/macros
|
|
|
|
// ============================================================================
|
|
|
|
|
2009-01-05 15:48:06 -05:00
|
|
|
/** @addtogroup group_funcmacro_rtti */
|
2008-04-28 04:26:04 -04:00
|
|
|
//@{
|
|
|
|
|
|
|
|
/**
|
|
|
|
This macro returns a pointer to the data stored in @a var (wxVariant) cast
|
|
|
|
to the type @a classname if the data is of this type (the check is done
|
|
|
|
during the run-time) or @NULL otherwise.
|
|
|
|
|
|
|
|
@header{wx/variant.h}
|
|
|
|
|
|
|
|
@see @ref overview_rtti, wxDynamicCast()
|
|
|
|
*/
|
|
|
|
#define wxGetVariantCast(var, classname)
|
|
|
|
|
|
|
|
//@}
|
|
|
|
|