// Modified by: Ron Lee
// Created: 04/01/98
// RCS-ID: $Id$
-// Copyright: (c) 1998 Julian Smart and Markus Holzem
+// Copyright: (c) 1998 Julian Smart
// (c) 2001 Ron Lee <ron@debian.org>
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#endif
#ifndef WX_PRECOMP
-#include "wx/hash.h"
+ #include "wx/hash.h"
+ #include "wx/object.h"
#endif
#include <string.h>
#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*>() ; }
+ wxObject* wxVariantOfPtrToObjectConverterwxObject ( wxxVariant &data )
+{ return &data.Get<wxObject>() ; }
+ wxxVariant wxObjectToVariantConverterwxObject ( wxObject *data )
+ { return wxxVariant( dynamic_cast<wxObject*> (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;
#endif
-
#ifdef _WX_WANT_NEW_SIZET_WXCHAR_INT
void *wxObject::operator new ( size_t size, const wxChar *fileName, int lineNum )
{
// wxClassInfo
// ----------------------------------------------------------------------------
+wxClassInfo::~wxClassInfo()
+{
+ // remove this object from the linked list of all class infos: if we don't
+ // do it, loading/unloading a DLL containing static wxClassInfo objects is
+ // not going to work
+ if ( this == sm_first )
+ {
+ sm_first = m_next;
+ }
+ else
+ {
+ wxClassInfo *info = sm_first;
+ while (info)
+ {
+ if ( info->m_next == this )
+ {
+ info->m_next = m_next;
+ break;
+ }
+
+ info = info->m_next;
+ }
+ }
+ Unregister();
+}
+
wxClassInfo *wxClassInfo::FindClass(const wxChar *className)
{
if ( sm_classTable )
}
}
-// a tiny InitializeClasses() helper
-/* static */
-inline wxClassInfo *wxClassInfo::GetBaseByName(const wxChar *name)
-{
- if ( !name )
- return NULL;
-
- wxClassInfo *classInfo = (wxClassInfo *)sm_classTable->Get(name);
-
- // this must be fixed, other things risk work wrongly later if you get this
- wxASSERT_MSG( classInfo,
- wxString::Format
- (
- _T("base class '%s' is unknown to wxWindows RTTI"),
- name
- ) );
-
- return classInfo;
-}
-
// Set pointers to base class(es) to speed up IsKindOf
void wxClassInfo::InitializeClasses()
{
size_t nClass = 0;
#endif
- wxClassInfo::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()
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)
{
// ----------------------------------------------------------------------------
-// wxClassInfo
+// wxObject
// ----------------------------------------------------------------------------
+// Initialize ref data from another object (needed for copy constructor and
+// assignment operator)
+void wxObject::InitFrom(const wxObject& other)
+{
+ m_refData = other.m_refData;
+ if ( m_refData )
+ m_refData->m_count++;
+}
+
void wxObject::Ref(const wxObject& clone)
{
#if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT
// misc
// ----------------------------------------------------------------------------
-#if defined(__DARWIN__) && defined(DYLIB_INIT)
+#if defined(__DARWIN__) && defined(WXMAKINGDLL)
extern "C" {
void __initialize_Cplusplus(void);
void wxWindowsDylibInit(void);
};
- // Dynamic shared library (dylib) initialization routine
- // required to initialize static C++ objects bacause of lazy dynamic linking
- // http://developer.apple.com/techpubs/macosx/Essentials/
- // SystemOverview/Frameworks/Dynamic_Shared_Libraries.html
+// Dynamic shared library (dylib) initialization routine
+// required to initialize static C++ objects bacause of lazy dynamic linking
+// http://developer.apple.com/techpubs/macosx/Essentials/
+// SystemOverview/Frameworks/Dynamic_Shared_Libraries.html
void wxWindowsDylibInit()
{
// library initialization routine to cause the static C++ objects in
// the library to be initialized (reference number 2441683).
+ // This only seems to be necessary if the library initialization routine
+ // needs to use the static C++ objects
__initialize_Cplusplus();
}