X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7db064f60f2d60bcfea44a9973a18e6c2bf2161d..b02dd12239c8a59b9a545d9fcb04974f8ad02c6b:/include/wx/typeinfo.h diff --git a/include/wx/typeinfo.h b/include/wx/typeinfo.h index c1efb1b0c9..734783af50 100644 --- a/include/wx/typeinfo.h +++ b/include/wx/typeinfo.h @@ -14,15 +14,30 @@ // // This file defines wxTypeId macro that should be used internally in // wxWidgets instead of typeid(), for compatibility with builds that do -// not implement C++ RTTI. Also, type defining macros in this file are also +// not implement C++ RTTI. Also, type defining macros in this file are // intended for internal use only at this time and may change in future // versions. // +// The reason why we need this simple RTTI system in addition to the older +// wxObject-based one is that the latter does not work in template +// classes. +// #include "wx/defs.h" #ifndef wxNO_RTTI +// +// Let's trust that Visual C++ versions 9.0 and later implement C++ +// RTTI well enough, so we can use it and work around harmless memory +// leaks reported by the static run-time libraries. +// +#if wxCHECK_VISUALC_VERSION(9) + #define wxTRUST_CPP_RTTI 1 +#else + #define wxTRUST_CPP_RTTI 0 +#endif + #include #include @@ -32,6 +47,12 @@ #define WX_DEFINE_TYPEINFO(CLS) #define WX_DECLARE_ABSTRACT_TYPEINFO(CLS) +#if wxTRUST_CPP_RTTI + +#define wxTypeId typeid + +#else /* !wxTRUST_CPP_RTTI */ + // // For improved type-safety, let's make the check using class name // comparison. Most modern compilers already do this, but we cannot @@ -40,20 +61,20 @@ // wxTypeId could of course simply be defined as typeid. // -class wxTypeInfo +class wxTypeIdentifier { public: - wxTypeInfo(const char* className) + wxTypeIdentifier(const char* className) { m_className = className; } - bool operator==(const wxTypeInfo& other) + bool operator==(const wxTypeIdentifier& other) { return strcmp(m_className, other.m_className) == 0; } - bool operator!=(const wxTypeInfo& other) + bool operator!=(const wxTypeIdentifier& other) { return strcmp(m_className, other.m_className) != 0; } @@ -61,10 +82,14 @@ private: const char* m_className; }; -#define wxTypeId(OBJ) wxTypeInfo(typeid(OBJ).name()) +#define wxTypeId(OBJ) wxTypeIdentifier(typeid(OBJ).name()) + +#endif /* wxTRUST_CPP_RTTI/!wxTRUST_CPP_RTTI */ #else // if !wxNO_RTTI +#define wxTRUST_CPP_RTTI 0 + // // When C++ RTTI is not available, we will have to make the type comparison // using pointer to a dummy static member function. This will fail if @@ -112,7 +137,7 @@ _WX_DECLARE_TYPEINFO_CUSTOM(CLS, sm_wxClassInfo) #define wxTypeId(OBJ) (OBJ).GetWxTypeId() -// Because abstract classes cannot be instantiated, we use +// Because abstract classes cannot be instantiated, we use // this macro to define pure virtual type interface for them. #define WX_DECLARE_ABSTRACT_TYPEINFO(CLS) \ public: \