1998-09-12 13:31:48 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2006-03-12 09:49:25 -05:00
|
|
|
// Name: wx/variant.h
|
1998-09-12 13:31:48 -04:00
|
|
|
// Purpose: wxVariant class, container for any type
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 10/09/98
|
|
|
|
// RCS-ID: $Id$
|
2005-05-04 14:57:50 -04:00
|
|
|
// Copyright: (c) Julian Smart
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-09-12 13:31:48 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_VARIANT_H_
|
|
|
|
#define _WX_VARIANT_H_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
2006-09-25 08:55:25 -04:00
|
|
|
|
|
|
|
#if wxUSE_VARIANT
|
|
|
|
|
1998-09-12 13:31:48 -04:00
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/string.h"
|
2003-07-19 11:05:08 -04:00
|
|
|
#include "wx/arrstr.h"
|
1998-09-12 13:31:48 -04:00
|
|
|
#include "wx/list.h"
|
2006-11-03 16:06:57 -05:00
|
|
|
#include "wx/cpp.h"
|
2009-06-15 18:43:27 -04:00
|
|
|
#include "wx/longlong.h"
|
1998-09-12 13:31:48 -04:00
|
|
|
|
2003-02-05 19:53:46 -05:00
|
|
|
#if wxUSE_DATETIME
|
|
|
|
#include "wx/datetime.h"
|
|
|
|
#endif // wxUSE_DATETIME
|
2001-06-10 13:04:00 -04:00
|
|
|
|
2003-01-25 19:12:12 -05:00
|
|
|
#include "wx/iosfwrap.h"
|
1998-09-12 13:31:48 -04:00
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
class wxAny;
|
|
|
|
|
1998-09-12 13:31:48 -04:00
|
|
|
/*
|
|
|
|
* wxVariantData stores the actual data in a wxVariant object,
|
|
|
|
* to allow it to store any type of data.
|
|
|
|
* Derive from this to provide custom data handling.
|
|
|
|
*
|
2006-09-30 07:20:14 -04:00
|
|
|
* NB: When you construct a wxVariantData, it will have refcount
|
|
|
|
* of one. Refcount will not be further increased when
|
|
|
|
* it is passed to wxVariant. This simulates old common
|
|
|
|
* scenario where wxVariant took ownership of wxVariantData
|
|
|
|
* passed to it.
|
|
|
|
* If you create wxVariantData for other reasons than passing
|
|
|
|
* it to wxVariant, technically you are not required to call
|
|
|
|
* DecRef() before deleting it.
|
|
|
|
*
|
1998-09-12 13:31:48 -04:00
|
|
|
* TODO: in order to replace wxPropertyValue, we would need
|
|
|
|
* to consider adding constructors that take pointers to C++ variables,
|
|
|
|
* or removing that functionality from the wxProperty library.
|
|
|
|
* Essentially wxPropertyValue takes on some of the wxValidator functionality
|
|
|
|
* by storing pointers and not just actual values, allowing update of C++ data
|
|
|
|
* to be handled automatically. Perhaps there's another way of doing this without
|
|
|
|
* overloading wxVariant with unnecessary functionality.
|
|
|
|
*/
|
|
|
|
|
2009-06-13 10:55:45 -04:00
|
|
|
class WXDLLIMPEXP_BASE wxVariantData : public wxObjectRefData
|
1998-09-12 13:31:48 -04:00
|
|
|
{
|
2006-09-30 07:20:14 -04:00
|
|
|
friend class wxVariant;
|
1998-09-12 13:31:48 -04:00
|
|
|
public:
|
2009-06-12 13:14:28 -04:00
|
|
|
wxVariantData() { }
|
1998-09-12 13:31:48 -04:00
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// Override these to provide common functionality
|
1998-09-12 13:31:48 -04:00
|
|
|
virtual bool Eq(wxVariantData& data) const = 0;
|
2006-10-02 03:09:20 -04:00
|
|
|
|
1999-06-27 06:39:38 -04:00
|
|
|
#if wxUSE_STD_IOSTREAM
|
2006-10-02 03:09:20 -04:00
|
|
|
virtual bool Write(wxSTD ostream& WXUNUSED(str)) const { return false; }
|
1999-06-27 06:39:38 -04:00
|
|
|
#endif
|
2006-10-02 03:09:20 -04:00
|
|
|
virtual bool Write(wxString& WXUNUSED(str)) const { return false; }
|
1999-06-27 06:39:38 -04:00
|
|
|
#if wxUSE_STD_IOSTREAM
|
2006-10-02 03:09:20 -04:00
|
|
|
virtual bool Read(wxSTD istream& WXUNUSED(str)) { return false; }
|
1999-06-27 06:39:38 -04:00
|
|
|
#endif
|
2006-10-02 03:09:20 -04:00
|
|
|
virtual bool Read(wxString& WXUNUSED(str)) { return false; }
|
1998-09-12 13:31:48 -04:00
|
|
|
// What type is it? Return a string name.
|
|
|
|
virtual wxString GetType() const = 0;
|
2003-06-02 17:17:28 -04:00
|
|
|
// If it based on wxObject return the ClassInfo.
|
|
|
|
virtual wxClassInfo* GetValueClassInfo() { return NULL; }
|
2006-09-30 07:20:14 -04:00
|
|
|
|
2009-06-13 10:55:45 -04:00
|
|
|
// Implement this to make wxVariant::UnShare work. Returns
|
2007-10-19 11:01:54 -04:00
|
|
|
// a copy of the data.
|
|
|
|
virtual wxVariantData* Clone() const { return NULL; }
|
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
#if wxUSE_ANY
|
|
|
|
// Converts value to wxAny, if possible. Return true if successful.
|
|
|
|
virtual bool GetAsAny(wxAny* WXUNUSED(any)) const { return false; }
|
|
|
|
#endif
|
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
protected:
|
|
|
|
// Protected dtor should make some incompatible code
|
|
|
|
// break more louder. That is, they should do data->DecRef()
|
|
|
|
// instead of delete data.
|
|
|
|
virtual ~wxVariantData() { }
|
1998-09-12 13:31:48 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* wxVariant can store any kind of data, but has some basic types
|
|
|
|
* built in.
|
|
|
|
*/
|
2007-10-19 11:01:54 -04:00
|
|
|
|
2007-10-13 07:57:48 -04:00
|
|
|
class WXDLLIMPEXP_FWD_BASE wxVariant;
|
|
|
|
|
|
|
|
WX_DECLARE_LIST_WITH_DECL(wxVariant, wxVariantList, class WXDLLIMPEXP_BASE);
|
1998-09-12 13:31:48 -04:00
|
|
|
|
2003-07-01 21:59:24 -04:00
|
|
|
class WXDLLIMPEXP_BASE wxVariant: public wxObject
|
1998-09-12 13:31:48 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxVariant();
|
2006-10-02 03:09:20 -04:00
|
|
|
|
1998-09-12 13:31:48 -04:00
|
|
|
wxVariant(const wxVariant& variant);
|
2006-09-30 07:20:14 -04:00
|
|
|
wxVariant(wxVariantData* data, const wxString& name = wxEmptyString);
|
2010-04-16 10:33:52 -04:00
|
|
|
#if wxUSE_ANY
|
|
|
|
wxVariant(const wxAny& any);
|
|
|
|
#endif
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~wxVariant();
|
1998-09-12 13:31:48 -04:00
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// generic assignment
|
1998-09-12 13:31:48 -04:00
|
|
|
void operator= (const wxVariant& variant);
|
|
|
|
|
|
|
|
// Assignment using data, e.g.
|
|
|
|
// myVariant = new wxStringVariantData("hello");
|
|
|
|
void operator= (wxVariantData* variantData);
|
2006-10-02 03:09:20 -04:00
|
|
|
|
1998-09-12 13:31:48 -04:00
|
|
|
bool operator== (const wxVariant& variant) const;
|
|
|
|
bool operator!= (const wxVariant& variant) const;
|
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// Sets/gets name
|
|
|
|
inline void SetName(const wxString& name) { m_name = name; }
|
|
|
|
inline const wxString& GetName() const { return m_name; }
|
|
|
|
|
|
|
|
// Tests whether there is data
|
2006-10-02 03:09:20 -04:00
|
|
|
bool IsNull() const;
|
2006-09-30 07:20:14 -04:00
|
|
|
|
|
|
|
// For compatibility with wxWidgets <= 2.6, this doesn't increase
|
|
|
|
// reference count.
|
2009-06-13 10:55:45 -04:00
|
|
|
wxVariantData* GetData() const
|
|
|
|
{
|
|
|
|
return (wxVariantData*) m_refData;
|
|
|
|
}
|
2006-09-30 07:20:14 -04:00
|
|
|
void SetData(wxVariantData* data) ;
|
|
|
|
|
|
|
|
// make a 'clone' of the object
|
2009-06-13 10:55:45 -04:00
|
|
|
void Ref(const wxVariant& clone) { wxObject::Ref(clone); }
|
2006-09-30 07:20:14 -04:00
|
|
|
|
2007-10-19 11:01:54 -04:00
|
|
|
// ensure that the data is exclusive to this variant, and not shared
|
|
|
|
bool Unshare();
|
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// Make NULL (i.e. delete the data)
|
|
|
|
void MakeNull();
|
2006-10-02 03:09:20 -04:00
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// Delete data and name
|
|
|
|
void Clear();
|
2006-10-02 03:09:20 -04:00
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// Returns a string representing the type of the variant,
|
|
|
|
// e.g. "string", "bool", "stringlist", "list", "double", "long"
|
|
|
|
wxString GetType() const;
|
|
|
|
|
|
|
|
bool IsType(const wxString& type) const;
|
|
|
|
bool IsValueKindOf(const wxClassInfo* type) const;
|
|
|
|
|
2006-10-02 03:09:20 -04:00
|
|
|
// write contents to a string (e.g. for debugging)
|
2006-09-30 07:20:14 -04:00
|
|
|
wxString MakeString() const;
|
2006-10-02 03:09:20 -04:00
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
#if wxUSE_ANY
|
|
|
|
wxAny GetAny() const;
|
|
|
|
#endif
|
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// double
|
|
|
|
wxVariant(double val, const wxString& name = wxEmptyString);
|
1998-09-12 13:31:48 -04:00
|
|
|
bool operator== (double value) const;
|
|
|
|
bool operator!= (double value) const;
|
|
|
|
void operator= (double value) ;
|
2006-09-30 07:20:14 -04:00
|
|
|
inline operator double () const { return GetDouble(); }
|
|
|
|
inline double GetReal() const { return GetDouble(); }
|
|
|
|
double GetDouble() const;
|
2006-10-02 03:09:20 -04:00
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// long
|
|
|
|
wxVariant(long val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(int val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(short val, const wxString& name = wxEmptyString);
|
1998-09-12 13:31:48 -04:00
|
|
|
bool operator== (long value) const;
|
|
|
|
bool operator!= (long value) const;
|
|
|
|
void operator= (long value) ;
|
2006-09-30 07:20:14 -04:00
|
|
|
inline operator long () const { return GetLong(); }
|
|
|
|
inline long GetInteger() const { return GetLong(); }
|
|
|
|
long GetLong() const;
|
2006-10-02 03:09:20 -04:00
|
|
|
|
|
|
|
// bool
|
2006-09-30 07:20:14 -04:00
|
|
|
wxVariant(bool val, const wxString& name = wxEmptyString);
|
1998-09-12 13:31:48 -04:00
|
|
|
bool operator== (bool value) const;
|
|
|
|
bool operator!= (bool value) const;
|
|
|
|
void operator= (bool value) ;
|
2006-09-30 07:20:14 -04:00
|
|
|
inline operator bool () const { return GetBool(); }
|
|
|
|
bool GetBool() const ;
|
|
|
|
|
|
|
|
// wxDateTime
|
|
|
|
#if wxUSE_DATETIME
|
2006-10-02 03:09:20 -04:00
|
|
|
wxVariant(const wxDateTime& val, const wxString& name = wxEmptyString);
|
2006-09-30 07:20:14 -04:00
|
|
|
bool operator== (const wxDateTime& value) const;
|
|
|
|
bool operator!= (const wxDateTime& value) const;
|
|
|
|
void operator= (const wxDateTime& value) ;
|
|
|
|
inline operator wxDateTime () const { return GetDateTime(); }
|
|
|
|
wxDateTime GetDateTime() const;
|
1999-03-12 14:12:49 -05:00
|
|
|
#endif
|
2006-09-30 07:20:14 -04:00
|
|
|
|
|
|
|
// wxString
|
|
|
|
wxVariant(const wxString& val, const wxString& name = wxEmptyString);
|
2007-07-06 19:02:16 -04:00
|
|
|
// these overloads are necessary to prevent the compiler from using bool
|
|
|
|
// version instead of wxString one:
|
|
|
|
wxVariant(const char* val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(const wchar_t* val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(const wxCStrData& val, const wxString& name = wxEmptyString);
|
2009-03-27 11:33:55 -04:00
|
|
|
wxVariant(const wxScopedCharBuffer& val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(const wxScopedWCharBuffer& val, const wxString& name = wxEmptyString);
|
2007-07-06 19:02:16 -04:00
|
|
|
|
1998-09-12 13:31:48 -04:00
|
|
|
bool operator== (const wxString& value) const;
|
|
|
|
bool operator!= (const wxString& value) const;
|
2007-07-06 19:02:16 -04:00
|
|
|
wxVariant& operator=(const wxString& value);
|
|
|
|
// these overloads are necessary to prevent the compiler from using bool
|
|
|
|
// version instead of wxString one:
|
|
|
|
wxVariant& operator=(const char* value)
|
|
|
|
{ return *this = wxString(value); }
|
|
|
|
wxVariant& operator=(const wchar_t* value)
|
|
|
|
{ return *this = wxString(value); }
|
|
|
|
wxVariant& operator=(const wxCStrData& value)
|
|
|
|
{ return *this = value.AsString(); }
|
|
|
|
template<typename T>
|
2009-03-27 11:33:55 -04:00
|
|
|
wxVariant& operator=(const wxScopedCharTypeBuffer<T>& value)
|
2007-07-06 19:02:16 -04:00
|
|
|
{ return *this = value.data(); }
|
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
inline operator wxString () const { return MakeString(); }
|
|
|
|
wxString GetString() const;
|
|
|
|
|
2010-07-05 10:23:21 -04:00
|
|
|
#if wxUSE_STD_STRING
|
|
|
|
wxVariant(const std::string& val, const wxString& name = wxEmptyString);
|
|
|
|
bool operator==(const std::string& value) const
|
|
|
|
{ return operator==(wxString(value)); }
|
|
|
|
bool operator!=(const std::string& value) const
|
|
|
|
{ return operator!=(wxString(value)); }
|
|
|
|
wxVariant& operator=(const std::string& value)
|
|
|
|
{ return operator=(wxString(value)); }
|
|
|
|
operator std::string() const { return (operator wxString()).ToStdString(); }
|
|
|
|
|
|
|
|
wxVariant(const wxStdWideString& val, const wxString& name = wxEmptyString);
|
|
|
|
bool operator==(const wxStdWideString& value) const
|
|
|
|
{ return operator==(wxString(value)); }
|
|
|
|
bool operator!=(const wxStdWideString& value) const
|
|
|
|
{ return operator!=(wxString(value)); }
|
|
|
|
wxVariant& operator=(const wxStdWideString& value)
|
|
|
|
{ return operator=(wxString(value)); }
|
|
|
|
operator wxStdWideString() const { return (operator wxString()).ToStdWstring(); }
|
|
|
|
#endif // wxUSE_STD_STRING
|
|
|
|
|
2007-07-06 19:02:16 -04:00
|
|
|
// wxUniChar
|
|
|
|
wxVariant(const wxUniChar& val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(const wxUniCharRef& val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(char val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(wchar_t val, const wxString& name = wxEmptyString);
|
|
|
|
bool operator==(const wxUniChar& value) const;
|
|
|
|
bool operator==(const wxUniCharRef& value) const { return *this == wxUniChar(value); }
|
|
|
|
bool operator==(char value) const { return *this == wxUniChar(value); }
|
|
|
|
bool operator==(wchar_t value) const { return *this == wxUniChar(value); }
|
|
|
|
bool operator!=(const wxUniChar& value) const { return !(*this == value); }
|
|
|
|
bool operator!=(const wxUniCharRef& value) const { return !(*this == value); }
|
|
|
|
bool operator!=(char value) const { return !(*this == value); }
|
|
|
|
bool operator!=(wchar_t value) const { return !(*this == value); }
|
|
|
|
wxVariant& operator=(const wxUniChar& value);
|
|
|
|
wxVariant& operator=(const wxUniCharRef& value) { return *this = wxUniChar(value); }
|
|
|
|
wxVariant& operator=(char value) { return *this = wxUniChar(value); }
|
|
|
|
wxVariant& operator=(wchar_t value) { return *this = wxUniChar(value); }
|
|
|
|
operator wxUniChar() const { return GetChar(); }
|
|
|
|
operator char() const { return GetChar(); }
|
|
|
|
operator wchar_t() const { return GetChar(); }
|
|
|
|
wxUniChar GetChar() const;
|
2006-10-02 03:09:20 -04:00
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
// wxArrayString
|
|
|
|
wxVariant(const wxArrayString& val, const wxString& name = wxEmptyString);
|
|
|
|
bool operator== (const wxArrayString& value) const;
|
|
|
|
bool operator!= (const wxArrayString& value) const;
|
|
|
|
void operator= (const wxArrayString& value);
|
2007-07-06 19:02:16 -04:00
|
|
|
operator wxArrayString () const { return GetArrayString(); }
|
2006-09-30 07:20:14 -04:00
|
|
|
wxArrayString GetArrayString() const;
|
|
|
|
|
|
|
|
// void*
|
|
|
|
wxVariant(void* ptr, const wxString& name = wxEmptyString);
|
|
|
|
bool operator== (void* value) const;
|
|
|
|
bool operator!= (void* value) const;
|
|
|
|
void operator= (void* value);
|
2007-07-06 19:02:16 -04:00
|
|
|
operator void* () const { return GetVoidPtr(); }
|
2006-09-30 07:20:14 -04:00
|
|
|
void* GetVoidPtr() const;
|
|
|
|
|
|
|
|
// wxObject*
|
|
|
|
wxVariant(wxObject* ptr, const wxString& name = wxEmptyString);
|
|
|
|
bool operator== (wxObject* value) const;
|
|
|
|
bool operator!= (wxObject* value) const;
|
|
|
|
void operator= (wxObject* value);
|
|
|
|
wxObject* GetWxObjectPtr() const;
|
|
|
|
|
2009-06-15 18:43:27 -04:00
|
|
|
#if wxUSE_LONGLONG
|
|
|
|
// wxLongLong
|
|
|
|
wxVariant(wxLongLong, const wxString& name = wxEmptyString);
|
|
|
|
bool operator==(wxLongLong value) const;
|
|
|
|
bool operator!=(wxLongLong value) const;
|
|
|
|
void operator=(wxLongLong value);
|
|
|
|
operator wxLongLong() const { return GetLongLong(); }
|
|
|
|
wxLongLong GetLongLong() const;
|
|
|
|
|
|
|
|
// wxULongLong
|
|
|
|
wxVariant(wxULongLong, const wxString& name = wxEmptyString);
|
|
|
|
bool operator==(wxULongLong value) const;
|
|
|
|
bool operator!=(wxULongLong value) const;
|
|
|
|
void operator=(wxULongLong value);
|
|
|
|
operator wxULongLong() const { return GetULongLong(); }
|
|
|
|
wxULongLong GetULongLong() const;
|
|
|
|
#endif
|
2006-09-30 07:20:14 -04:00
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// list operations
|
|
|
|
// ------------------------------
|
|
|
|
|
2007-10-13 08:11:51 -04:00
|
|
|
wxVariant(const wxVariantList& val, const wxString& name = wxEmptyString); // List of variants
|
|
|
|
bool operator== (const wxVariantList& value) const;
|
|
|
|
bool operator!= (const wxVariantList& value) const;
|
|
|
|
void operator= (const wxVariantList& value) ;
|
1998-09-12 13:31:48 -04:00
|
|
|
// Treat a list variant as an array
|
|
|
|
wxVariant operator[] (size_t idx) const;
|
|
|
|
wxVariant& operator[] (size_t idx) ;
|
2007-10-13 08:11:51 -04:00
|
|
|
wxVariantList& GetList() const ;
|
1998-09-12 13:31:48 -04:00
|
|
|
|
|
|
|
// Return the number of elements in a list
|
2006-03-12 09:49:25 -05:00
|
|
|
size_t GetCount() const;
|
2006-10-02 03:09:20 -04:00
|
|
|
|
1998-09-12 13:31:48 -04:00
|
|
|
// Make empty list
|
|
|
|
void NullList();
|
|
|
|
|
|
|
|
// Append to list
|
|
|
|
void Append(const wxVariant& value);
|
|
|
|
|
|
|
|
// Insert at front of list
|
|
|
|
void Insert(const wxVariant& value);
|
|
|
|
|
2004-09-24 10:32:35 -04:00
|
|
|
// Returns true if the variant is a member of the list
|
1998-09-12 13:31:48 -04:00
|
|
|
bool Member(const wxVariant& value) const;
|
|
|
|
|
|
|
|
// Deletes the nth element of the list
|
2006-03-12 09:49:25 -05:00
|
|
|
bool Delete(size_t item);
|
1998-09-12 13:31:48 -04:00
|
|
|
|
|
|
|
// Clear list
|
|
|
|
void ClearList();
|
|
|
|
|
2002-08-01 16:00:55 -04:00
|
|
|
public:
|
2006-09-30 07:20:14 -04:00
|
|
|
// Type conversion
|
1998-09-12 13:31:48 -04:00
|
|
|
bool Convert(long* value) const;
|
|
|
|
bool Convert(bool* value) const;
|
|
|
|
bool Convert(double* value) const;
|
|
|
|
bool Convert(wxString* value) const;
|
2007-07-06 19:02:16 -04:00
|
|
|
bool Convert(wxUniChar* value) const;
|
|
|
|
bool Convert(char* value) const;
|
|
|
|
bool Convert(wchar_t* value) const;
|
2003-02-05 19:53:46 -05:00
|
|
|
#if wxUSE_DATETIME
|
2001-06-10 13:04:00 -04:00
|
|
|
bool Convert(wxDateTime* value) const;
|
2003-02-05 19:53:46 -05:00
|
|
|
#endif // wxUSE_DATETIME
|
2009-06-15 18:43:27 -04:00
|
|
|
#if wxUSE_LONGLONG
|
|
|
|
bool Convert(wxLongLong* value) const;
|
|
|
|
bool Convert(wxULongLong* value) const;
|
2010-07-25 05:30:50 -04:00
|
|
|
#ifdef wxLongLong_t
|
|
|
|
bool Convert(wxLongLong_t* value) const
|
|
|
|
{
|
|
|
|
wxLongLong temp;
|
|
|
|
if ( !Convert(&temp) )
|
|
|
|
return false;
|
|
|
|
*value = temp.GetValue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Convert(wxULongLong_t* value) const
|
|
|
|
{
|
|
|
|
wxULongLong temp;
|
|
|
|
if ( !Convert(&temp) )
|
|
|
|
return false;
|
|
|
|
*value = temp.GetValue();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif // wxLongLong_t
|
2009-06-15 18:43:27 -04:00
|
|
|
#endif // wxUSE_LONGLONG
|
1998-09-12 13:31:48 -04:00
|
|
|
|
|
|
|
// Attributes
|
|
|
|
protected:
|
2009-06-13 10:55:45 -04:00
|
|
|
virtual wxObjectRefData *CreateRefData() const;
|
|
|
|
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
|
|
|
|
|
1998-11-29 16:20:12 -05:00
|
|
|
wxString m_name;
|
2006-10-02 03:09:20 -04:00
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxVariant)
|
1998-09-12 13:31:48 -04:00
|
|
|
};
|
|
|
|
|
2010-04-16 10:33:52 -04:00
|
|
|
|
|
|
|
//
|
|
|
|
// wxVariant <-> wxAny conversion code
|
|
|
|
//
|
|
|
|
#if wxUSE_ANY
|
|
|
|
|
|
|
|
#include "wx/any.h"
|
|
|
|
|
|
|
|
// In order to convert wxAny to wxVariant, we need to be able to associate
|
|
|
|
// wxAnyValueType with a wxVariantData factory function.
|
|
|
|
typedef wxVariantData* (*wxVariantDataFactory)(const wxAny& any);
|
|
|
|
|
|
|
|
// Actual Any-to-Variant registration must be postponed to a time when all
|
|
|
|
// global variables have been initialized. Hence this arrangement.
|
|
|
|
// wxAnyToVariantRegistration instances are kept in global scope and
|
|
|
|
// wxAnyValueTypeGlobals in any.cpp will use their data when the time is
|
|
|
|
// right.
|
|
|
|
class WXDLLIMPEXP_BASE wxAnyToVariantRegistration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxAnyToVariantRegistration(wxVariantDataFactory factory);
|
2010-04-17 08:34:32 -04:00
|
|
|
virtual ~wxAnyToVariantRegistration();
|
2010-04-16 10:33:52 -04:00
|
|
|
|
|
|
|
virtual wxAnyValueType* GetAssociatedType() = 0;
|
|
|
|
wxVariantDataFactory GetFactory() const { return m_factory; }
|
|
|
|
private:
|
|
|
|
wxVariantDataFactory m_factory;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class wxAnyToVariantRegistrationImpl : public wxAnyToVariantRegistration
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxAnyToVariantRegistrationImpl(wxVariantDataFactory factory)
|
|
|
|
: wxAnyToVariantRegistration(factory)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual wxAnyValueType* GetAssociatedType()
|
|
|
|
{
|
|
|
|
return wxAnyValueTypeImpl<T>::GetInstance();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DECLARE_WXANY_CONVERSION() \
|
|
|
|
virtual bool GetAsAny(wxAny* any) const; \
|
|
|
|
static wxVariantData* VariantDataFactory(const wxAny& any);
|
|
|
|
|
2010-04-22 09:51:38 -04:00
|
|
|
#define _REGISTER_WXANY_CONVERSION(T, CLASSNAME, FUNC) \
|
2010-04-16 10:33:52 -04:00
|
|
|
static wxAnyToVariantRegistrationImpl<T> \
|
|
|
|
gs_##CLASSNAME##AnyToVariantRegistration = \
|
2010-04-22 09:51:38 -04:00
|
|
|
wxAnyToVariantRegistrationImpl<T>(&FUNC);
|
|
|
|
|
|
|
|
#define REGISTER_WXANY_CONVERSION(T, CLASSNAME) \
|
|
|
|
_REGISTER_WXANY_CONVERSION(T, CLASSNAME, CLASSNAME::VariantDataFactory)
|
2010-04-16 10:33:52 -04:00
|
|
|
|
|
|
|
#define IMPLEMENT_TRIVIAL_WXANY_CONVERSION(T, CLASSNAME) \
|
|
|
|
bool CLASSNAME::GetAsAny(wxAny* any) const \
|
|
|
|
{ \
|
|
|
|
*any = m_value; \
|
|
|
|
return true; \
|
|
|
|
} \
|
|
|
|
wxVariantData* CLASSNAME::VariantDataFactory(const wxAny& any) \
|
|
|
|
{ \
|
|
|
|
return new CLASSNAME(wxANY_AS(any, T)); \
|
|
|
|
} \
|
|
|
|
REGISTER_WXANY_CONVERSION(T, CLASSNAME)
|
|
|
|
|
|
|
|
// This is needed for wxVariantList conversion
|
|
|
|
WX_DECLARE_LIST_WITH_DECL(wxAny, wxAnyList, class WXDLLIMPEXP_BASE);
|
|
|
|
|
|
|
|
#else // if !wxUSE_ANY
|
|
|
|
|
|
|
|
#define DECLARE_WXANY_CONVERSION()
|
|
|
|
#define REGISTER_WXANY_CONVERSION(T, CLASSNAME)
|
|
|
|
#define IMPLEMENT_TRIVIAL_WXANY_CONVERSION(T, CLASSNAME)
|
|
|
|
|
|
|
|
#endif // wxUSE_ANY/!wxUSE_ANY
|
|
|
|
|
|
|
|
|
2006-09-30 11:37:52 -04:00
|
|
|
#define DECLARE_VARIANT_OBJECT(classname) \
|
2006-11-03 16:06:57 -05:00
|
|
|
DECLARE_VARIANT_OBJECT_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
|
2006-10-02 03:09:20 -04:00
|
|
|
|
2006-09-30 16:45:15 -04:00
|
|
|
#define DECLARE_VARIANT_OBJECT_EXPORTED(classname,expdecl) \
|
2006-10-02 05:00:12 -04:00
|
|
|
expdecl classname& operator << ( classname &object, const wxVariant &variant ); \
|
|
|
|
expdecl wxVariant& operator << ( wxVariant &variant, const classname &object );
|
2006-09-30 11:37:52 -04:00
|
|
|
|
|
|
|
#define IMPLEMENT_VARIANT_OBJECT(classname) \
|
2006-11-03 16:06:57 -05:00
|
|
|
IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
|
2006-09-30 16:45:15 -04:00
|
|
|
|
2006-10-30 14:26:48 -05:00
|
|
|
#define IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,expdecl) \
|
2006-09-30 11:37:52 -04:00
|
|
|
class classname##VariantData: public wxVariantData \
|
|
|
|
{ \
|
|
|
|
public:\
|
|
|
|
classname##VariantData() {} \
|
|
|
|
classname##VariantData( const classname &value ) { m_value = value; } \
|
|
|
|
\
|
|
|
|
classname &GetValue() { return m_value; } \
|
|
|
|
\
|
|
|
|
virtual bool Eq(wxVariantData& data) const; \
|
|
|
|
\
|
|
|
|
virtual wxString GetType() const; \
|
|
|
|
virtual wxClassInfo* GetValueClassInfo(); \
|
2007-10-19 11:01:54 -04:00
|
|
|
\
|
|
|
|
virtual wxVariantData* Clone() const { return new classname##VariantData(m_value); } \
|
2006-09-30 11:37:52 -04:00
|
|
|
\
|
2010-04-16 10:33:52 -04:00
|
|
|
DECLARE_WXANY_CONVERSION() \
|
2006-09-30 11:37:52 -04:00
|
|
|
protected:\
|
|
|
|
classname m_value; \
|
|
|
|
};\
|
|
|
|
\
|
|
|
|
wxString classname##VariantData::GetType() const\
|
|
|
|
{\
|
|
|
|
return m_value.GetClassInfo()->GetClassName();\
|
|
|
|
}\
|
|
|
|
\
|
|
|
|
wxClassInfo* classname##VariantData::GetValueClassInfo()\
|
|
|
|
{\
|
|
|
|
return m_value.GetClassInfo();\
|
|
|
|
}\
|
|
|
|
\
|
2006-10-02 05:00:12 -04:00
|
|
|
expdecl classname& operator << ( classname &value, const wxVariant &variant )\
|
2006-09-30 11:37:52 -04:00
|
|
|
{\
|
2007-10-13 07:45:34 -04:00
|
|
|
wxASSERT( variant.GetType() == #classname );\
|
2006-09-30 11:37:52 -04:00
|
|
|
\
|
|
|
|
classname##VariantData *data = (classname##VariantData*) variant.GetData();\
|
|
|
|
value = data->GetValue();\
|
|
|
|
return value;\
|
|
|
|
}\
|
|
|
|
\
|
2006-10-02 05:00:12 -04:00
|
|
|
expdecl wxVariant& operator << ( wxVariant &variant, const classname &value )\
|
2006-09-30 11:37:52 -04:00
|
|
|
{\
|
|
|
|
classname##VariantData *data = new classname##VariantData( value );\
|
|
|
|
variant.SetData( data );\
|
|
|
|
return variant;\
|
2010-04-16 10:33:52 -04:00
|
|
|
} \
|
|
|
|
IMPLEMENT_TRIVIAL_WXANY_CONVERSION(classname, classname##VariantData)
|
2006-09-30 11:37:52 -04:00
|
|
|
|
2006-11-03 16:25:59 -05:00
|
|
|
// implements a wxVariantData-derived class using for the Eq() method the
|
|
|
|
// operator== which must have been provided by "classname"
|
2006-10-30 14:26:48 -05:00
|
|
|
#define IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname,expdecl) \
|
2006-11-03 16:37:08 -05:00
|
|
|
IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
|
2006-10-30 14:26:48 -05:00
|
|
|
\
|
|
|
|
bool classname##VariantData::Eq(wxVariantData& data) const \
|
|
|
|
{\
|
2007-10-13 07:45:34 -04:00
|
|
|
wxASSERT( GetType() == data.GetType() );\
|
2006-10-30 14:26:48 -05:00
|
|
|
\
|
|
|
|
classname##VariantData & otherData = (classname##VariantData &) data;\
|
|
|
|
\
|
|
|
|
return otherData.m_value == m_value;\
|
|
|
|
}\
|
|
|
|
|
|
|
|
|
|
|
|
// implements a wxVariantData-derived class using for the Eq() method a shallow
|
2006-10-30 17:03:53 -05:00
|
|
|
// comparison (through wxObject::IsSameAs function)
|
2006-11-03 16:25:59 -05:00
|
|
|
#define IMPLEMENT_VARIANT_OBJECT_SHALLOWCMP(classname) \
|
|
|
|
IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(classname, wxEMPTY_PARAMETER_VALUE)
|
2006-10-30 14:26:48 -05:00
|
|
|
#define IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(classname,expdecl) \
|
2006-11-03 16:37:08 -05:00
|
|
|
IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
|
2006-10-30 14:26:48 -05:00
|
|
|
\
|
|
|
|
bool classname##VariantData::Eq(wxVariantData& data) const \
|
|
|
|
{\
|
2007-10-13 07:45:34 -04:00
|
|
|
wxASSERT( GetType() == data.GetType() );\
|
2006-10-30 14:26:48 -05:00
|
|
|
\
|
|
|
|
classname##VariantData & otherData = (classname##VariantData &) data;\
|
|
|
|
\
|
2006-10-30 17:03:53 -05:00
|
|
|
return (otherData.m_value.IsSameAs(m_value));\
|
2006-10-30 14:26:48 -05:00
|
|
|
}\
|
|
|
|
|
|
|
|
|
2006-09-30 11:37:52 -04:00
|
|
|
// Since we want type safety wxVariant we need to fetch and dynamic_cast
|
|
|
|
// in a seemingly safe way so the compiler can check, so we define
|
|
|
|
// a dynamic_cast /wxDynamicCast analogue.
|
2003-06-02 17:17:28 -04:00
|
|
|
|
|
|
|
#define wxGetVariantCast(var,classname) \
|
2004-09-24 10:32:35 -04:00
|
|
|
((classname*)(var.IsValueKindOf(&classname::ms_classInfo) ?\
|
|
|
|
var.GetWxObjectPtr() : NULL));
|
2003-06-02 17:17:28 -04:00
|
|
|
|
2007-10-19 11:01:54 -04:00
|
|
|
// Replacement for using wxDynamicCast on a wxVariantData object
|
|
|
|
#define wxDynamicCastVariantData(data, classname) dynamic_cast<classname*>(data)
|
|
|
|
|
2003-07-01 21:59:24 -04:00
|
|
|
extern wxVariant WXDLLIMPEXP_BASE wxNullVariant;
|
1998-11-29 16:20:12 -05:00
|
|
|
|
2006-09-25 08:55:25 -04:00
|
|
|
#endif // wxUSE_VARIANT
|
|
|
|
|
|
|
|
#endif // _WX_VARIANT_H_
|