From: Stefan Csomor Date: Fri, 7 Jan 2011 17:22:59 +0000 (+0000) Subject: XTI updates X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/cbca59a8fb340a4ed288eed5fad9589df63c49ec?ds=inline XTI updates git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66621 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/any.h b/include/wx/any.h index 511239f111..6e38772532 100644 --- a/include/wx/any.h +++ b/include/wx/any.h @@ -113,6 +113,10 @@ public: // FIXME-VC6: remove this hack when VC6 is no longer supported template bool CheckType(T* reserved = NULL) const; + +#if wxUSE_EXTENDED_RTTI + virtual const wxTypeInfo* GetTypeInfo() const = 0; +#endif private: }; @@ -314,6 +318,12 @@ public: { return Ops::GetValue(buf); } +#if wxUSE_EXTENDED_RTTI + virtual const wxTypeInfo* GetTypeInfo() const + { + return wxGetTypeInfo((T*)NULL); + } +#endif }; @@ -348,7 +358,7 @@ wxAnyValueTypeScopedPtr wxAnyValueTypeImpl::sm_instance = new wxAnyValueTypeI // Helper macro for using same base value type implementation for multiple // actual C++ data types. // -#define WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \ +#define _WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \ template<> \ class wxAnyValueTypeImpl : public wxAnyValueTypeImpl##CLSTYPE \ { \ @@ -369,9 +379,21 @@ public: \ const UseDataType* sptr = \ reinterpret_cast(voidPtr); \ return static_cast(*sptr); \ + } + +#if wxUSE_EXTENDED_RTTI +#define WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \ +_WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE)\ + virtual const wxTypeInfo* GetTypeInfo() const \ + { \ + return wxGetTypeInfo((T*)NULL); \ } \ }; - +#else +#define WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE) \ +_WX_ANY_DEFINE_SUB_TYPE(T, CLSTYPE)\ +}; +#endif // // Integer value types @@ -967,6 +989,12 @@ public: return value; } +#if wxUSE_EXTENDED_RTTI + const wxTypeInfo* GetTypeInfo() const + { + return m_type->GetTypeInfo(); + } +#endif /** Template function that retrieves and converts the value of this variant to the type that T* value is. diff --git a/include/wx/defs.h b/include/wx/defs.h index e3c8c9313b..14afcf2f7e 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1486,12 +1486,12 @@ typedef double wxDouble; #else # define wxTO_STRING(type) ToString##type # define wxTO_STRING_IMP(type) \ - inline void ToString##type( const wxVariantBase& data, wxString &result ) \ + inline void ToString##type( const wxAny& data, wxString &result ) \ { wxToStringConverter(data, result); } # define wxFROM_STRING(type) FromString##type # define wxFROM_STRING_IMP(type) \ - inline void FromString##type( const wxString& data, wxVariantBase &result ) \ + inline void FromString##type( const wxString& data, wxAny &result ) \ { wxFromStringConverter(data, result); } #endif diff --git a/include/wx/object.h b/include/wx/object.h index 26bfc5b1e4..ef260e496c 100644 --- a/include/wx/object.h +++ b/include/wx/object.h @@ -26,6 +26,12 @@ #include "wx/xti.h" #include "wx/rtti.h" +#define wxIMPLEMENT_CLASS(name, basename) \ + wxIMPLEMENT_ABSTRACT_CLASS(name, basename) + +#define wxIMPLEMENT_CLASS2(name, basename1, basename2) \ + wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) + // ----------------------------------- // for pluggable classes // ----------------------------------- @@ -186,6 +192,25 @@ inline T *wxCheckCast(const void *ptr, T * = NULL) #endif // wxUSE_MEMORY_TRACING +// ---------------------------------------------------------------------------- +// Compatibility macro aliases DECLARE group +// ---------------------------------------------------------------------------- +// deprecated variants _not_ requiring a semicolon after them and without wx prefix. +// (note that also some wx-prefixed macro do _not_ require a semicolon because +// it's not always possible to force the compire to require it) + +#define DECLARE_CLASS_INFO_ITERATORS() wxDECLARE_CLASS_INFO_ITERATORS(); +#define DECLARE_ABSTRACT_CLASS(n) wxDECLARE_ABSTRACT_CLASS(n); +#define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(n) wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(n); +#define DECLARE_DYNAMIC_CLASS_NO_COPY(n) wxDECLARE_DYNAMIC_CLASS_NO_COPY(n); +#define DECLARE_DYNAMIC_CLASS(n) wxDECLARE_DYNAMIC_CLASS(n); +#define DECLARE_CLASS(n) wxDECLARE_CLASS(n); + +#define DECLARE_PLUGGABLE_CLASS(n) wxDECLARE_PLUGGABLE_CLASS(n); +#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(n) wxDECLARE_ABSTRACT_PLUGGABLE_CLASS(n); +#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(n,u) wxDECLARE_USER_EXPORTED_PLUGGABLE_CLASS(n,u); +#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,u) wxDECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,u); + // ---------------------------------------------------------------------------- // wxRefCounter: ref counted data "manager" // ---------------------------------------------------------------------------- @@ -222,7 +247,6 @@ private: typedef wxRefCounter wxObjectRefData; - // ---------------------------------------------------------------------------- // wxObjectDataPtr: helper class to avoid memleaks because of missing calls // to wxObjectRefData::DecRef @@ -403,46 +427,7 @@ inline wxObject *wxCheckDynamicCast(wxObject *obj, wxClassInfo *classInfo) return obj && obj->GetClassInfo()->IsKindOf(classInfo) ? obj : NULL; } -#if wxUSE_EXTENDED_RTTI -class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject -{ - friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo ; -public: - // instantiates this object with an instance of its superclass - wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ; - virtual ~wxDynamicObject(); - - void SetProperty (const wxChar *propertyName, const wxxVariant &value); - wxxVariant GetProperty (const wxChar *propertyName) const ; - - // get the runtime identity of this object - wxClassInfo *GetClassInfo() const - { -#ifdef _MSC_VER - return (wxClassInfo*) m_classInfo; -#else - wxDynamicClassInfo *nonconst = const_cast(m_classInfo); - return static_cast(nonconst); -#endif - } - - wxObject* GetSuperClassInstance() const - { - return m_superClassInstance ; - } -private : - // removes an existing runtime-property - void RemoveProperty( const wxChar *propertyName ) ; - - // renames an existing runtime-property - void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ; - - wxObject *m_superClassInstance ; - const wxDynamicClassInfo *m_classInfo; - struct wxDynamicObjectInternal; - wxDynamicObjectInternal *m_data; -}; -#endif +#include "wx/xti2.h" // ---------------------------------------------------------------------------- // more debugging macros @@ -461,20 +446,13 @@ private : #endif // wxUSE_DEBUG_NEW_ALWAYS // ---------------------------------------------------------------------------- -// Compatibility macro aliases +// Compatibility macro aliases IMPLEMENT group // ---------------------------------------------------------------------------- // deprecated variants _not_ requiring a semicolon after them and without wx prefix. // (note that also some wx-prefixed macro do _not_ require a semicolon because // it's not always possible to force the compire to require it) -#define DECLARE_CLASS_INFO_ITERATORS() wxDECLARE_CLASS_INFO_ITERATORS(); -#define DECLARE_ABSTRACT_CLASS(n) wxDECLARE_ABSTRACT_CLASS(n); -#define DECLARE_DYNAMIC_CLASS_NO_ASSIGN(n) wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(n); -#define DECLARE_DYNAMIC_CLASS_NO_COPY(n) wxDECLARE_DYNAMIC_CLASS_NO_COPY(n); -#define DECLARE_DYNAMIC_CLASS(n) wxDECLARE_DYNAMIC_CLASS(n); -#define DECLARE_CLASS(n) wxDECLARE_CLASS(n); - #define IMPLEMENT_DYNAMIC_CLASS(n,b) wxIMPLEMENT_DYNAMIC_CLASS(n,b) #define IMPLEMENT_DYNAMIC_CLASS2(n,b1,b2) wxIMPLEMENT_DYNAMIC_CLASS2(n,b1,b2) #define IMPLEMENT_ABSTRACT_CLASS(n,b) wxIMPLEMENT_ABSTRACT_CLASS(n,b) @@ -482,11 +460,6 @@ private : #define IMPLEMENT_CLASS(n,b) wxIMPLEMENT_CLASS(n,b) #define IMPLEMENT_CLASS2(n,b1,b2) wxIMPLEMENT_CLASS2(n,b1,b2) -#define DECLARE_PLUGGABLE_CLASS(n) wxDECLARE_PLUGGABLE_CLASS(n); -#define DECLARE_ABSTRACT_PLUGGABLE_CLASS(n) wxDECLARE_ABSTRACT_PLUGGABLE_CLASS(n); -#define DECLARE_USER_EXPORTED_PLUGGABLE_CLASS(n,u) wxDECLARE_USER_EXPORTED_PLUGGABLE_CLASS(n,u); -#define DECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,u) wxDECLARE_USER_EXPORTED_ABSTRACT_PLUGGABLE_CLASS(n,u); - #define IMPLEMENT_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_PLUGGABLE_CLASS(n,b) #define IMPLEMENT_PLUGGABLE_CLASS2(n,b,b2) wxIMPLEMENT_PLUGGABLE_CLASS2(n,b,b2) #define IMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(n,b) wxIMPLEMENT_ABSTRACT_PLUGGABLE_CLASS(n,b) diff --git a/include/wx/xti.h b/include/wx/xti.h index 75da3785c8..15abee18a2 100644 --- a/include/wx/xti.h +++ b/include/wx/xti.h @@ -21,7 +21,7 @@ // // - Type Information for categorizing built in types as well as custom types // this includes information about enums, their values and names -// - Type safe value storage : a kind of wxVariant, called right now wxVariantBase +// - Type safe value storage : a kind of wxVariant, called right now wxAny // which will be merged with wxVariant // - Property Information and Property Accessors providing access to a class' // values and exposed event delegates @@ -36,36 +36,66 @@ #if wxUSE_EXTENDED_RTTI -// include definitions of other XTI structures -#include "wx/variantbase.h" +class WXDLLIMPEXP_FWD_BASE wxAny; +class WXDLLIMPEXP_FWD_BASE wxAnyList; +class WXDLLIMPEXP_FWD_BASE wxObject; +class WXDLLIMPEXP_FWD_BASE wxString; +class WXDLLIMPEXP_FWD_BASE wxClassInfo; +class WXDLLIMPEXP_FWD_BASE wxHashTable; +class WXDLLIMPEXP_FWD_BASE wxObject; +class WXDLLIMPEXP_FWD_BASE wxPluginLibrary; +class WXDLLIMPEXP_FWD_BASE wxHashTable; +class WXDLLIMPEXP_FWD_BASE wxHashTable_Node; + +class WXDLLIMPEXP_FWD_BASE wxStringToAnyHashMap; +class WXDLLIMPEXP_FWD_BASE wxPropertyInfoMap; +class WXDLLIMPEXP_FWD_BASE wxPropertyAccessor; + +#define wx_dynamic_cast(t, x) dynamic_cast(x) + #include "wx/xtitypes.h" #include "wx/xtictor.h" -#include "wx/xtiprop.h" #include "wx/xtihandler.h" // ---------------------------------------------------------------------------- // wxClassInfo // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_BASE wxObject; -class WXDLLIMPEXP_BASE wxVariantBase; -class WXDLLIMPEXP_BASE wxVariantBaseArray; +class WXDLLIMPEXP_BASE wxObjectFunctor +{ +public: + virtual ~wxObjectFunctor(); + + // Invoke the actual event handler: + virtual void operator()(const wxObject *) = 0; +}; + +class WXDLLIMPEXP_FWD_BASE wxPropertyInfo; +class WXDLLIMPEXP_FWD_BASE wxHandlerInfo; typedef wxObject *(*wxObjectConstructorFn)(void); -typedef wxObject* (*wxVariantToObjectConverter)( wxVariantBase &data ); -typedef wxVariantBase (*wxObjectToVariantConverter)( wxObject* ); +typedef wxPropertyInfo *(*wxPropertyInfoFn)(void); +typedef wxHandlerInfo *(*wxHandlerInfoFn)(void); +typedef void (*wxVariantToObjectConverter)( const wxAny &data, wxObjectFunctor* fn ); +typedef wxObject* (*wxVariantToObjectPtrConverter) ( const wxAny& data); +typedef wxAny (*wxObjectToVariantConverter)( wxObject* ); + +WXDLLIMPEXP_BASE wxString wxAnyGetAsString( const wxAny& data); +WXDLLIMPEXP_BASE const wxObject* wxAnyGetAsObjectPtr( const wxAny& data); class WXDLLIMPEXP_BASE wxObjectWriter; -class WXDLLIMPEXP_BASE wxObjectReaderCallback; +class WXDLLIMPEXP_BASE wxObjectWriterCallback; typedef bool (*wxObjectStreamingCallback) ( const wxObject *, wxObjectWriter *, \ - wxObjectReaderCallback *, wxVariantBaseArray & ); + wxObjectWriterCallback *, const wxStringToAnyHashMap & ); + + class WXDLLIMPEXP_BASE wxClassInfo { friend class WXDLLIMPEXP_BASE wxPropertyInfo; friend class WXDLLIMPEXP_BASE wxHandlerInfo; - friend wxObject *wxCreateDynamicObject(const wxChar *name); + friend wxObject *wxCreateDynamicObject(const wxString& name); public: wxClassInfo(const wxClassInfo **_Parents, @@ -73,12 +103,12 @@ public: const wxChar *_ClassName, int size, wxObjectConstructorFn ctor, - wxPropertyInfo *_Props, - wxHandlerInfo *_Handlers, + wxPropertyInfoFn _Props, + wxHandlerInfoFn _Handlers, wxObjectAllocatorAndCreator* _Constructor, const wxChar ** _ConstructorProperties, const int _ConstructorPropertiesCount, - wxVariantToObjectConverter _PtrConverter1, + wxVariantToObjectPtrConverter _PtrConverter1, wxVariantToObjectConverter _Converter2, wxObjectToVariantConverter _Converter3, wxObjectStreamingCallback _streamingCallback = NULL) : @@ -86,8 +116,11 @@ public: m_objectSize(size), m_objectConstructor(ctor), m_next(sm_first), - m_firstProperty(_Props), - m_firstHandler(_Handlers), + m_firstPropertyFn(_Props), + m_firstHandlerFn(_Handlers), + m_firstProperty(NULL), + m_firstHandler(NULL), + m_firstInited(false), m_parents(_Parents), m_unitName(_UnitName), m_constructor(_Constructor), @@ -108,8 +141,11 @@ public: m_objectSize(0), m_objectConstructor(NULL), m_next(sm_first), + m_firstPropertyFn(NULL), + m_firstHandlerFn(NULL), m_firstProperty(NULL), m_firstHandler(NULL), + m_firstInited(true), m_parents(_Parents), m_unitName(_UnitName), m_constructor(NULL), @@ -134,8 +170,11 @@ public: m_objectSize(size), m_objectConstructor(ctor), m_next(sm_first), + m_firstPropertyFn(NULL), + m_firstHandlerFn(NULL), m_firstProperty(NULL), m_firstHandler(NULL), + m_firstInited(true), m_parents(NULL), m_unitName(NULL), m_constructor(NULL), @@ -164,7 +203,7 @@ public: wxObject *CreateObject() const { return AllocateObject(); } // direct construction call for classes that cannot construct instances via alloc/create - wxObject *ConstructObject(int ParamCount, wxVariantBase *Params) const; + wxObject *ConstructObject(int ParamCount, wxAny *Params) const; bool NeedsDirectConstruction() const { return wx_dynamic_cast(wxObjectAllocator*, m_constructor) != NULL; } @@ -198,7 +237,7 @@ public: // statics: static void CleanUp(); - static wxClassInfo *FindClass(const wxChar *className); + static wxClassInfo *FindClass(const wxString& className); static const wxClassInfo *GetFirst() { return sm_first; } @@ -208,30 +247,30 @@ public: bool IsKindOf(const wxClassInfo *info) const; - wxDECLARE_CLASS_INFO_ITERATORS() + wxDECLARE_CLASS_INFO_ITERATORS(); // if there is a callback registered with that class it will be called // before this object will be written to disk, it can veto streaming out // this object by returning false, if this class has not registered a // callback, the search will go up the inheritance tree if no callback has // been registered true will be returned by default - bool BeforeWriteObject( const wxObject *obj, wxObjectWriter *streamer, \ - wxObjectReaderCallback *persister, wxVariantBaseArray &metadata) const; + bool BeforeWriteObject( const wxObject *obj, wxObjectWriter *streamer, + wxObjectWriterCallback *writercallback, const wxStringToAnyHashMap &metadata) const; // gets the streaming callback from this class or any superclass wxObjectStreamingCallback GetStreamingCallback() const; // returns the first property - const wxPropertyInfo* GetFirstProperty() const - { return m_firstProperty; } + wxPropertyInfo* GetFirstProperty() const + { EnsureInfosInited(); return m_firstProperty; } // returns the first handler - const wxHandlerInfo* GetFirstHandler() const - { return m_firstHandler; } + wxHandlerInfo* GetFirstHandler() const + { EnsureInfosInited(); return m_firstHandler; } // Call the Create upon an instance of the class, in the end the object is fully // initialized - virtual bool Create (wxObject *object, int ParamCount, wxVariantBase *Params) const; + virtual bool Create (wxObject *object, int ParamCount, wxAny *Params) const; // get number of parameters for constructor virtual int GetCreateParamCount() const @@ -244,27 +283,22 @@ public: // Runtime access to objects for simple properties (get/set) by property // name and variant data virtual void SetProperty (wxObject *object, const wxChar *propertyName, - const wxVariantBase &value) const; - virtual wxVariantBase GetProperty (wxObject *object, const wxChar *propertyName) const; + const wxAny &value) const; + virtual wxAny GetProperty (wxObject *object, const wxChar *propertyName) const; // Runtime access to objects for collection properties by property name - virtual wxVariantBaseArray GetPropertyCollection(wxObject *object, + virtual wxAnyList GetPropertyCollection(wxObject *object, const wxChar *propertyName) const; virtual void AddToPropertyCollection(wxObject *object, const wxChar *propertyName, - const wxVariantBase& value) const; + const wxAny& value) const; // we must be able to cast variants to wxObject pointers, templates seem // not to be suitable - wxObject* VariantToInstance( wxVariantBase &data ) const - { - if ( data.GetTypeInfo()->GetKind() == wxT_OBJECT ) - return m_variantToObjectConverter( data ); - else - return m_variantOfPtrToObjectConverter( data ); - } + void CallOnAny( const wxAny &data, wxObjectFunctor* functor ) const; + + wxObject* AnyToObjectPtr( const wxAny &data) const; - wxVariantBase InstanceToVariant( wxObject *object ) const - { return m_objectToVariantConverter( object ); } + wxAny ObjectPtrToAny( wxObject *object ) const; // find property by name virtual const wxPropertyInfo *FindPropertyInfo (const wxChar *PropertyName) const; @@ -295,9 +329,25 @@ private: static wxHashTable *sm_classTable; + wxPropertyInfoFn m_firstPropertyFn; + wxHandlerInfoFn m_firstHandlerFn; + + mutable bool m_firstInited; + protected: - wxPropertyInfo * m_firstProperty; - wxHandlerInfo * m_firstHandler; + void EnsureInfosInited() const + { + if ( !m_firstInited) + { + if ( m_firstPropertyFn != NULL) + m_firstProperty = (*m_firstPropertyFn)(); + if ( m_firstHandlerFn != NULL) + m_firstHandler = (*m_firstHandlerFn)(); + m_firstInited = true; + } + } + mutable wxPropertyInfo* m_firstProperty; + mutable wxHandlerInfo* m_firstHandler; private: const wxClassInfo** m_parents; @@ -306,7 +356,7 @@ private: wxObjectAllocatorAndCreator* m_constructor; const wxChar ** m_constructorProperties; const int m_constructorPropertiesCount; - wxVariantToObjectConverter m_variantOfPtrToObjectConverter; + wxVariantToObjectPtrConverter m_variantOfPtrToObjectConverter; wxVariantToObjectConverter m_variantToObjectConverter; wxObjectToVariantConverter m_objectToVariantConverter; wxObjectStreamingCallback m_streamingCallback; @@ -321,8 +371,7 @@ protected: DECLARE_NO_COPY_CLASS(wxClassInfo) }; -WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name); - +WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name); // ---------------------------------------------------------------------------- // wxDynamicClassInfo @@ -343,7 +392,7 @@ public: virtual wxObject *AllocateObject() const; // Call the Create method for a class - virtual bool Create (wxObject *object, int ParamCount, wxVariantBase *Params) const; + virtual bool Create (wxObject *object, int ParamCount, wxAny *Params) const; // get number of parameters for constructor virtual int GetCreateParamCount() const; @@ -353,8 +402,8 @@ public: // Runtime access to objects by property name, and variant data virtual void SetProperty (wxObject *object, const wxChar *PropertyName, - const wxVariantBase &Value) const; - virtual wxVariantBase GetProperty (wxObject *object, const wxChar *PropertyName) const; + const wxAny &Value) const; + virtual wxAny GetProperty (wxObject *object, const wxChar *PropertyName) const; // adds a property to this class at runtime void AddProperty( const wxChar *propertyName, const wxTypeInfo* typeInfo ); @@ -380,7 +429,6 @@ private: wxDynamicClassInfoInternal* m_data; }; - // ---------------------------------------------------------------------------- // wxDECLARE class macros // ---------------------------------------------------------------------------- @@ -403,210 +451,39 @@ private: _DECLARE_DYNAMIC_CLASS(name) #define wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(name) \ - wxDECLARE_NO_ASSIGN_CLASS(name) \ + wxDECLARE_NO_ASSIGN_CLASS(name); \ wxDECLARE_DYNAMIC_CLASS(name) #define wxDECLARE_DYNAMIC_CLASS_NO_COPY(name) \ - wxDECLARE_NO_COPY_CLASS(name) \ + wxDECLARE_NO_COPY_CLASS(name); \ + wxDECLARE_DYNAMIC_CLASS(name) + +#define wxDECLARE_CLASS(name) \ wxDECLARE_DYNAMIC_CLASS(name) #define wxDECLARE_ABSTRACT_CLASS(name) _DECLARE_DYNAMIC_CLASS(name) #define wxCLASSINFO(name) (&name::ms_classInfo) - -// ---------------------------------------------------------------------------- -// wxIMPLEMENT class macros for concrete classes -// ---------------------------------------------------------------------------- - -// Single inheritance with one base class - -#define _TYPEINFO_CLASSES(n, toString, fromString ) \ - wxClassTypeInfo s_typeInfo##n(wxT_OBJECT, &n::ms_classInfo, \ - toString, fromString, typeid(n).name()); \ - wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR, &n::ms_classInfo, \ - toString, fromString, typeid(n*).name()); - -#define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \ - wxObject* wxConstructorFor##name() \ - { return new name; } \ - wxObject* wxVariantOfPtrToObjectConverter##name ( wxVariantBase &data ) \ - { return data.wxTEMPLATED_MEMBER_CALL(Get, name*); } \ - wxVariantBase wxObjectToVariantConverter##name ( wxObject *data ) \ - { return wxVariantBase( wx_dynamic_cast(name*, data) ); } \ - \ - const wxClassInfo* name::ms_classParents[] = \ - { &basename::ms_classInfo, NULL }; \ - wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \ - wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \ - name::GetPropertiesStatic(), name::GetHandlersStatic(), name::ms_constructor, \ - name::ms_constructorProperties, name::ms_constructorPropertiesCount, \ - wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \ - callback); - -#define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \ - wxObject* wxConstructorFor##name() \ - { return new name; } \ - wxObject* wxVariantToObjectConverter##name ( wxVariantBase &data ) \ - { return &data.wxTEMPLATED_MEMBER_CALL(Get, name); } \ - wxObject* wxVariantOfPtrToObjectConverter##name ( wxVariantBase &data ) \ - { return data.wxTEMPLATED_MEMBER_CALL(Get, name*); } \ - wxVariantBase wxObjectToVariantConverter##name ( wxObject *data ) \ - { return wxVariantBase( wx_dynamic_cast(name*, data) ); } \ - \ - const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo,NULL }; \ - wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \ - wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \ - name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor, \ - name::ms_constructorProperties, name::ms_constructorPropertiesCount, \ - wxVariantOfPtrToObjectConverter##name, wxVariantToObjectConverter##name, \ - wxObjectToVariantConverter##name, callback); - -#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename ) \ - _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, "", NULL ) \ - _TYPEINFO_CLASSES(name, NULL, NULL) \ - const wxPropertyInfo *name::GetPropertiesStatic() \ - { return (wxPropertyInfo*) NULL; } \ - const wxHandlerInfo *name::GetHandlersStatic() \ - { return (wxHandlerInfo*) NULL; } \ - wxCONSTRUCTOR_DUMMY( name ) - -#define wxIMPLEMENT_DYNAMIC_CLASS( name, basename ) \ - _IMPLEMENT_DYNAMIC_CLASS( name, basename, "", NULL ) \ - _TYPEINFO_CLASSES(name, NULL, NULL) \ - wxPropertyInfo *name::GetPropertiesStatic() \ - { return (wxPropertyInfo*) NULL; } \ - wxHandlerInfo *name::GetHandlersStatic() \ - { return (wxHandlerInfo*) NULL; } \ - wxCONSTRUCTOR_DUMMY( name ) - -#define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \ - _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \ - _TYPEINFO_CLASSES(name, NULL, NULL) - -#define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback )\ - _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, &callback ) \ - _TYPEINFO_CLASSES(name, NULL, NULL) - -#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \ - _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \ - _TYPEINFO_CLASSES(name, NULL, NULL) - -#define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \ - unit, toString, \ - fromString ) \ - _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \ - _TYPEINFO_CLASSES(name, toString, fromString) - -// this is for classes that do not derive from wxObject, there are no creators for these - -#define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) \ - const wxClassInfo* name::ms_classParents[] = { NULL }; \ - wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \ - wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \ - name::GetPropertiesStatic(),name::GetHandlersStatic(), 0, 0, \ - 0, 0, 0 ); \ - _TYPEINFO_CLASSES(name, NULL, NULL) - -// this is for subclasses that still do not derive from wxObject - -#define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) \ - const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo, NULL }; \ - wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \ - wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \ - name::GetPropertiesStatic(),name::GetHandlersStatic(), 0, 0, \ - 0, 0, 0 ); \ - _TYPEINFO_CLASSES(name, NULL, NULL) - - -// Multiple inheritance with two base classes - -#define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \ - wxObject* wxConstructorFor##name() { return new name; } \ - wxObject* wxVariantOfPtrToObjectConverter##name ( wxVariantBase &data ) \ - { return data.wxTEMPLATED_MEMBER_CALL(Get, name*); } \ - wxVariantBase wxObjectToVariantConverter##name ( wxObject *data ) \ - { return wxVariantBase( wx_dynamic_cast(name*, data) ); } \ - \ - const wxClassInfo* name::ms_classParents[] = \ - { &basename::ms_classInfo,&basename2::ms_classInfo, NULL }; \ - wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \ - wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \ - name::GetPropertiesStatic(),name::GetHandlersStatic(),name::ms_constructor, \ - name::ms_constructorProperties, name::ms_constructorPropertiesCount, \ - wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \ - callback); - -#define wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2) \ - _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, "", NULL) \ - _TYPEINFO_CLASSES(name, NULL, NULL) \ - wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } \ - wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \ - wxCONSTRUCTOR_DUMMY( name ) - -#define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) \ - _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, unit, NULL) \ - _TYPEINFO_CLASSES(name, NULL, NULL) - - - -// ---------------------------------------------------------------------------- -// wxIMPLEMENT class macros for abstract classes -// ---------------------------------------------------------------------------- - -// Single inheritance with one base class - -#define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \ - wxObject* wxVariantToObjectConverter##name ( wxVariantBase &data ) \ - { return data.wxTEMPLATED_MEMBER_CALL(Get, name*); } \ - wxObject* wxVariantOfPtrToObjectConverter##name ( wxVariantBase &data ) \ - { return data.wxTEMPLATED_MEMBER_CALL(Get, name*); } \ - wxVariantBase wxObjectToVariantConverter##name ( wxObject *data ) \ - { return wxVariantBase( wx_dynamic_cast(name*, data) ); } \ - \ - const wxClassInfo* name::ms_classParents[] = \ - { &basename::ms_classInfo,NULL }; \ - wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \ - wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \ - name::GetPropertiesStatic(),name::GetHandlersStatic(), 0, 0, \ - 0, wxVariantOfPtrToObjectConverter##name,wxVariantToObjectConverter##name, \ - wxObjectToVariantConverter##name); \ - _TYPEINFO_CLASSES(name, NULL, NULL) - -#define wxIMPLEMENT_ABSTRACT_CLASS( name, basename ) \ - _IMPLEMENT_ABSTRACT_CLASS( name, basename ) \ - wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \ - wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } - -// Multiple inheritance with two base classes - -#define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \ - wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \ - wxT(#basename2), (int) sizeof(name), \ - (wxObjectConstructorFn) 0); - - - // -------------------------------------------------------------------------- // Collection Support // -------------------------------------------------------------------------- -template void wxListCollectionToVariantArray( - const collection_t& coll, wxVariantBaseArray &value ) +template void wxListCollectionToAnyList( + const collection_t& coll, wxAnyList &value ) { - iter current = coll.GetFirst(); - while (current) + for ( collection_t::compatibility_iterator current = coll.GetFirst(); current; + current = current->GetNext() ) { - value.Add( new wxVariantBase(current->GetData()) ); - current = current->GetNext(); + value.Append( new wxAny(current->GetData()) ); } } template void wxArrayCollectionToVariantArray( - const collection_t& coll, wxVariantBaseArray &value ) + const collection_t& coll, wxAnyList &value ) { for( size_t i = 0; i < coll.GetCount(); i++ ) { - value.Add( new wxVariantBase(coll[i]) ); + value.Append( new wxAny(coll[i]) ); } } diff --git a/include/wx/xtistrm.h b/include/wx/xtistrm.h index acfce43942..98917ca6ab 100644 --- a/include/wx/xtistrm.h +++ b/include/wx/xtistrm.h @@ -16,7 +16,6 @@ #if wxUSE_EXTENDED_RTTI -#include "wx/string.h" #include "wx/object.h" const int wxInvalidObjectID = -2; @@ -26,13 +25,13 @@ const int wxNullObjectID = -3; // rendering them either to objects in memory, or to code. Note: We // consider the process of generating code to be one of *depersisting* the // object from xml, *not* of persisting the object to code from an object -// in memory. This distincation can be confusing, and should be kept +// in memory. This distinction can be confusing, and should be kept // in mind when looking at the property streamers and callback interfaces // listed below. // ---------------------------------------------------------------------------- -// wxObjectReaderCallback +// wxObjectWriterCallback // // This class will be asked during the streaming-out process about every single // property or object instance. It can veto streaming out by returning false @@ -42,22 +41,22 @@ const int wxNullObjectID = -3; class WXDLLIMPEXP_BASE wxObjectWriter; class WXDLLIMPEXP_BASE wxObjectReader; class WXDLLIMPEXP_BASE wxClassInfo; -class WXDLLIMPEXP_BASE wxVariantBaseArray; +class WXDLLIMPEXP_BASE wxAnyList; class WXDLLIMPEXP_BASE wxPropertyInfo; -class WXDLLIMPEXP_BASE wxVariantBase; +class WXDLLIMPEXP_BASE wxAny; class WXDLLIMPEXP_BASE wxObjectWriter; class WXDLLIMPEXP_BASE wxHandlerInfo; -class WXDLLIMPEXP_BASE wxObjectReaderCallback +class WXDLLIMPEXP_BASE wxObjectWriterCallback { public: - virtual ~wxObjectReaderCallback() {} + virtual ~wxObjectWriterCallback() {} // will be called before an object is written, may veto by returning false virtual bool BeforeWriteObject( wxObjectWriter *WXUNUSED(writer), const wxObject *WXUNUSED(object), const wxClassInfo *WXUNUSED(classInfo), - wxVariantBaseArray &WXUNUSED(metadata)) + const wxStringToAnyHashMap &WXUNUSED(metadata)) { return true; } // will be called after this object has been written, may be @@ -73,7 +72,7 @@ public: virtual bool BeforeWriteProperty( wxObjectWriter *WXUNUSED(writer), const wxObject *WXUNUSED(object), const wxPropertyInfo *WXUNUSED(propInfo), - wxVariantBase &WXUNUSED(value) ) + const wxAny &WXUNUSED(value) ) { return true; } // will be called before a property gets written, may change the value, @@ -82,7 +81,7 @@ public: virtual bool BeforeWriteProperty( wxObjectWriter *WXUNUSED(writer), const wxObject *WXUNUSED(object), const wxPropertyInfo *WXUNUSED(propInfo), - wxVariantBaseArray &WXUNUSED(value) ) + const wxAnyList &WXUNUSED(value) ) { return true; } // will be called after a property has been written out, may be needed @@ -109,16 +108,21 @@ public: { } }; +class WXDLLIMPEXP_BASE wxObjectWriterFunctor: public wxObjectFunctor +{ +}; + class WXDLLIMPEXP_BASE wxObjectWriter: public wxObject { + friend class wxObjectWriterFunctor; public: wxObjectWriter(); virtual ~wxObjectWriter(); // with this call you start writing out a new top-level object void WriteObject(const wxObject *object, const wxClassInfo *classInfo, - wxObjectReaderCallback *persister, const wxString &name, - wxVariantBaseArray &WXUNUSED(metadata)); + wxObjectWriterCallback *writercallback, const wxString &name, + const wxStringToAnyHashMap &metadata); // Managing the object identity table a.k.a context // @@ -147,7 +151,7 @@ public: // start of writing an object having the passed in ID virtual void DoBeginWriteObject(const wxObject *object, const wxClassInfo *classInfo, - int objectID, wxVariantBaseArray &metadata ) = 0; + int objectID, const wxStringToAnyHashMap &metadata ) = 0; // end of writing an toplevel object name param is used for unique // identification within the container @@ -155,7 +159,7 @@ public: const wxClassInfo *classInfo, int objectID ) = 0; // writes a simple property in the stream format - virtual void DoWriteSimpleType( wxVariantBase &value ) = 0; + virtual void DoWriteSimpleType( const wxAny &value ) = 0; // start of writing a complex property into the stream ( virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ) = 0; @@ -177,22 +181,23 @@ public: int sinkObjectID, const wxClassInfo* eventSinkClassInfo, const wxHandlerInfo* handlerIndo ) = 0; -private: + void WriteObject(const wxObject *object, const wxClassInfo *classInfo, + wxObjectWriterCallback *writercallback, bool isEmbedded, const wxStringToAnyHashMap &metadata ); + +protected: struct wxObjectWriterInternal; wxObjectWriterInternal* m_data; struct wxObjectWriterInternalPropertiesData; void WriteAllProperties( const wxObject * obj, const wxClassInfo* ci, - wxObjectReaderCallback *persister, + wxObjectWriterCallback *writercallback, wxObjectWriterInternalPropertiesData * data ); void WriteOneProperty( const wxObject *obj, const wxClassInfo* ci, - const wxPropertyInfo* pi, wxObjectReaderCallback *persister, + const wxPropertyInfo* pi, wxObjectWriterCallback *writercallback, wxObjectWriterInternalPropertiesData *data ); - void WriteObject(const wxObject *object, const wxClassInfo *classInfo, - wxObjectReaderCallback *persister, bool isEmbedded, wxVariantBaseArray &metadata ); void FindConnectEntry(const wxEvtHandler * evSource, const wxEventSourceTypeInfo* dti, const wxObject* &sink, @@ -204,11 +209,11 @@ private: Streaming callbacks for depersisting XML to code, or running objects */ -class WXDLLIMPEXP_BASE wxObjectWriterCallback; +class WXDLLIMPEXP_BASE wxObjectReaderCallback; /* wxObjectReader handles streaming in a class from a arbitrary format. -While walking through it issues calls out to interfaces to depersist +While walking through it issues calls out to interfaces to readercallback the guts from the underlying storage format. */ @@ -228,7 +233,7 @@ public: // then be used to ask the depersister about that object // if there was a problem you will get back wxInvalidObjectID and the current // error log will carry the problems encoutered - virtual int ReadObject( const wxString &name, wxObjectWriterCallback *depersist ) = 0; + virtual int ReadObject( const wxString &name, wxObjectReaderCallback *readercallback ) = 0; private: struct wxObjectReaderInternal; @@ -240,14 +245,14 @@ private: // When generating code, these will just create statements of C++ // code to create the objects. -class WXDLLIMPEXP_BASE wxObjectWriterCallback +class WXDLLIMPEXP_BASE wxObjectReaderCallback { public: - virtual ~wxObjectWriterCallback() {} + virtual ~wxObjectReaderCallback() {} // allocate the new object on the heap, that object will have the passed in ID virtual void AllocateObject(int objectID, wxClassInfo *classInfo, - wxVariantBaseArray &metadata) = 0; + wxStringToAnyHashMap &metadata) = 0; // initialize the already allocated object having the ID objectID with the Create method // creation parameters which are objects are having their Ids passed in objectIDValues @@ -256,10 +261,10 @@ public: virtual void CreateObject(int objectID, const wxClassInfo *classInfo, int paramCount, - wxVariantBase *VariantValues, + wxAny *VariantValues, int *objectIDValues, const wxClassInfo **objectClassInfos, - wxVariantBaseArray &metadata) = 0; + wxStringToAnyHashMap &metadata) = 0; // construct the new object on the heap, that object will have the passed in ID // (for objects that don't support allocate-create type of creation) @@ -269,10 +274,10 @@ public: virtual void ConstructObject(int objectID, const wxClassInfo *classInfo, int paramCount, - wxVariantBase *VariantValues, + wxAny *VariantValues, int *objectIDValues, const wxClassInfo **objectClassInfos, - wxVariantBaseArray &metadata) = 0; + wxStringToAnyHashMap &metadata) = 0; // destroy the heap-allocated object having the ID objectID, this may be used // if an object is embedded in another object and set via value semantics, @@ -283,7 +288,7 @@ public: virtual void SetProperty(int objectID, const wxClassInfo *classInfo, const wxPropertyInfo* propertyInfo, - const wxVariantBase &VariantValue) = 0; + const wxAny &VariantValue) = 0; // sets the corresponding property (value is an object) virtual void SetPropertyAsObject(int objectID, @@ -295,7 +300,7 @@ public: virtual void AddToPropertyCollection( int objectID, const wxClassInfo *classInfo, const wxPropertyInfo* propertyInfo, - const wxVariantBase &VariantValue) = 0; + const wxAny &VariantValue) = 0; // sets the corresponding property (value is an object) virtual void AddToPropertyCollectionAsObject(int objectID, @@ -313,12 +318,11 @@ public: }; /* -wxObjectRuntimeReaderCallback implements the callbacks that will depersist -an object into a running memory image, as opposed to writing -C++ initialization code to bring the object to life. +wxObjectRuntimeReaderCallback implements the callbacks that will bring back +an object into a life memory instance */ -class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback: public wxObjectWriterCallback +class WXDLLIMPEXP_BASE wxObjectRuntimeReaderCallback: public wxObjectReaderCallback { struct wxObjectRuntimeReaderCallbackInternal; wxObjectRuntimeReaderCallbackInternal * m_data; @@ -332,7 +336,7 @@ public: // allocate the new object on the heap, that object will have the passed in ID virtual void AllocateObject(int objectID, wxClassInfo *classInfo, - wxVariantBaseArray &metadata); + wxStringToAnyHashMap &metadata); // initialize the already allocated object having the ID objectID with // the Create method creation parameters which are objects are having @@ -341,10 +345,10 @@ public: virtual void CreateObject(int objectID, const wxClassInfo *classInfo, int paramCount, - wxVariantBase *VariantValues, + wxAny *VariantValues, int *objectIDValues, const wxClassInfo **objectClassInfos, - wxVariantBaseArray &metadata + wxStringToAnyHashMap &metadata ); // construct the new object on the heap, that object will have the @@ -355,10 +359,10 @@ public: virtual void ConstructObject(int objectID, const wxClassInfo *classInfo, int paramCount, - wxVariantBase *VariantValues, + wxAny *VariantValues, int *objectIDValues, const wxClassInfo **objectClassInfos, - wxVariantBaseArray &metadata); + wxStringToAnyHashMap &metadata); // destroy the heap-allocated object having the ID objectID, this may be // used if an object is embedded in another object and set via value semantics, @@ -369,7 +373,7 @@ public: virtual void SetProperty(int objectID, const wxClassInfo *classInfo, const wxPropertyInfo* propertyInfo, - const wxVariantBase &variantValue); + const wxAny &variantValue); // sets the corresponding property (value is an object) virtual void SetPropertyAsObject(int objectId, @@ -381,7 +385,7 @@ public: virtual void AddToPropertyCollection( int objectID, const wxClassInfo *classInfo, const wxPropertyInfo* propertyInfo, - const wxVariantBase &VariantValue); + const wxAny &VariantValue); // sets the corresponding property (value is an object) virtual void AddToPropertyCollectionAsObject(int objectID, diff --git a/include/wx/xtixml.h b/include/wx/xtixml.h index f11b4ec0be..aace527aaf 100644 --- a/include/wx/xtixml.h +++ b/include/wx/xtixml.h @@ -23,7 +23,7 @@ class WXDLLIMPEXP_XML wxXmlNode; class WXDLLIMPEXP_BASE wxPropertyInfo; class WXDLLIMPEXP_BASE wxObject; class WXDLLIMPEXP_BASE wxClassInfo; -class WXDLLIMPEXP_BASE wxVariantBaseArray; +class WXDLLIMPEXP_BASE wxAnyList; class WXDLLIMPEXP_BASE wxHandlerInfo; class WXDLLIMPEXP_BASE wxObjectWriterCallback; @@ -53,7 +53,7 @@ public: // start of writing an object having the passed in ID virtual void DoBeginWriteObject(const wxObject *object, - const wxClassInfo *classInfo, int objectID, wxVariantBaseArray &metadata ); + const wxClassInfo *classInfo, int objectID, const wxStringToAnyHashMap &metadata ); // end of writing an toplevel object name param is used for unique // identification within the container @@ -61,7 +61,7 @@ public: const wxClassInfo *classInfo, int objectID ); // writes a simple property in the stream format - virtual void DoWriteSimpleType( wxVariantBase &value ); + virtual void DoWriteSimpleType( const wxAny &value ); // start of writing a complex property into the stream ( virtual void DoBeginWriteProperty( const wxPropertyInfo *propInfo ); @@ -100,15 +100,15 @@ public: virtual ~wxObjectXmlReader() {} // Reads a component from XML. The return value is the root object ID, which can - // then be used to ask the depersister about that object + // then be used to ask the readercallback about that object - virtual int ReadObject( const wxString &name, wxObjectWriterCallback *depersist ); + virtual int ReadObject( const wxString &name, wxObjectReaderCallback *readercallback ); private: - int ReadComponent(wxXmlNode *parent, wxObjectWriterCallback *callbacks); + int ReadComponent(wxXmlNode *parent, wxObjectReaderCallback *callbacks); // read the content of this node (simple type) and return the corresponding value - wxVariantBase ReadValue(wxXmlNode *Node, const wxTypeInfo *type ); + wxAny ReadValue(wxXmlNode *Node, const wxTypeInfo *type ); wxXmlNode * m_parent; };