- virtual ~wxxVariantData() {}
-
- // return a heap allocated duplicate
- virtual wxxVariantData* Clone() const = 0 ;
-
- // returns the type info of the contentc
- virtual const wxTypeInfo* GetTypeInfo() const = 0 ;
-
- // write the value into a string
- virtual void Write( wxString &s ) const = 0 ;
-
- // read the value from a string
- virtual void Read( const wxString &s) = 0 ;
-} ;
-
-template<typename T> class WXDLLIMPEXP_BASE wxxVariantDataT : public wxxVariantData
-{
-public:
- wxxVariantDataT(const T& d) : m_data(d) {}
- virtual ~wxxVariantDataT() {}
-
- // get a ref to the stored data
- T & Get() { return m_data; }
-
- // get a const ref to the stored data
- const T & Get() const { return m_data; }
-
- // set the data
- void Set(const T& d) { m_data = d; }
-
- // return a heap allocated duplicate
- virtual wxxVariantData* Clone() const { return new wxxVariantDataT<T>( Get() ) ; }
-
- // returns the type info of the contentc
- virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; }
-
- // write the value into a string
- virtual void Write( wxString &s ) const { wxStringWriteValue( s , m_data ) ; }
-
- // read the value from a string
- virtual void Read( const wxString &s) { wxStringReadValue( s , m_data ) ; }
-
-private:
- T m_data;
-};
-
-class WXDLLIMPEXP_BASE wxxVariant
-{
-public :
- wxxVariant() { m_data = NULL ; }
- wxxVariant( wxxVariantData* data , const wxString& name = wxT("") ) : m_data(data) , m_name(name) {}
- wxxVariant( const wxxVariant &d ) { if ( d.m_data ) m_data = d.m_data->Clone() ; else m_data = NULL ; m_name = d.m_name ; }
-
- template<typename T> wxxVariant( T data , const wxString& name = wxT("") ) :
- m_data(new wxxVariantDataT<T>(data) ), m_name(name) {}
- ~wxxVariant() { delete m_data ; }
-
- // get a ref to the stored data
- template<typename T> T& Get()
- {
- wxxVariantDataT<T> *dataptr = dynamic_cast<wxxVariantDataT<T>*> (m_data) ;
- wxASSERT_MSG( dataptr , "Cast not possible" ) ;
- return dataptr->Get() ;
- }
-
- // get a ref to the stored data
- template<typename T> const T& Get() const
- {
- const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
- wxASSERT_MSG( dataptr , "Cast not possible" ) ;
- return dataptr->Get() ;
- }
-
- // stores the data
- template<typename T> void Set(const T& data) const
- {
- delete m_data ;
- m_data = new wxxVariantDataT<T>(data) ;
- }
-
- wxxVariant& operator=(const wxxVariant &d)
- {
- m_data = d.m_data->Clone() ;
- m_name = d.m_name ;
- return *this ;
- }
-
- // gets the stored data casted to a wxObject* , returning NULL if cast is not possible
- wxObject* GetAsObject() ;
-
- // get the typeinfo of the stored object
- const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
-
- // write the value into a string
- void Write( wxString &s ) const { m_data->Write( s ) ; }
-
- // read the value from a string
- void Read( const wxString &s) { m_data->Read( s ) ; }
-
- // returns this value as string
- wxString GetAsString() const
- {
- wxString s ;
- Write( s ) ;
- return s ;
- }
-
- void SetFromString( const wxString &s)
- {
- Read( s ) ;
- }
-private :
- wxxVariantData* m_data ;
- wxString m_name ;
-} ;
-
-#include <wx/dynarray.h>
-
-WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant, wxxVariantArray, class WXDLLIMPEXP_BASE);
-
-// ----------------------------------------------------------------------------
-// Property Support
-//
-// wxPropertyInfo is used to inquire of the property by name. It doesn't
-// provide access to the property, only information about it. If you
-// want access, look at wxPropertyAccessor.
-// ----------------------------------------------------------------------------
-
-class WXDLLIMPEXP_BASE wxPropertyAccessor
-{
-public :
-#if WX_XTI_TEMPLATE_FIX
- class SetByRef ;
- class SetByRefRetBool ;
- class SetRetBool ;
- class SetAndGetByRef ;
- class SetAndGetByRefRetBool ;
- class GetByRef ;
-#endif
- wxPropertyAccessor() { m_setterName = NULL ; m_getterName = NULL ; m_adderName = NULL ;}
- virtual ~wxPropertyAccessor() {}
-
- // Setting a simple property (non-collection)
- virtual void SetProperty(wxObject *object, const wxxVariant &value) const = 0 ;
-
- // Getting a simple property (non-collection)
- virtual wxxVariant GetProperty(const wxObject *object) const = 0 ;
-
- // Adding an element to a collection property
- virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const
- { wxASSERT_MSG(0,wxT("Collection Operation called on non Collection Property")) ; }
-
- // Getting a collection property
- virtual wxxVariantArray GetPropertyCollection( const wxObject *obj) const
- { wxASSERT_MSG(0,wxT("Collection Operation called on non Collection Property")) ; return wxxVariantArray() ; }
-
- virtual bool HasSetter() const = 0 ;
- virtual bool HasGetter() const = 0 ;
- virtual bool HasAdder() const = 0 ;
-
- const wxChar * GetGetterName() const { return m_setterName ; }
- const wxChar * GetSetterName() const { return m_getterName ; }
- const wxChar * GetAdderName() const { return m_adderName ; }
-
- virtual wxxVariant ReadValue( const wxString &value ) const = 0 ;
- virtual void WriteValue( wxString& value , const wxObject *o ) const = 0 ;
-protected :
- const wxChar *m_setterName ;
- const wxChar *m_getterName ;
- const wxChar *m_adderName ;
-};
-
-class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
-{
-public :
- wxGenericPropertyAccessor( const wxChar* propertyName ) ;
- ~wxGenericPropertyAccessor() ;
- virtual void SetProperty(wxObject *object, const wxxVariant &value) const ;
- virtual wxxVariant GetProperty(const wxObject *object) const ;
-
- virtual bool HasSetter() const { return true ; }
- virtual bool HasGetter() const { return true ; }
- virtual bool HasAdder() const { return false ; }
-
- virtual wxxVariant ReadValue( const wxString &value ) const ;
- virtual void WriteValue( wxString& value , const wxObject *o ) const ;
-private :
- struct wxGenericPropertyAccessorInternal ;
- wxGenericPropertyAccessorInternal* m_data ;
-} ;
-
-template<class Klass, typename T>
-class WXDLLIMPEXP_BASE wxPropertyAccessorT : public wxPropertyAccessor
-{
-public:
-
- typedef void (Klass::*setter_t)(T value);
- typedef bool (Klass::*setter_bool_t)(T value);
- typedef void (Klass::*setter_ref_t)(const T& value);
- typedef bool (Klass::*setter_ref_bool_t)(const T& value);
- typedef T (Klass::*getter_t)() const;
- typedef const T& (Klass::*getter_ref_t)() const;
-
- wxPropertyAccessorT(setter_t setter, getter_t getter, const wxChar *s, const wxChar *g)
- : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(setter), m_setter_ref(NULL), m_getter(getter) ,m_getter_ref(NULL) {m_setterName = s;m_getterName=g ;}
-
- wxPropertyAccessorT( getter_t getter, const wxChar *g)
- : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) ,m_getter_ref(NULL) {m_setterName = "";m_getterName=g ;}
-
- wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetRetBool*,) setter_bool_t setter, getter_t getter, const wxChar *s, const wxChar *g)
- : m_setter_bool( setter ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;}
-
- wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetByRef*,) setter_ref_t setter, getter_t getter, const wxChar *s, const wxChar *g)
- : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(setter), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;}
-
- wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetByRefRetBool*,) setter_ref_bool_t setter, getter_t getter, const wxChar *s, const wxChar *g)
- : m_setter_bool( NULL ) , m_setter_ref_bool( setter ) , m_setter(NULL), m_setter_ref(NULL), m_getter(getter) , m_getter_ref(NULL){m_setterName = s;m_getterName=g ;}
-
- wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetAndGetByRef*,) setter_ref_t setter, getter_ref_t getter, const wxChar *s, const wxChar *g)
- : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter_ref(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;}
-
- wxPropertyAccessorT(WX_XTI_PARAM_FIX(SetAndGetByRefRetBool*,) setter_ref_bool_t setter, getter_ref_t getter, const wxChar *s, const wxChar *g)
- : m_setter_bool( NULL ) , m_setter_ref_bool( setter ) , m_setter(NULL), m_setter_ref(NULL), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;}
-
- wxPropertyAccessorT(WX_XTI_PARAM_FIX(GetByRef*,) setter_t setter, getter_ref_t getter, const wxChar *s, const wxChar *g)
- : m_setter_bool( NULL ) , m_setter_ref_bool( NULL ) , m_setter(NULL), m_setter(setter), m_getter(NULL) , m_getter_ref(getter){m_setterName = s;m_getterName=g ;}
-
- // returns true if this accessor has a setter
- bool HasSetter() const { return m_setter != NULL || m_setter_ref != NULL || m_setter_ref_bool != NULL || m_setter_bool ; }
-
- // return true if this accessor has a getter
- bool HasGetter() const { return m_getter != NULL || m_getter_ref != NULL ; }
-
- bool HasAdder() const { return true ; }
- // set the property this accessor is responsible for in an object
- void SetProperty(wxObject *o, const wxxVariant &v) const
- {
- Klass *obj = dynamic_cast<Klass*>(o);
- T value ;
-
- if ( wxGetTypeInfo((T*)NULL)->GetKind() == wxT_OBJECT && v.GetTypeInfo()->GetKind() == wxT_OBJECT_PTR )
- value = *v.Get<T*>();
- else
- value = v.Get<T>();
- if (m_setter)
- (obj->*(m_setter))(value);
- else if ( m_setter_ref )
- (obj->*(m_setter_ref))(value);
- else if ( m_setter_ref_bool )
- (obj->*(m_setter_ref_bool))(value);
- else if ( m_setter_bool )
- (obj->*(m_setter_bool))(value);
- else
- {
- wxASSERT_MSG(0 , wxT("SetPropertyCalled without a valid Setter") ) ;
- }
- }
-
- // gets the property this accessor is responsible for from an object
- wxxVariant GetProperty(const wxObject *o) const
- {
- return wxxVariant( (wxxVariantData* ) DoGetProperty( o ) ) ;
- }
-
- // write the property this accessor is responsible for from an object into
- // a string
- void WriteValue( wxString& s , const wxObject *o ) const
- {
- DoGetProperty( o )->Write( s ) ;
- }
-
- // read a wxxVariant having the correct type for the property this accessor
- // is responsible for from a string
- wxxVariant ReadValue( const wxString &value ) const
- {
- T data ;
- wxStringReadValue( value , data ) ;
- return wxxVariant( data ) ;
- }
-
-private :
- wxxVariantDataT<T>* DoGetProperty(const wxObject *o) const
- {
- const Klass *obj = dynamic_cast<const Klass*>(o);
- if ( m_getter )
- return new wxxVariantDataT<T>( (obj->*(m_getter))() ) ;
- else
- return new wxxVariantDataT<T>( (obj->*(m_getter_ref))() ) ;
- }
-
- setter_t m_setter;
- setter_ref_t m_setter_ref;
- setter_ref_bool_t m_setter_ref_bool ;
- setter_bool_t m_setter_bool ;
- getter_t m_getter;
- getter_ref_t m_getter_ref ;
-};
-
-template<class Klass, typename CollectionType , typename AddedElementType>
-class WXDLLIMPEXP_BASE wxPropertyCollectionAccessorT : public wxPropertyAccessor
-{
-public:
-
- typedef void (Klass::*adder_t)(AddedElementType value);
- typedef const CollectionType& (Klass::*getter_t)() const ;
-
- wxPropertyCollectionAccessorT(adder_t adder, getter_t getter, const wxChar *a, const wxChar *g)
- : m_getter(getter), m_adder(adder) { m_adderName = a;m_getterName=g ;}
-
- ~wxPropertyCollectionAccessorT() {}
-
- // returns true if this accessor has a setter
- bool HasSetter() const { return false ;}
-
- // return true if this accessor has a getter
- bool HasGetter() const { return m_getter != NULL ;}
-
- // return true if this accessor has a getter
- bool HasAdder() const { return m_adder != NULL ;}
-
- // set the property this accessor is responsible for in an object
- void AddToPropertyCollection(wxObject *o, const wxxVariant &v) const
- {
- Klass *obj = dynamic_cast<Klass*>(o);
- AddedElementType value ;
-
- if ( wxGetTypeInfo((AddedElementType*)NULL)->GetKind() == wxT_OBJECT && v.GetTypeInfo()->GetKind() == wxT_OBJECT_PTR )
- value = *v.Get<AddedElementType*>();
- else
- value = v.Get<AddedElementType>();
-
- if (m_adder)
- (obj->*(m_adder))(value);
- else
- {
- wxASSERT_MSG(0 , wxT("SetPropertyCalled without a valid Setter") ) ;
- }
- }
-
- // gets the property this accessor is responsible for from an object
- wxxVariantArray GetPropertyCollection(const wxObject *o) const
- {
- const Klass *obj = dynamic_cast<const Klass*>(o);
-
- wxxVariantArray result ;
- CollectionType::compatibility_iterator current = (obj->*(m_getter))().GetFirst();
- while (current)
- {
- result.Add( new wxxVariant(current->GetData()) ) ;
- current = current->GetNext();
- }
- return result ;
- }
-
-
- // set the property this accessor is responsible for in an object
- void SetProperty(wxObject *WXUNUSED(o), const wxxVariant &WXUNUSED(v)) const
- {
- wxASSERT_MSG(0,wxT("SetProperty called on Collection Property")) ;
- }
-
- // gets the property this accessor is responsible for from an object
- wxxVariant GetProperty(const wxObject *WXUNUSED(o)) const
- {
- wxASSERT_MSG(0,wxT("GetProperty called on Collection Property")) ;
- return wxxVariant() ;
- }
-
- // write the property this accessor is responsible for from an object into
- // a string
- void WriteValue( wxString& s , const wxObject *o ) const
- {
- wxASSERT_MSG(0,wxT("WriteValue called on Collection Property")) ;
- }
-
- // read a wxxVariant having the correct type for the property this accessor
- // is responsible for from a string
- wxxVariant ReadValue( const wxString &value ) const
- {
- wxASSERT_MSG(0,wxT("ReadValue called on Collection Property")) ;
- return wxxVariant() ;
- }
-
-private :
- getter_t m_getter;
- adder_t m_adder;
-};
-
-class WXDLLIMPEXP_BASE wxPropertyInfo
-{
-public :
- wxPropertyInfo( wxPropertyInfo* &iter , const wxChar *name , const wxTypeInfo* typeInfo , wxPropertyAccessor *accessor , wxxVariant dv ) :
- m_name( name ) , m_typeInfo( typeInfo ) , m_accessor( accessor ) , m_defaultValue( dv ) , m_collectionElementTypeInfo(NULL)
- {
- Insert(iter) ;
- }
-
- wxPropertyInfo( wxPropertyInfo* &iter , const wxChar *name , const wxTypeInfo* collTypeInfo , const wxTypeInfo* elemTypeInfo , wxPropertyAccessor *accessor ) :
- m_name( name ) , m_typeInfo( collTypeInfo ) , m_accessor( accessor ) , m_collectionElementTypeInfo(elemTypeInfo)
- {
- Insert(iter) ;
- }
-
- // return the name of this property
- const wxChar * GetName() const { return m_name ; }
-
- // return the element type info of this property (for collections, otherwise NULL)
- const wxTypeInfo * GetCollectionElementTypeInfo() const { return m_collectionElementTypeInfo ; }
-
- // return the type info of this property
- const wxTypeInfo * GetTypeInfo() const { return m_typeInfo ; }
-
- // return the accessor for this property
- wxPropertyAccessor* GetAccessor() const { return m_accessor ; }
-
- // returns NULL if this is the last property of this class
- wxPropertyInfo* GetNext() const { return m_next ; }
-
- // returns the default value of this property, its kind may be wxT_VOID if it is not valid
- wxxVariant GetDefaultValue() const { return m_defaultValue ; }
-private :
- void Insert(wxPropertyInfo* &iter)
- {
- m_next = NULL ;
- if ( iter == NULL )
- iter = this ;
- else
- {
- wxPropertyInfo* i = iter ;
- while( i->m_next )
- i = i->m_next ;
-
- i->m_next = this ;
- }
- }