- 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 ;
-} ;
-
-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 ) ; }
-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() ;
- }
-
- template<typename T> bool HasData() const
- {
- const wxxVariantDataT<T> *dataptr = dynamic_cast<const wxxVariantDataT<T>*> (m_data) ;
- return dataptr != NULL ;
- }
-
- // 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() ; }
-
- // returns this value as string
- wxString GetAsString() const
- {
- wxString s ;
- GetTypeInfo()->ConvertToString( *this , s ) ;
- return 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 wxSetter
-{
-public :
- wxSetter( const wxString name ) { m_name = name ; }
- virtual void Set( wxObject *object, const wxxVariant &variantValue ) const = 0;
- const wxString& GetName() const { return m_name ; }
-private :
- wxString m_name ;
-} ;
-
-class wxGetter
-{
-public :
- wxGetter( const wxString name ) { m_name = name ; }
- virtual void Get( const wxObject *object , wxxVariant& result) const = 0;
- const wxString& GetName() const { return m_name ; }
-private :
- wxString m_name ;
-} ;
-
-class wxCollectionGetter
-{
-public :
- wxCollectionGetter( const wxString name ) { m_name = name ; }
- virtual void Get( const wxObject *object , wxxVariantArray& result) const = 0;
- const wxString& GetName() const { return m_name ; }
-private :
- wxString m_name ;
-} ;
-
-template<typename coll_t> void wxCollectionToVariantArray( const coll_t& coll , wxxVariantArray& result ) ;
-
-class wxAdder
-{
-public :
- wxAdder( const wxString name ) { m_name = name ; }
- virtual void Add( wxObject *object, const wxxVariant &variantValue ) const= 0;
- const wxString& GetName() const { return m_name ; }
-private :
- wxString m_name ;
-} ;
-
-
-template <class Klass, typename valueType, typename retType> void wxSetterFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*setter)( valueType ) )
-{
- Klass *obj = dynamic_cast<Klass*>(object);
- if ( variantValue.HasData<valueType>() )
- (obj->*(setter))(variantValue.Get<valueType>()) ;
- else
- (obj->*(setter))(*variantValue.Get<valueType*>()) ;
-}
-
-template <class Klass, typename valueType, typename retType> void wxSetterFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*setter)( valueType& ) )
-{
- Klass *obj = dynamic_cast<Klass*>(object);
- if ( variantValue.HasData<valueType>() )
- (obj->*(setter))(variantValue.Get<valueType>()) ;
- else
- (obj->*(setter))(*variantValue.Get<valueType*>()) ;
-}
-
-template <class Klass, typename valueType, typename retType> void wxSetterFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*setter)( const valueType& ) )
-{
- Klass *obj = dynamic_cast<Klass*>(object);
- if ( variantValue.HasData<valueType>() )
- (obj->*(setter))(variantValue.Get<valueType>()) ;
- else
- (obj->*(setter))(*variantValue.Get<valueType*>()) ;
-}
-
-template <class Klass, typename valueType, typename retType> void wxAdderFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*adder)( valueType ) )
-{
- Klass *obj = dynamic_cast<Klass*>(object);
- (obj->*(adder))(variantValue.Get<valueType>()) ;
-}
-
-template <class Klass, typename valueType, typename retType> void wxAdderFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*adder)( valueType& ) )
-{
- Klass *obj = dynamic_cast<Klass*>(object);
- (obj->*(adder))(variantValue.Get<valueType>()) ;
-}
-
-template <class Klass, typename valueType, typename retType> void wxAdderFunc( wxObject *object , const wxxVariant &variantValue , retType(Klass::*adder)( const valueType& ) )
-{
- Klass *obj = dynamic_cast<Klass*>(object);
- (obj->*(adder))(variantValue.Get<valueType>()) ;
-}
-
-/*
-template <class Klass, typename valueType> void wxxGetterFunc( const wxObject *object , wxxVariant &result, valueType& (Klass::*getter)() const )
-{
- const Klass *obj = dynamic_cast<const Klass*>(object);
- result = wxxVariant((obj->*(getter))()) ;
-}
-*/
-
-template <class Klass, typename valueType> void wxGetterFunc( const wxObject *object , wxxVariant &result, valueType(Klass::*getter)() const )
-{
- const Klass *obj = dynamic_cast<const Klass*>(object);
- result = wxxVariant((obj->*(getter))()) ;
-}
-
-template <class Klass, typename valueType> void wxGetterFunc( const wxObject *object , wxxVariant &result, const valueType&(Klass::*getter)() const)
-{
- const Klass *obj = dynamic_cast<const Klass*>(object);
- result = wxxVariant((obj->*(getter))()) ;
-}
-
-template <class Klass, typename valueType> void wxCollectionGetterFunc( const wxObject *object , wxxVariantArray &result, valueType& (Klass::*getter)() const )
-{
- const Klass *obj = dynamic_cast<const Klass*>(object);
- wxCollectionToVariantArray( (obj->*(getter))() , result ) ;
-}
-
-template <class Klass, typename valueType> void wxCollectionGetterFunc( const wxObject *object , wxxVariantArray &result, valueType(Klass::*getter)() const )
-{
- const Klass *obj = dynamic_cast<const Klass*>(object);
- wxCollectionToVariantArray( (obj->*(getter))() , result ) ;
-}
-
-template <class Klass, typename valueType> void wxCollectionGetterFunc( const wxObject *object , wxxVariantArray &result, const valueType&(Klass::*getter)() const)
-{
- const Klass *obj = dynamic_cast<const Klass*>(object);
- wxCollectionToVariantArray( (obj->*(getter))() , result ) ;
-}
-
-#define WX_SETTER( property , settermethod ) \
- class wxSetter##property : public wxSetter \
- { \
- public: \
- wxSetter##property() : wxSetter( #settermethod ) {} \
- void Set( wxObject *object, const wxxVariant &variantValue ) const \
- { \
- wxSetterFunc( object , variantValue , &class_t::settermethod ) ; \
- } \
- } ;
-
-#define WX_GETTER( property , gettermethod ) \
- class wxGetter##property : public wxGetter \
- { \
- public : \
- wxGetter##property() : wxGetter( #gettermethod ) {} \
- void Get( const wxObject *object , wxxVariant &result) const \
- { \
- wxGetterFunc( object , result , &class_t::gettermethod ) ; \
- } \
- } ;
-
-#define WX_ADDER( property , addermethod ) \
- class wxAdder##property : public wxAdder \
- { \
- public: \
- wxAdder##property() : wxAdder( #addermethod ) {} \
- void Add( wxObject *object, const wxxVariant &variantValue ) const \
- { \
- wxAdderFunc( object , variantValue , &class_t::addermethod ) ; \
- } \
- } ;
-
-#define WX_COLLECTION_GETTER( property , gettermethod ) \
- class wxCollectionGetter##property : public wxCollectionGetter \
- { \
- public : \
- wxCollectionGetter##property() : wxCollectionGetter( #gettermethod ) {} \
- void Get( const wxObject *object , wxxVariantArray &result) const \
- { \
- wxCollectionGetterFunc( object , result , &class_t::gettermethod ) ; \
- } \
- } ;
-
-class WXDLLIMPEXP_BASE wxPropertyAccessor
-{
-public :
- wxPropertyAccessor( wxSetter *setter , wxGetter *getter , wxAdder *adder , wxCollectionGetter *collectionGetter )
- { m_setter = setter ; m_getter = getter ; m_adder = adder ; m_collectionGetter = collectionGetter ;}
-
- virtual ~wxPropertyAccessor() {}
-
- // Setting a simple property (non-collection)
- virtual void SetProperty(wxObject *object, const wxxVariant &value) const
- { wxASSERT_MSG(m_setter,wxT("SetProperty called w/o valid setter") ) ; m_setter->Set( object , value ) ;}
-
- // Getting a simple property (non-collection)
- virtual void GetProperty(const wxObject *object, wxxVariant &result) const
- { wxASSERT_MSG(m_getter,wxT("GetProperty called w/o valid getter") ) ; return m_getter->Get( object , result ) ;}
-
- // Adding an element to a collection property
- virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const
- { wxASSERT_MSG(m_adder,wxT("AddToPropertyCollection called w/o valid adder") ) ; m_adder->Add( object , value ) ;}
-
- // Getting a collection property
- virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const
- { wxASSERT_MSG(m_collectionGetter,wxT("GetPropertyCollection called w/o valid collection getter") ) ; return m_collectionGetter->Get( obj , result) ;}
-
- virtual bool HasSetter() const { return m_setter != NULL ; }
- virtual bool HasCollectionGetter() const { return m_collectionGetter != NULL ; }
- virtual bool HasGetter() const { return m_getter != NULL ; }
- virtual bool HasAdder() const { return m_adder != NULL ; }
-
- virtual const wxString& GetCollectionGetterName() const
- { return m_collectionGetter->GetName() ; }
- virtual const wxString& GetGetterName() const
- { return m_getter->GetName() ; }
- virtual const wxString& GetSetterName() const
- { return m_setter->GetName() ; }
- virtual const wxString& GetAdderName() const
- { return m_adder->GetName() ; }
- /*
- virtual wxxVariant ReadValue( const wxString &value ) const ;
- virtual void WriteValue( wxString& value , const wxObject *o ) const ;
- */
-protected :
- wxSetter *m_setter ;
- wxAdder *m_adder ;
- wxGetter *m_getter ;
- wxCollectionGetter* m_collectionGetter ;
-};
-
- class WXDLLIMPEXP_BASE wxGenericPropertyAccessor : public wxPropertyAccessor
- {
- public :
- wxGenericPropertyAccessor( const wxString &propName ) ;
- ~wxGenericPropertyAccessor() ;
-
- virtual bool HasSetter() const { return true ; }
- virtual bool HasGetter() const { return true ; }
- virtual bool HasAdder() const { return false ; }
- virtual bool HasCollectionGetter() const { return false ; }
-
- virtual const wxString& GetGetterName() const
- { return m_getterName ; }
- virtual const wxString& GetSetterName() const
- { return m_setterName ; }
-
- virtual void SetProperty(wxObject *object, const wxxVariant &value) const ;
- virtual void GetProperty(const wxObject *object, wxxVariant &value) const ;
-
- // Adding an element to a collection property
- virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const
- { wxASSERT_MSG(0,wxT("AddToPropertyCollection called on a generic accessor") ) ;}
-
- // Getting a collection property
- virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const
- { wxASSERT_MSG(0,wxT("GetPropertyCollection called on a generic accessor") ) ;}
- private :
- struct wxGenericPropertyAccessorInternal ;
- wxGenericPropertyAccessorInternal* m_data ;
- wxString m_propertyName ;
- wxString m_setterName ;
- wxString m_getterName ;
-} ;
-
-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 ;
- }
- }