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"
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* 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: To prevent addition of extra vtbl pointer to wxVariantData,
|
|
|
|
* we don't multiple-inherit from wxObjectRefData. Instead,
|
|
|
|
* we simply replicate the wxObject ref-counting scheme.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-10-13 07:45:34 -04:00
|
|
|
class WXDLLIMPEXP_BASE wxVariantData
|
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:
|
2007-10-13 07:45:34 -04:00
|
|
|
wxVariantData() : m_count(1) { }
|
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
|
|
|
|
2007-10-19 11:01:54 -04:00
|
|
|
// Implement this to make wxVariant::AllocExcusive work. Returns
|
|
|
|
// a copy of the data.
|
|
|
|
virtual wxVariantData* Clone() const { return NULL; }
|
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
void IncRef() { m_count++; }
|
|
|
|
void DecRef()
|
|
|
|
{
|
|
|
|
if ( --m_count == 0 )
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetRefCount() const { return m_count; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Protected dtor should make some incompatible code
|
|
|
|
// break more louder. That is, they should do data->DecRef()
|
|
|
|
// instead of delete data.
|
|
|
|
virtual ~wxVariantData() { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_count;
|
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);
|
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.
|
|
|
|
wxVariantData* GetData() const { return m_data; }
|
|
|
|
void SetData(wxVariantData* data) ;
|
|
|
|
|
|
|
|
// make a 'clone' of the object
|
|
|
|
void Ref(const wxVariant& clone);
|
|
|
|
|
|
|
|
// destroy a reference
|
|
|
|
void UnRef();
|
|
|
|
|
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
|
|
|
|
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
|
1999-03-12 14:12:49 -05:00
|
|
|
#ifdef HAVE_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 ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
wxVariant(const wxCharBuffer& val, const wxString& name = wxEmptyString);
|
|
|
|
wxVariant(const wxWCharBuffer& val, const wxString& name = wxEmptyString);
|
|
|
|
|
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>
|
|
|
|
wxVariant& operator=(const wxCharTypeBuffer<T>& value)
|
|
|
|
{ return *this = value.data(); }
|
|
|
|
|
2006-09-30 07:20:14 -04:00
|
|
|
inline operator wxString () const { return MakeString(); }
|
|
|
|
wxString GetString() const;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------
|
|
|
|
// 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
|
1998-09-12 13:31:48 -04:00
|
|
|
|
|
|
|
// Attributes
|
|
|
|
protected:
|
|
|
|
wxVariantData* m_data;
|
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
|
|
|
};
|
|
|
|
|
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
|
|
|
\
|
|
|
|
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;\
|
|
|
|
}
|
|
|
|
|
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_
|