xti.h

来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C头文件 代码 · 共 1,688 行 · 第 1/5 页

H
1,688
字号
    // 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 ;
    }
    const wxString& GetName() const { return m_name ; }
private :
    wxxVariantData* m_data ;
    wxString m_name ;
} ;

#include <wx/dynarray.h>

WX_DECLARE_OBJARRAY_WITH_DECL(wxxVariant, wxxVariantArray, class WXDLLIMPEXP_BASE);

// templated streaming, every type must have their specialization for these methods

template<typename T>
void wxStringReadValue( const wxString &s , T &data );

template<typename T>
void wxStringWriteValue( wxString &s , const T &data);

template<typename T>
void wxToStringConverter( const wxxVariant &v, wxString &s wxTEMPLATED_FUNCTION_FIX(T)) { wxStringWriteValue( s , v.wxTEMPLATED_MEMBER_CALL(Get , T) ) ; }

template<typename T>
void wxFromStringConverter( const wxString &s, wxxVariant &v wxTEMPLATED_FUNCTION_FIX(T)) { T d ; wxStringReadValue( s , d ) ; v = wxxVariant(d) ; }

// ----------------------------------------------------------------------------
// 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 wxSetter
{
public:
    wxSetter( const wxString name ) { m_name = name ; }
    virtual ~wxSetter() {}
    virtual void Set( wxObject *object, const wxxVariant &variantValue ) const = 0;
    const wxString& GetName() const { return m_name ; }
private:
    wxString m_name;
};

class WXDLLIMPEXP_BASE wxGetter
{
public:
    wxGetter( const wxString name ) { m_name = name ; }
    virtual ~wxGetter() {}
    virtual void Get( const wxObject *object , wxxVariant& result) const = 0;
    const wxString& GetName() const { return m_name ; }
private:
    wxString m_name;
};

class WXDLLIMPEXP_BASE wxCollectionGetter
{
public :
    wxCollectionGetter( const wxString name ) { m_name = name ; }
    virtual ~wxCollectionGetter() {}
    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 WXDLLIMPEXP_BASE wxCollectionToVariantArray( const coll_t& coll , wxxVariantArray& result ) ;

class WXDLLIMPEXP_BASE wxAdder
{
public :
    wxAdder( const wxString name ) { m_name = name ; }
    virtual ~wxAdder() {}
    virtual void Add( wxObject *object, const wxxVariant &variantValue ) const= 0;
    const wxString& GetName() const { return m_name ; }
private :
    wxString m_name ;
} ;


#define wxSETTER( property, Klass, valueType, setterMethod ) \
class wxSetter##property : public wxSetter \
{ \
public: \
    wxINFUNC_CLASS_TYPE_FIX(Klass) \
    wxSetter##property() : wxSetter( wxT(#setterMethod) ) {} \
    ~wxSetter##property() {} \
    void Set( wxObject *object, const wxxVariant &variantValue ) const \
{ \
    Klass *obj = dynamic_cast<Klass*>(object) ;  \
    if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
    obj->setterMethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
            else \
            obj->setterMethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
} \
} ;

#define wxGETTER( property, Klass, valueType , gettermethod ) \
class wxGetter##property : public wxGetter \
{ \
public : \
    wxINFUNC_CLASS_TYPE_FIX(Klass) \
    wxGetter##property() : wxGetter( wxT(#gettermethod) ) {} \
    ~wxGetter##property() {} \
    void Get( const wxObject *object , wxxVariant &result) const \
{ \
    const Klass *obj = dynamic_cast<const Klass*>(object) ;  \
    result = wxxVariant( obj->gettermethod() ) ; \
} \
} ;

#define wxADDER( property, Klass, valueType , addermethod ) \
class wxAdder##property : public wxAdder \
{ \
public: \
    wxINFUNC_CLASS_TYPE_FIX(Klass) \
    wxAdder##property() : wxAdder( wxT(#addermethod) ) {} \
    ~wxAdder##property() {} \
    void Add( wxObject *object, const wxxVariant &variantValue ) const \
{ \
    Klass *obj = dynamic_cast<Klass*>(object) ;  \
    if ( variantValue.wxTEMPLATED_MEMBER_CALL(HasData, valueType) ) \
    obj->addermethod(variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType)) ; \
            else \
            obj->addermethod(*variantValue.wxTEMPLATED_MEMBER_CALL(Get , valueType*)) ; \
} \
} ;

