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 ; }
-// ----------------------------------------------------------------------------
-// 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
template<typename T>
template<typename T>
void wxStringWriteValue( wxString &s , const T &data);
-// for simple types this default implementation is ok, composited structures will have to
-// loop through their properties
-
-template<typename T>
-void wxXmlReadValue( wxXmlNode *node , T &data )
-{
- wxStringReadValue<T>( wxXmlGetContentFromNode( node ) , data ) ;
-}
+// sometimes a compiler invents specializations that are nowhere called, use this macro to satisfy the refs
-template<typename T>
-void wxXmlWriteValue( wxXmlNode *node , const T &data)
-{
- wxString s ;
- wxStringWriteValue<T>( s, data ) ;
- wxXmlAddContentToNode( node ,s ) ;
-}
+#define WX_ILLEGAL_TYPE_SPECIALIZATION( a ) \
+template<> const wxTypeInfo* wxGetTypeInfo( a * ) { assert(0) ; \
+ static wxBuiltInTypeInfo s_typeInfo( wxT_VOID ) ; return &s_typeInfo ; } \
+template<> void wxStringReadValue(const wxString & , a & ) { assert(0) ; }\
+template<> void wxStringWriteValue(wxString & , a const & ) { assert(0) ; }
// ----------------------------------------------------------------------------
// wxxVariant as typesafe data holder
// returns the type info of the contentc
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
virtual void Write( wxString &s ) const = 0 ;
// returns the type info of the contentc
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
virtual void Write( wxString &s ) const { wxStringWriteValue( s , m_data ) ; }
// get the typeinfo of the stored object
const wxTypeInfo* GetTypeInfo() const { return m_data->GetTypeInfo() ; }
- // write the value into an xml node
- 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
+ // write the value into a string
void Write( wxString &s ) const { m_data->Write( s ) ; }
// read the value from a string
class SetAndGetByRefRetBool ;
class GetByRef ;
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 HasGetter() const = 0 ;
const wxChar * GetGetterName() const { return m_setterName ; }
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 void WriteValue( wxString& value , wxObject *o ) const = 0 ;
+ virtual void WriteValue( wxString& value , const wxObject *o ) const = 0 ;
protected :
const wxChar *m_setterName ;
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>
class WXDLLIMPEXP_BASE wxPropertyAccessorT : public wxPropertyAccessor
{
}
// 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 ) ) ;
}
- // 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
// a string
- void WriteValue( wxString& s , wxObject *o ) const
+ 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 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
// is responsible for from a string
wxxVariant ReadValue( const wxString &value ) const
}
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 )
return new wxxVariantDataT<T>( (obj->*(m_getter))() ) ;
else
m_variantOfPtrToObjectConverter( _PtrConverter1 ) , m_variantToObjectConverter( _Converter2 ) , m_objectToVariantConverter( _Converter3 ) , m_next(sm_first)
{
sm_first = this;
- Register( m_className , this ) ;
+ Register() ;
}
virtual ~wxClassInfo() ;
return false ;
}
+#ifdef WXWIN_COMPATIBILITY_2_4
// Initializes parent pointers and hash table for fast searching.
- // this is going to be removed by Register/Unregister calls
- // in Constructor / Destructor together with making the hash map private
-
- static void InitializeClasses();
-
+ wxDEPRECATED( static void InitializeClasses() );
// Cleans up hash table used for fast searching.
-
- static void CleanUpClasses();
-
+ wxDEPRECATED( static void CleanUpClasses() );
+#endif
+ static void CleanUp();
+
// returns the first property
const wxPropertyInfo* GetFirstProperty() const { return m_firstProperty ; }
// 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
public :
wxReader() ;
~wxReader() ;
+
// the only thing wxReader knows about is the class info by object ID
wxClassInfo *GetObjectClassInfo(int objectID) ;
bool HasObjectClassInfo( int objectID ) ;