xti2.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/wxt2.h
  3. // Purpose: runtime metadata information (extended class info)
  4. // Author: Stefan Csomor
  5. // Modified by: Francesco Montorsi
  6. // Created: 27/07/03
  7. // Copyright: (c) 1997 Julian Smart
  8. // (c) 2003 Stefan Csomor
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_XTI2H__
  11. #define _WX_XTI2H__
  12. // ----------------------------------------------------------------------------
  13. // second part of xti headers, is included from object.h
  14. // ----------------------------------------------------------------------------
  15. #if wxUSE_EXTENDED_RTTI
  16. // ----------------------------------------------------------------------------
  17. // wxDynamicObject class, its instances connect to a 'super class instance'
  18. // ----------------------------------------------------------------------------
  19. class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject
  20. {
  21. friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo ;
  22. public:
  23. // instantiates this object with an instance of its superclass
  24. wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ;
  25. virtual ~wxDynamicObject();
  26. void SetProperty (const wxChar *propertyName, const wxAny &value);
  27. wxAny GetProperty (const wxChar *propertyName) const ;
  28. // get the runtime identity of this object
  29. wxClassInfo *GetClassInfo() const
  30. {
  31. #ifdef _MSC_VER
  32. return (wxClassInfo*) m_classInfo;
  33. #else
  34. wxDynamicClassInfo *nonconst = const_cast<wxDynamicClassInfo *>(m_classInfo);
  35. return static_cast<wxClassInfo *>(nonconst);
  36. #endif
  37. }
  38. wxObject* GetSuperClassInstance() const
  39. {
  40. return m_superClassInstance ;
  41. }
  42. private :
  43. // removes an existing runtime-property
  44. void RemoveProperty( const wxChar *propertyName ) ;
  45. // renames an existing runtime-property
  46. void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ;
  47. wxObject *m_superClassInstance ;
  48. const wxDynamicClassInfo *m_classInfo;
  49. struct wxDynamicObjectInternal;
  50. wxDynamicObjectInternal *m_data;
  51. };
  52. // ----------------------------------------------------------------------------
  53. // String conversion templates supporting older compilers
  54. // ----------------------------------------------------------------------------
  55. #if wxUSE_FUNC_TEMPLATE_POINTER
  56. # define wxTO_STRING(type) wxToStringConverter<type>
  57. # define wxTO_STRING_IMP(type)
  58. # define wxFROM_STRING(type) wxFromStringConverter<type>
  59. # define wxFROM_STRING_IMP(type)
  60. #else
  61. # define wxTO_STRING(type) ToString##type
  62. # define wxTO_STRING_IMP(type) \
  63. inline void ToString##type( const wxAny& data, wxString &result ) \
  64. { wxToStringConverter<type>(data, result); }
  65. # define wxFROM_STRING(type) FromString##type
  66. # define wxFROM_STRING_IMP(type) \
  67. inline void FromString##type( const wxString& data, wxAny &result ) \
  68. { wxFromStringConverter<type>(data, result); }
  69. #endif
  70. #include "wx/xtiprop.h"
  71. #include "wx/xtictor.h"
  72. // ----------------------------------------------------------------------------
  73. // wxIMPLEMENT class macros for concrete classes
  74. // ----------------------------------------------------------------------------
  75. // Single inheritance with one base class
  76. #define _DEFAULT_CONSTRUCTOR(name) \
  77. wxObject* wxConstructorFor##name() \
  78. { return new name; }
  79. #define _DEFAULT_CONVERTERS(name) \
  80. wxObject* wxVariantOfPtrToObjectConverter##name ( const wxAny &data ) \
  81. { return data.As( (name**)NULL ); } \
  82. wxAny wxObjectToVariantConverter##name ( wxObject *data ) \
  83. { return wxAny( wx_dynamic_cast(name*, data) ); }
  84. #define _TYPEINFO_CLASSES(n, toString, fromString ) \
  85. wxClassTypeInfo s_typeInfo##n(wxT_OBJECT, &n::ms_classInfo, \
  86. toString, fromString, typeid(n).name()); \
  87. wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR, &n::ms_classInfo, \
  88. toString, fromString, typeid(n*).name());
  89. #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \
  90. _DEFAULT_CONSTRUCTOR(name) \
  91. _DEFAULT_CONVERTERS(name) \
  92. \
  93. const wxClassInfo* name::ms_classParents[] = \
  94. { &basename::ms_classInfo, NULL }; \
  95. wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
  96. wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
  97. name::GetPropertiesStatic, name::GetHandlersStatic, name::ms_constructor, \
  98. name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
  99. wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
  100. callback);
  101. #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
  102. _DEFAULT_CONSTRUCTOR(name) \
  103. _DEFAULT_CONVERTERS(name) \
  104. void wxVariantToObjectConverter##name ( const wxAny &data, wxObjectFunctor* fn ) \
  105. { name o = wxANY_AS(data, name); (*fn)( &o ); } \
  106. \
  107. const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo,NULL }; \
  108. wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
  109. wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
  110. name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
  111. name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
  112. wxVariantOfPtrToObjectConverter##name, wxVariantToObjectConverter##name, \
  113. wxObjectToVariantConverter##name, callback);
  114. #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename ) \
  115. _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, "", NULL ) \
  116. _TYPEINFO_CLASSES(name, NULL, NULL) \
  117. const wxPropertyInfo *name::GetPropertiesStatic() \
  118. { return (wxPropertyInfo*) NULL; } \
  119. const wxHandlerInfo *name::GetHandlersStatic() \
  120. { return (wxHandlerInfo*) NULL; } \
  121. wxCONSTRUCTOR_DUMMY( name )
  122. #define wxIMPLEMENT_DYNAMIC_CLASS( name, basename ) \
  123. _IMPLEMENT_DYNAMIC_CLASS( name, basename, "", NULL ) \
  124. _TYPEINFO_CLASSES(name, NULL, NULL) \
  125. wxPropertyInfo *name::GetPropertiesStatic() \
  126. { return (wxPropertyInfo*) NULL; } \
  127. wxHandlerInfo *name::GetHandlersStatic() \
  128. { return (wxHandlerInfo*) NULL; } \
  129. wxCONSTRUCTOR_DUMMY( name )
  130. #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
  131. _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \
  132. _TYPEINFO_CLASSES(name, NULL, NULL)
  133. #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback )\
  134. _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, &callback ) \
  135. _TYPEINFO_CLASSES(name, NULL, NULL)
  136. #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
  137. _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
  138. _TYPEINFO_CLASSES(name, NULL, NULL)
  139. #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
  140. unit, toString, \
  141. fromString ) \
  142. _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
  143. _TYPEINFO_CLASSES(name, toString, fromString)
  144. // this is for classes that do not derive from wxObject, there are no creators for these
  145. #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) \
  146. const wxClassInfo* name::ms_classParents[] = { NULL }; \
  147. wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
  148. wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
  149. name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
  150. 0, 0, 0 ); \
  151. _TYPEINFO_CLASSES(name, NULL, NULL)
  152. // this is for subclasses that still do not derive from wxObject
  153. #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) \
  154. const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo, NULL }; \
  155. wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
  156. wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
  157. name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
  158. 0, 0, 0 ); \
  159. _TYPEINFO_CLASSES(name, NULL, NULL)
  160. // Multiple inheritance with two base classes
  161. #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
  162. _DEFAULT_CONSTRUCTOR(name) \
  163. _DEFAULT_CONVERTERS(name) \
  164. \
  165. const wxClassInfo* name::ms_classParents[] = \
  166. { &basename::ms_classInfo,&basename2::ms_classInfo, NULL }; \
  167. wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
  168. wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
  169. name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
  170. name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
  171. wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
  172. callback);
  173. #define wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2) \
  174. _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, "", NULL) \
  175. _TYPEINFO_CLASSES(name, NULL, NULL) \
  176. wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } \
  177. wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
  178. wxCONSTRUCTOR_DUMMY( name )
  179. #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) \
  180. _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, unit, NULL) \
  181. _TYPEINFO_CLASSES(name, NULL, NULL)
  182. // ----------------------------------------------------------------------------
  183. // wxIMPLEMENT class macros for abstract classes
  184. // ----------------------------------------------------------------------------
  185. // Single inheritance with one base class
  186. #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
  187. _DEFAULT_CONVERTERS(name) \
  188. \
  189. const wxClassInfo* name::ms_classParents[] = \
  190. { &basename::ms_classInfo,NULL }; \
  191. wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
  192. wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
  193. name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
  194. 0, wxVariantOfPtrToObjectConverter##name,0, \
  195. wxObjectToVariantConverter##name); \
  196. _TYPEINFO_CLASSES(name, NULL, NULL)
  197. #define wxIMPLEMENT_ABSTRACT_CLASS( name, basename ) \
  198. _IMPLEMENT_ABSTRACT_CLASS( name, basename ) \
  199. wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
  200. wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; }
  201. // Multiple inheritance with two base classes
  202. #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
  203. wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
  204. wxT(#basename2), (int) sizeof(name), \
  205. (wxObjectConstructorFn) 0);
  206. // templated streaming, every type that can be converted to wxString
  207. // must have their specialization for these methods
  208. template<typename T>
  209. void wxStringReadValue( const wxString &s, T &data );
  210. template<typename T>
  211. void wxStringWriteValue( wxString &s, const T &data);
  212. template<typename T>
  213. void wxToStringConverter( const wxAny &v, wxString &s )
  214. { wxStringWriteValue(s, wxANY_AS(v, T)); }
  215. template<typename T>
  216. void wxFromStringConverter( const wxString &s, wxAny &v)
  217. { T d; wxStringReadValue(s, d); v = wxAny(d); }
  218. // --------------------------------------------------------------------------
  219. // Collection Support
  220. // --------------------------------------------------------------------------
  221. template<typename iter, typename collection_t > void wxListCollectionToAnyList(
  222. const collection_t& coll, wxAnyList &value )
  223. {
  224. for ( iter current = coll.GetFirst(); current;
  225. current = current->GetNext() )
  226. {
  227. value.Append( new wxAny(current->GetData()) );
  228. }
  229. }
  230. template<typename collection_t> void wxArrayCollectionToVariantArray(
  231. const collection_t& coll, wxAnyList &value )
  232. {
  233. for( size_t i = 0; i < coll.GetCount(); i++ )
  234. {
  235. value.Append( new wxAny(coll[i]) );
  236. }
  237. }
  238. #endif
  239. #endif // _WX_XTIH2__