xti expansions, streaming code changes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22710 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
26f75f229b
commit
aa8d7c2f9b
106
include/wx/xti.h
106
include/wx/xti.h
@ -316,19 +316,6 @@ template<typename T> const wxTypeInfo* wxGetTypeInfo( wxSet<T> * )
|
|||||||
template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \
|
template<> const wxTypeInfo* wxGetTypeInfo( e ** ){ static wxBuiltInTypeInfo s_typeInfo(wxT_VOID) ; assert(0) ; return &s_typeInfo ; } \
|
||||||
template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e) ; return &s_typeInfo ; }
|
template<> const wxTypeInfo* wxGetTypeInfo( e * ){ static wxCustomTypeInfo s_typeInfo(#e) ; return &s_typeInfo ; }
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// value streaming
|
|
||||||
//
|
|
||||||
// streaming is defined for xml constructs right now, the aim is to make this
|
|
||||||
// pluggable in the future
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// convenience function (avoids including xml headers in users code)
|
|
||||||
|
|
||||||
class wxXmlNode ;
|
|
||||||
void wxXmlAddContentToNode( wxXmlNode* node , const wxString& data ) ;
|
|
||||||
wxString wxXmlGetContentFromNode( wxXmlNode *node ) ;
|
|
||||||
|
|
||||||
// templated streaming, every type must have their specialization for these methods
|
// templated streaming, every type must have their specialization for these methods
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@ -337,22 +324,13 @@ void wxStringReadValue( const wxString &s , T &data );
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
void wxStringWriteValue( wxString &s , const T &data);
|
void wxStringWriteValue( wxString &s , const T &data);
|
||||||
|
|
||||||
// for simple types this default implementation is ok, composited structures will have to
|
// sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
|
||||||
// loop through their properties
|
|
||||||
|
|
||||||
template<typename T>
|
#define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \
|
||||||
void wxXmlReadValue( wxXmlNode *node , T &data )
|
template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
|
||||||
{
|
static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
|
||||||
wxStringReadValue<T>( wxXmlGetContentFromNode( node ) , data ) ;
|
template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
|
||||||
}
|
template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void wxXmlWriteValue( wxXmlNode *node , const T &data)
|
|
||||||
{
|
|
||||||
wxString s ;
|
|
||||||
wxStringWriteValue<T>( s, data ) ;
|
|
||||||
wxXmlAddContentToNode( node ,s ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxxVariant as typesafe data holder
|
// wxxVariant as typesafe data holder
|
||||||
@ -369,12 +347,6 @@ public:
|
|||||||
// returns the type info of the contentc
|
// returns the type info of the contentc
|
||||||
virtual const wxTypeInfo* GetTypeInfo() const = 0 ;
|
virtual const wxTypeInfo* GetTypeInfo() const = 0 ;
|
||||||
|
|
||||||
// write the value into an xml node
|
|
||||||
virtual void Write( wxXmlNode* node ) const = 0 ;
|
|
||||||
|
|
||||||
// read the value from the xml node
|
|
||||||
virtual void Read( wxXmlNode* node ) = 0 ;
|
|
||||||
|
|
||||||
// write the value into a string
|
// write the value into a string
|
||||||
virtual void Write( wxString &s ) const = 0 ;
|
virtual void Write( wxString &s ) const = 0 ;
|
||||||
|
|
||||||
@ -403,12 +375,6 @@ public:
|
|||||||
// returns the type info of the contentc
|
// returns the type info of the contentc
|
||||||
virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; }
|
virtual const wxTypeInfo* GetTypeInfo() const { return wxGetTypeInfo( (T*) NULL ) ; }
|
||||||
|
|
||||||
// write the value into an xml node
|
|
||||||
virtual void Write( wxXmlNode* node ) const { wxXmlWriteValue( node , m_data ) ; }
|
|
||||||
|
|
||||||
// read the value from the xml node
|
|
||||||
virtual void Read( wxXmlNode* node ) { wxXmlReadValue( node , m_data ) ; }
|
|
||||||
|
|
||||||
// write the value into a string
|
// write the value into a string
|
||||||
virtual void Write( wxString &s ) const { wxStringWriteValue( s , m_data ) ; }
|
virtual void Write( wxString &s ) const { wxStringWriteValue( s , m_data ) ; }
|
||||||
|
|
||||||
@ -466,13 +432,7 @@ public :
|
|||||||
// get the typeinfo of the stored object
|
// get the typeinfo of the stored object
|
||||||
const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
|
const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
|
||||||
|
|
||||||
// write the value into an xml node
|
// write the value into a string
|
||||||
void Write( wxXmlNode* node ) const { m_data->Write( node ) ; }
|
|
||||||
|
|
||||||
// read the value from the xml node
|
|
||||||
void Read( wxXmlNode* node ) { m_data->Read( node ) ; }
|
|
||||||
|
|
||||||
// write the value into a string
|
|
||||||
void Write( wxString &s ) const { m_data->Write( s ) ; }
|
void Write( wxString &s ) const { m_data->Write( s ) ; }
|
||||||
|
|
||||||
// read the value from a string
|
// read the value from a string
|
||||||
@ -513,26 +473,18 @@ public :
|
|||||||
class SetAndGetByRefRetBool ;
|
class SetAndGetByRefRetBool ;
|
||||||
class GetByRef ;
|
class GetByRef ;
|
||||||
virtual void SetProperty(wxObject *object, const wxxVariant &value) const = 0 ;
|
virtual void SetProperty(wxObject *object, const wxxVariant &value) const = 0 ;
|
||||||
virtual wxxVariant GetProperty(wxObject *object) const = 0 ;
|
virtual wxxVariant GetProperty(const wxObject *object) const = 0 ;
|
||||||
virtual bool HasSetter() const = 0 ;
|
virtual bool HasSetter() const = 0 ;
|
||||||
virtual bool HasGetter() const = 0 ;
|
virtual bool HasGetter() const = 0 ;
|
||||||
const wxChar * GetGetterName() const { return m_setterName ; }
|
const wxChar * GetGetterName() const { return m_setterName ; }
|
||||||
const wxChar * GetSetterName() const { return m_getterName ; }
|
const wxChar * GetSetterName() const { return m_getterName ; }
|
||||||
virtual wxxVariant ReadValue( wxXmlNode* node ) const = 0 ;
|
|
||||||
virtual void WriteValue( wxXmlNode* node , wxObject *o ) const = 0 ;
|
|
||||||
virtual wxxVariant ReadValue( const wxString &value ) const = 0 ;
|
virtual wxxVariant ReadValue( const wxString &value ) const = 0 ;
|
||||||
virtual void WriteValue( wxString& value , wxObject *o ) const = 0 ;
|
virtual void WriteValue( wxString& value , const wxObject *o ) const = 0 ;
|
||||||
protected :
|
protected :
|
||||||
const wxChar *m_setterName ;
|
const wxChar *m_setterName ;
|
||||||
const wxChar *m_getterName ;
|
const wxChar *m_getterName ;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void wxXmlReadValue( wxXmlNode *node , T &data ) ;
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void wxXmlWriteValue( wxXmlNode *node , const T &data) ;
|
|
||||||
|
|
||||||
template<class Klass, typename T>
|
template<class Klass, typename T>
|
||||||
class WXDLLIMPEXP_BASE wxPropertyAccessorT : public wxPropertyAccessor
|
class WXDLLIMPEXP_BASE wxPropertyAccessorT : public wxPropertyAccessor
|
||||||
{
|
{
|
||||||
@ -611,34 +563,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// gets the property this accessor is responsible for from an object
|
// gets the property this accessor is responsible for from an object
|
||||||
wxxVariant GetProperty(wxObject *o) const
|
wxxVariant GetProperty(const wxObject *o) const
|
||||||
{
|
{
|
||||||
return wxxVariant( (wxxVariantData* ) DoGetProperty( o ) ) ;
|
return wxxVariant( (wxxVariantData* ) DoGetProperty( o ) ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write the property this accessor is responsible for from an object into
|
|
||||||
// a xml node
|
|
||||||
void WriteValue( wxXmlNode* node , wxObject *o ) const
|
|
||||||
{
|
|
||||||
DoGetProperty( o )->Write( node ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// write the property this accessor is responsible for from an object into
|
// write the property this accessor is responsible for from an object into
|
||||||
// a string
|
// a string
|
||||||
void WriteValue( wxString& s , wxObject *o ) const
|
void WriteValue( wxString& s , const wxObject *o ) const
|
||||||
{
|
{
|
||||||
DoGetProperty( o )->Write( s ) ;
|
DoGetProperty( o )->Write( s ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read a wxxVariant having the correct type for the property this accessor
|
|
||||||
// is responsible for from an xml node
|
|
||||||
wxxVariant ReadValue( wxXmlNode* node ) const
|
|
||||||
{
|
|
||||||
T data ;
|
|
||||||
wxXmlReadValue( node , data ) ;
|
|
||||||
return wxxVariant( data ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
// read a wxxVariant having the correct type for the property this accessor
|
// read a wxxVariant having the correct type for the property this accessor
|
||||||
// is responsible for from a string
|
// is responsible for from a string
|
||||||
wxxVariant ReadValue( const wxString &value ) const
|
wxxVariant ReadValue( const wxString &value ) const
|
||||||
@ -649,9 +585,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private :
|
private :
|
||||||
wxxVariantDataT<T>* DoGetProperty(wxObject *o) const
|
wxxVariantDataT<T>* DoGetProperty(const wxObject *o) const
|
||||||
{
|
{
|
||||||
Klass *obj = dynamic_cast<Klass*>(o);
|
const Klass *obj = dynamic_cast<const Klass*>(o);
|
||||||
if ( m_getter )
|
if ( m_getter )
|
||||||
return new wxxVariantDataT<T>( (obj->*(m_getter))() ) ;
|
return new wxxVariantDataT<T>( (obj->*(m_getter))() ) ;
|
||||||
else
|
else
|
||||||
@ -1021,7 +957,7 @@ public:
|
|||||||
m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first)
|
m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first)
|
||||||
{
|
{
|
||||||
sm_first = this;
|
sm_first = this;
|
||||||
Register( m_className , this ) ;
|
Register() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~wxClassInfo() ;
|
virtual ~wxClassInfo() ;
|
||||||
@ -1056,16 +992,14 @@ public:
|
|||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef WXWIN_COMPATIBILITY_2_4
|
||||||
// Initializes parent pointers and hash table for fast searching.
|
// Initializes parent pointers and hash table for fast searching.
|
||||||
// this is going to be removed by Register/Unregister calls
|
wxDEPRECATED( static void InitializeClasses() );
|
||||||
// in Constructor / Destructor together with making the hash map private
|
|
||||||
|
|
||||||
static void InitializeClasses();
|
|
||||||
|
|
||||||
// Cleans up hash table used for fast searching.
|
// Cleans up hash table used for fast searching.
|
||||||
|
wxDEPRECATED( static void CleanUpClasses() );
|
||||||
static void CleanUpClasses();
|
#endif
|
||||||
|
static void CleanUp();
|
||||||
|
|
||||||
// returns the first property
|
// returns the first property
|
||||||
const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
|
const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
|
||||||
|
|
||||||
|
@ -32,10 +32,122 @@ const int wxNullObjectID = -1 ;
|
|||||||
// listed below.
|
// listed below.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Main interface for streaming out an object to XML.
|
Main interfaces for streaming out objects.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void WriteComponent(wxObject *Object, const wxClassInfo *ClassInfo, wxXmlNode *parent, const wxString& nodeName );
|
class wxPersister
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
// will be called before a toplevel object is written, may veto even that (eg for objects that cannot be supported) by returning false
|
||||||
|
virtual bool BeforeWriteObject( const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) , const wxString &WXUNUSED(name)) { return true ; }
|
||||||
|
|
||||||
|
// will be called before a property gets written, may change the value , eg replace a concrete wxSize by wxSize( -1 , -1 ) or veto
|
||||||
|
// writing that property at all by returning false
|
||||||
|
virtual bool BeforeWriteProperty( const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) , wxxVariant &WXUNUSED(value) ) { return true ; }
|
||||||
|
|
||||||
|
// will be called before a property with an object value gets written, may change the value , eg replace the instance, void it or veto
|
||||||
|
// writing that property at all by returning false
|
||||||
|
virtual bool BeforeWritePropertyAsObject( const wxObject *WXUNUSED(object) , const wxClassInfo *WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) , wxxVariant &WXUNUSED(value) ) { return true ; }
|
||||||
|
|
||||||
|
// will be called before a delegate property gets written, you may change all informations about the event sink
|
||||||
|
virtual bool BeforeWriteDelegate( const wxObject *WXUNUSED(object), const wxClassInfo* WXUNUSED(classInfo) , const wxPropertyInfo *WXUNUSED(propInfo) ,
|
||||||
|
const wxObject *&WXUNUSED(eventSink) , const wxHandlerInfo* &WXUNUSED(handlerInfo) ) { return true ; }
|
||||||
|
} ;
|
||||||
|
|
||||||
|
class wxWriter : public wxObject
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
wxWriter() ;
|
||||||
|
~wxWriter() ;
|
||||||
|
|
||||||
|
// with this call you start writing out a new top-level object
|
||||||
|
void WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name ) ;
|
||||||
|
|
||||||
|
int GetObjectID(const wxObject *obj) ;
|
||||||
|
bool IsObjectKnown( const wxObject *obj ) ;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// streaming callbacks
|
||||||
|
//
|
||||||
|
// these callbacks really write out the values in the stream format
|
||||||
|
//
|
||||||
|
|
||||||
|
// start of writing an toplevel object name param is used for unique identification within the container
|
||||||
|
virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , const wxString &name ) = 0 ;
|
||||||
|
|
||||||
|
// end of writing an toplevel object name param is used for unique identification within the container
|
||||||
|
virtual void DoEndWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , const wxString &name ) = 0 ;
|
||||||
|
|
||||||
|
// start of writing an object used as param
|
||||||
|
virtual void DoBeginWriteParamAsObject(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
|
||||||
|
const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) = 0 ;
|
||||||
|
|
||||||
|
// end of writing an object used as param
|
||||||
|
virtual void DoEndWriteParamAsObject(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
|
||||||
|
const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) = 0 ;
|
||||||
|
|
||||||
|
// insert an object reference to an already written object
|
||||||
|
virtual void DoWriteObjectReference(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
|
||||||
|
const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) = 0 ;
|
||||||
|
|
||||||
|
// writes a property in the stream format
|
||||||
|
virtual void DoWriteProperty( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo , wxxVariant &value ) = 0 ;
|
||||||
|
|
||||||
|
// writes a delegate in the stream format
|
||||||
|
virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo ,
|
||||||
|
const wxObject *eventSink , int sinkObjectID , const wxClassInfo* eventSinkClassInfo , const wxHandlerInfo* handlerIndo ) = 0;
|
||||||
|
private :
|
||||||
|
|
||||||
|
struct wxWriterInternal ;
|
||||||
|
wxWriterInternal* m_data ;
|
||||||
|
|
||||||
|
struct wxWriterInternalPropertiesData ;
|
||||||
|
|
||||||
|
void WriteAllProperties( const wxObject * obj , const wxClassInfo* ci , wxPersister *persister, wxWriterInternalPropertiesData * data ) ;
|
||||||
|
} ;
|
||||||
|
|
||||||
|
class wxXmlWriter : public wxWriter
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
|
||||||
|
wxXmlWriter( wxXmlNode * parent ) ;
|
||||||
|
~wxXmlWriter() ;
|
||||||
|
|
||||||
|
//
|
||||||
|
// streaming callbacks
|
||||||
|
//
|
||||||
|
// these callbacks really write out the values in the stream format
|
||||||
|
//
|
||||||
|
|
||||||
|
// start of writing an toplevel object name param is used for unique identification within the container
|
||||||
|
virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , const wxString &name ) ;
|
||||||
|
|
||||||
|
// end of writing an toplevel object name param is used for unique identification within the container
|
||||||
|
virtual void DoEndWriteObject(const wxObject *object, const wxClassInfo *classInfo, int objectID , const wxString &name ) ;
|
||||||
|
|
||||||
|
// start of writing an object used as param
|
||||||
|
virtual void DoBeginWriteParamAsObject(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
|
||||||
|
const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) ;
|
||||||
|
|
||||||
|
// end of writing an object used as param
|
||||||
|
virtual void DoEndWriteParamAsObject(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
|
||||||
|
const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) ;
|
||||||
|
|
||||||
|
// insert an object reference to an already written object or to a null object
|
||||||
|
virtual void DoWriteObjectReference(const wxObject *parentObject, const wxClassInfo *parentClassInfo, const wxObject *valueObject,
|
||||||
|
const wxClassInfo *valueObjectClassInfo, int valueObjectID , const wxPropertyInfo *propInfo ) ;
|
||||||
|
|
||||||
|
// writes a property in the stream format
|
||||||
|
virtual void DoWriteProperty( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo , wxxVariant &value ) ;
|
||||||
|
|
||||||
|
// writes a delegate in the stream format
|
||||||
|
virtual void DoWriteDelegate( const wxObject *object, const wxClassInfo* classInfo , const wxPropertyInfo *propInfo ,
|
||||||
|
const wxObject *eventSink, int sinkObjectID , const wxClassInfo* eventSinkClassInfo , const wxHandlerInfo* handlerInfo ) ;
|
||||||
|
private :
|
||||||
|
struct wxXmlWriterInternal ;
|
||||||
|
wxXmlWriterInternal* m_data ;
|
||||||
|
} ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Streaming callbacks for depersisting XML to code, or running objects
|
Streaming callbacks for depersisting XML to code, or running objects
|
||||||
@ -53,6 +165,7 @@ class wxReader : public wxObject
|
|||||||
public :
|
public :
|
||||||
wxReader() ;
|
wxReader() ;
|
||||||
~wxReader() ;
|
~wxReader() ;
|
||||||
|
|
||||||
// the only thing wxReader knows about is the class info by object ID
|
// the only thing wxReader knows about is the class info by object ID
|
||||||
wxClassInfo *GetObjectClassInfo(int objectID) ;
|
wxClassInfo *GetObjectClassInfo(int objectID) ;
|
||||||
bool HasObjectClassInfo( int objectID ) ;
|
bool HasObjectClassInfo( int objectID ) ;
|
||||||
|
Loading…
Reference in New Issue
Block a user