X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/27db95f05459cad75e705f15750bf4d7d7666713..ab94455525efa69b50b013ed876a82afb22aacae:/src/common/object.cpp diff --git a/src/common/object.cpp b/src/common/object.cpp index b3c4367ad7..212f195a28 100644 --- a/src/common/object.cpp +++ b/src/common/object.cpp @@ -22,7 +22,8 @@ #endif #ifndef WX_PRECOMP -#include "wx/hash.h" + #include "wx/hash.h" + #include "wx/object.h" #endif #include @@ -43,10 +44,44 @@ #endif #endif // __WXDEBUG__ || wxUSE_DEBUG_CONTEXT +// we must disable optimizations for VC.NET because otherwise its too eager +// linker discards wxClassInfo objects in release build thus breaking many, +// many things +#if defined __VISUALC__ && __VISUALC__ >= 1300 + #pragma optimize("", off) +#endif +#if wxUSE_EXTENDED_RTTI +const wxClassInfo* wxObject::sm_classParentswxObject[] = { NULL } ; + wxObject* wxVariantToObjectConverterwxObject ( wxxVariant &data ) +{ return data.Get() ; } + wxObject* wxVariantOfPtrToObjectConverterwxObject ( wxxVariant &data ) +{ return &data.Get() ; } + wxxVariant wxObjectToVariantConverterwxObject ( wxObject *data ) + { return wxxVariant( dynamic_cast (data) ) ; } + wxClassInfo wxObject::sm_classwxObject(sm_classParentswxObject , wxT("") , wxT("wxObject"), + (int) sizeof(wxObject), \ + (wxObjectConstructorFn) 0 , + (wxPropertyInfo*) NULL,(wxHandlerInfo*) NULL,0 , 0 , + 0 , wxVariantOfPtrToObjectConverterwxObject , wxVariantToObjectConverterwxObject , wxObjectToVariantConverterwxObject); + template<> void wxStringReadValue(const wxString & , wxObject * & ){assert(0) ;} + template<> void wxStringWriteValue(wxString & , wxObject* const & ){assert(0) ;} + template<> void wxStringReadValue(const wxString & , wxObject & ){assert(0) ;} + template<> void wxStringWriteValue(wxString & , wxObject const & ){assert(0) ;} + template<> const wxTypeInfo* wxGetTypeInfo( wxObject ** ) + { static wxClassTypeInfo s_typeInfo(wxT_OBJECT_PTR , &wxObject::sm_classwxObject) ; return &s_typeInfo ; } + template<> const wxTypeInfo* wxGetTypeInfo( wxObject * ) + { static wxClassTypeInfo s_typeInfo(wxT_OBJECT , &wxObject::sm_classwxObject) ; return &s_typeInfo ; } +#else wxClassInfo wxObject::sm_classwxObject( wxT("wxObject"), 0, 0, (int) sizeof(wxObject), (wxObjectConstructorFn) 0 ); +#endif + +// restore optimizations +#if defined __VISUALC__ && __VISUALC__ >= 1300 + #pragma optimize("", on) +#endif wxClassInfo* wxClassInfo::sm_first = NULL; wxHashTable* wxClassInfo::sm_classTable = NULL; @@ -159,6 +194,7 @@ wxClassInfo::~wxClassInfo() info = info->m_next; } } + Unregister(); } wxClassInfo *wxClassInfo::FindClass(const wxChar *className) @@ -179,30 +215,6 @@ wxClassInfo *wxClassInfo::FindClass(const wxChar *className) } } -// a tiny InitializeClasses() helper -/* static */ -inline wxClassInfo *wxClassInfo::GetBaseByName(const wxChar *name) -{ - if ( !name ) - return NULL; - - wxClassInfo *classInfo = (wxClassInfo *)sm_classTable->Get(name); - -#ifdef __WXDEBUG__ - // this must be fixed, other things will work wrongly later if you get this - if ( !classInfo ) - { - wxFAIL_MSG( wxString::Format - ( - _T("base class '%s' is unknown to wxWindows RTTI"), - name - ) ); - } -#endif // __WXDEBUG__ - - return classInfo; -} - // Set pointers to base class(es) to speed up IsKindOf void wxClassInfo::InitializeClasses() { @@ -217,28 +229,24 @@ void wxClassInfo::InitializeClasses() size_t nClass = 0; #endif - sm_classTable = new wxHashTable(wxKEY_STRING); - - // Index all class infos by their class name - - wxClassInfo *info; - for(info = sm_first; info; info = info->m_next) + // Do this initialization only once, because classes are added + // automatically if + if ( sm_classTable == NULL ) { - if (info->m_className) + sm_classTable = new wxHashTable(wxKEY_STRING); + + // Index all class infos by their class name: + wxClassInfo *info; + for(info = sm_first; info; info = info->m_next) { - wxASSERT_MSG( ++nClass < nMaxClasses, - _T("an infinite loop detected - have you used IMPLEMENT_DYNAMIC_CLASS() twice (may be by linking some object module(s) twice)?") ); - sm_classTable->Put(info->m_className, (wxObject *)info); + if (info->m_className) + { + wxASSERT_MSG( ++nClass < nMaxClasses, + _T("an infinite loop detected - have you used IMPLEMENT_DYNAMIC_CLASS() twice (may be by linking some object module(s) twice)?") ); + sm_classTable->Put(info->m_className, (wxObject *)info); + } } } - - // Set base pointers for each wxClassInfo - - for(info = sm_first; info; info = info->m_next) - { - info->m_baseInfo1 = GetBaseByName(info->GetBaseClassName1()); - info->m_baseInfo2 = GetBaseByName(info->GetBaseClassName2()); - } } void wxClassInfo::CleanUpClasses() @@ -247,6 +255,21 @@ void wxClassInfo::CleanUpClasses() wxClassInfo::sm_classTable = NULL; } +void wxClassInfo::Register() +{ + if ( sm_classTable ) + { + sm_classTable->Put(m_className, (wxObject *)this); + } +} + +void wxClassInfo::Unregister() +{ + if ( sm_classTable ) + { + sm_classTable->Delete(m_className); + } +} wxObject *wxCreateDynamicObject(const wxChar *name) {