#define wxCOLLECTION_GETTER( property, Klass, valueType , gettermethod ) \
class wxCollectionGetter##property : public wxCollectionGetter \
{ \
public : \
    wxINFUNC_CLASS_TYPE_FIX(Klass) \
    wxCollectionGetter##property() : wxCollectionGetter( wxT(#gettermethod) ) {} \
    ~wxCollectionGetter##property() {} \
    void Get( const wxObject *object , wxxVariantArray &result) const \
{ \
    const Klass *obj = dynamic_cast<const Klass*>(object) ;  \
    wxCollectionToVariantArray( obj->gettermethod() , result ) ; \
} \
} ;

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
    { if ( m_setter ) m_setter->Set( object , value ) ; else wxLogError( _("SetProperty called w/o valid setter") ) ;}

    // Getting a simple property (non-collection)
    virtual void GetProperty(const wxObject *object, wxxVariant &result) const
    { if ( m_getter ) m_getter->Get( object , result ) ; else wxLogError( _("GetProperty called w/o valid getter") ) ;}

    // Adding an element to a collection property
    virtual void AddToPropertyCollection(wxObject *object, const wxxVariant &value) const
    { if ( m_adder ) m_adder->Add( object , value ) ; else wxLogError( _("AddToPropertyCollection called w/o valid adder") ) ;}

    // Getting a collection property
    virtual void GetPropertyCollection( const wxObject *obj, wxxVariantArray &result) const
    { if ( m_collectionGetter ) m_collectionGetter->Get( obj , result) ; else wxLogError( _("GetPropertyCollection called w/o valid collection getter") ) ;}

    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() ; }

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() ;

    void RenameProperty( const wxString& WXUNUSED_UNLESS_DEBUG(oldName),
        const wxString& newName )
    {
        wxASSERT( oldName == m_propertyName ) ; m_propertyName = newName ;
    }
    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 *WXUNUSED(object), const wxxVariant &WXUNUSED(value)) const
    { wxLogError( _("AddToPropertyCollection called on a generic accessor") ) ;}

    // Getting a collection property
    virtual void GetPropertyCollection( const wxObject *WXUNUSED(obj), wxxVariantArray &WXUNUSED(result)) const
    { wxLogError ( _("GetPropertyCollection called on a generic accessor") ) ;}
private :
    struct wxGenericPropertyAccessorInternal ;
    wxGenericPropertyAccessorInternal* m_data ;
    wxString m_propertyName ;
    wxString m_setterName ;
    wxString m_getterName ;
} ;

typedef long wxPropertyInfoFlags ;
enum {
    // will be removed in future releases
    wxPROP_DEPRECATED       = 0x00000001 ,
    // object graph property, will be streamed with priority (after constructor properties)
    wxPROP_OBJECT_GRAPH     = 0x00000002 ,
    // this will only be streamed out and in as enum/set, the internal representation is still a long
    wxPROP_ENUM_STORE_LONG  = 0x00000004 ,
    // don't stream out this property, needed eg to avoid streaming out children that are always created by their parents
    wxPROP_DONT_STREAM = 0x00000008 ,
}  ;

class WXDLLIMPEXP_BASE wxPropertyInfo
{
    friend class WXDLLIMPEXP_BASE wxDynamicClassInfo ;
public :
    wxPropertyInfo(wxPropertyInfo* &iter,
                   wxClassInfo* itsClass,
                   const wxString& name,
                   const wxString& typeName,
                   wxPropertyAccessor *accessor,
                   wxxVariant dv,
                   wxPropertyInfoFlags flags = 0,
                   const wxString& helpString = wxEmptyString,
                   const wxString& groupString = wxEmptyString) :
                   m_itsClass(itsClass),
           m_name(name),
           m_typeInfo(NULL),
           m_typeName(typeName) ,
           m_collectionElementTypeInfo(NULL),
           m_accessor(accessor),
           m_defaultValue(dv),
           m_flags(flags),
           m_helpString(helpString),
           m_groupString(groupString)
       {
           Insert(iter);
       }

#if wxUSE_UNICODE
    wxPropertyInfo(wxPropertyInfo* &iter,
                   wxClassInfo* itsClass,
                   const wxString& name,
                   const char* typeName,
                   wxPropertyAccessor *accessor,
                   wxxVariant dv,
                   wxPropertyInfoFlags flags = 0,
                   const wxString& helpString = wxEmptyString,
                   const wxString& groupString = wxEmptyString) :
                   m_itsClass(itsClass),
           m_name(name),
           m_typeInfo(NULL),
           m_typeName(wxString::FromAscii(typeName)) ,
           m_collectionElementTypeInfo(NULL),
           m_accessor(accessor),
           m_defaultValue(dv),
           m_flags(flags),
           m_helpString(helpString),
           m_groupString(groupString)
       {
           Insert(iter);
       }
#endif
    wxPropertyInfo(wxPropertyInfo* &iter,
                   wxClassInfo* itsClass,
                   const wxString& name,
                   wxDelegateTypeInfo* type,
                   wxPropertyAccessor *accessor,
                   wxxVariant dv,
                   wxPropertyInfoFlags flags = 0,
                   const wxString& helpString = wxEmptyString,
                   const wxString& groupString = wxEmptyString) :
           m_itsClass(itsClass),
           m_name(name),
           m_typeInfo(type),
           m_collectionElementTypeInfo(NULL),
           m_accessor(accessor),
           m_defaultValue(dv),
           m_flags(flags),
           m_helpString(helpString),
           m_groupString(groupString)
       {
           Insert(iter);
       }

       wxPropertyInfo(wxPropertyInfo* &iter,
                      wxClassInfo* itsClass, const wxString& name,
                      const wxString& collectionTypeName,
                      const wxString& elementTypeName,
                      wxPropertyAccessor *accessor,
                      wxPropertyInfoFlags flags = 0,
                      const wxString& helpString = wxEmptyString,
                      const wxString& groupString = wxEmptyString) :
           m_itsClass(itsClass),
           m_name(name),
           m_typeInfo(NULL),
           m_typeName(collectionTypeName) ,
           m_collectionElementTypeInfo(NULL),
           m_collectionElementTypeName(elementTypeName),
           m_accessor(accessor) ,

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?