initialize wxClassInfo::sm_classTable automatically
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22626 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
14fc7eb426
commit
d1d738f18c
@ -63,27 +63,28 @@ class WXDLLIMPEXP_BASE wxClassInfo
|
||||
{
|
||||
public:
|
||||
wxClassInfo( const wxChar *className,
|
||||
const wxChar *baseName1,
|
||||
const wxChar *baseName2,
|
||||
const wxClassInfo *baseInfo1,
|
||||
const wxClassInfo *baseInfo2,
|
||||
int size,
|
||||
wxObjectConstructorFn ctor )
|
||||
: m_className(className)
|
||||
, m_baseClassName1(baseName1)
|
||||
, m_baseClassName2(baseName2)
|
||||
, m_objectSize(size)
|
||||
, m_objectConstructor(ctor)
|
||||
, m_baseInfo1(0)
|
||||
, m_baseInfo2(0)
|
||||
, m_baseInfo1(baseInfo1)
|
||||
, m_baseInfo2(baseInfo2)
|
||||
, m_next(sm_first)
|
||||
{ sm_first = this; }
|
||||
{
|
||||
sm_first = this;
|
||||
Register();
|
||||
}
|
||||
|
||||
~wxClassInfo();
|
||||
|
||||
wxObject *CreateObject() { return m_objectConstructor ? (*m_objectConstructor)() : 0; }
|
||||
|
||||
const wxChar *GetClassName() const { return m_className; }
|
||||
const wxChar *GetBaseClassName1() const { return m_baseClassName1; }
|
||||
const wxChar *GetBaseClassName2() const { return m_baseClassName2; }
|
||||
const wxChar *GetBaseClassName1() const { return m_baseInfo1->GetClassName(); }
|
||||
const wxChar *GetBaseClassName2() const { return m_baseInfo2->GetClassName(); }
|
||||
const wxClassInfo *GetBaseClass1() const { return m_baseInfo1; }
|
||||
const wxClassInfo *GetBaseClass2() const { return m_baseInfo2; }
|
||||
int GetSize() const { return m_objectSize; }
|
||||
@ -104,19 +105,14 @@ public:
|
||||
( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
|
||||
}
|
||||
|
||||
// Initializes parent pointers and hash table for fast searching.
|
||||
|
||||
// Initializes parent pointers and hash table for fast searching.
|
||||
static void InitializeClasses();
|
||||
|
||||
// Cleans up hash table used for fast searching.
|
||||
|
||||
// Cleans up hash table used for fast searching.
|
||||
static void CleanUpClasses();
|
||||
|
||||
|
||||
|
||||
public:
|
||||
const wxChar *m_className;
|
||||
const wxChar *m_baseClassName1;
|
||||
const wxChar *m_baseClassName2;
|
||||
int m_objectSize;
|
||||
wxObjectConstructorFn m_objectConstructor;
|
||||
|
||||
@ -140,6 +136,11 @@ private:
|
||||
static wxClassInfo *GetBaseByName(const wxChar *name);
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxClassInfo)
|
||||
|
||||
protected:
|
||||
// registers the class
|
||||
void Register();
|
||||
void Unregister();
|
||||
};
|
||||
|
||||
WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
|
||||
@ -174,8 +175,9 @@ WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
|
||||
#define IMPLEMENT_DYNAMIC_CLASS(name, basename) \
|
||||
wxObject* wxConstructorFor##name() \
|
||||
{ return new name; } \
|
||||
wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename), \
|
||||
0, (int) sizeof(name), \
|
||||
wxClassInfo name::sm_class##name(wxT(#name), \
|
||||
&basename::sm_class##basename, NULL, \
|
||||
(int) sizeof(name), \
|
||||
(wxObjectConstructorFn) wxConstructorFor##name);
|
||||
|
||||
// Multiple inheritance with two base classes
|
||||
@ -183,7 +185,9 @@ WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
|
||||
#define IMPLEMENT_DYNAMIC_CLASS2(name, basename1, basename2) \
|
||||
wxObject* wxConstructorFor##name() \
|
||||
{ return new name; } \
|
||||
wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
|
||||
wxClassInfo name::sm_class##name(wxT(#name), \
|
||||
&basename1::sm_class##basename1, \
|
||||
&basename2::sm_class##basename2, \
|
||||
wxT(#basename2), (int) sizeof(name), \
|
||||
(wxObjectConstructorFn) wxConstructorFor##name);
|
||||
|
||||
@ -194,14 +198,17 @@ WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxChar *name);
|
||||
// Single inheritance with one base class
|
||||
|
||||
#define IMPLEMENT_ABSTRACT_CLASS(name, basename) \
|
||||
wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename), \
|
||||
0, (int) sizeof(name), (wxObjectConstructorFn) 0);
|
||||
wxClassInfo name::sm_class##name(wxT(#name), \
|
||||
&basename::sm_class##basename, NULL, \
|
||||
(int) sizeof(name), (wxObjectConstructorFn) 0);
|
||||
|
||||
// Multiple inheritance with two base classes
|
||||
|
||||
#define IMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
|
||||
wxClassInfo name::sm_class##name(wxT(#name), wxT(#basename1), \
|
||||
wxT(#basename2), (int) sizeof(name), \
|
||||
wxClassInfo name::sm_class##name(wxT(#name), \
|
||||
&basename1::sm_class##basename1, \
|
||||
&basename2::sm_class##basename2, \
|
||||
(int) sizeof(name), \
|
||||
(wxObjectConstructorFn) 0);
|
||||
|
||||
#define IMPLEMENT_CLASS IMPLEMENT_ABSTRACT_CLASS
|
||||
|
@ -1135,13 +1135,14 @@ private:
|
||||
|
||||
const wxPropertyAccessor *FindAccessor (const wxChar *propertyName);
|
||||
|
||||
// registers the class
|
||||
static void Register(const wxChar *name, wxClassInfo *info);
|
||||
|
||||
static void Unregister(const wxChar *name);
|
||||
|
||||
// InitializeClasses() helper
|
||||
static wxClassInfo *GetBaseByName(const wxChar *name);
|
||||
|
||||
protected:
|
||||
// registers the class
|
||||
void Register();
|
||||
void Unregister();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(wxClassInfo)
|
||||
};
|
||||
|
@ -159,16 +159,6 @@ void wxPluginLibrary::UpdateClassInfo()
|
||||
(*ms_classes)[info->m_className] = this;
|
||||
}
|
||||
}
|
||||
|
||||
#if wxUSE_EXTENDED_RTTI == 0
|
||||
for(info = m_after; info != m_before; info = info->m_next)
|
||||
{
|
||||
if( info->m_baseClassName1 )
|
||||
info->m_baseInfo1 = (wxClassInfo *)t->Get(info->m_baseClassName1);
|
||||
if( info->m_baseClassName2 )
|
||||
info->m_baseInfo2 = (wxClassInfo *)t->Get(info->m_baseClassName2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxPluginLibrary::RestoreClassInfo()
|
||||
@ -531,7 +521,7 @@ void wxLibrary::PrepareClasses(wxClassInfo *first)
|
||||
info = info->m_next;
|
||||
}
|
||||
|
||||
#if wxUSE_EXTENDED_RTTI == 0
|
||||
#if !wxUSE_EXTENDED_RTTI
|
||||
// Set base pointers for each wxClassInfo
|
||||
info = first;
|
||||
while (info)
|
||||
|
@ -194,9 +194,7 @@ wxClassInfo::~wxClassInfo()
|
||||
info = info->m_next;
|
||||
}
|
||||
}
|
||||
#if wxUSE_EXTENDED_RTTI
|
||||
Unregister( m_className ) ;
|
||||
#endif
|
||||
Unregister();
|
||||
}
|
||||
|
||||
wxClassInfo *wxClassInfo::FindClass(const wxChar *className)
|
||||
@ -217,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()
|
||||
{
|
||||
@ -255,30 +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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if wxUSE_EXTENDED_RTTI == 0
|
||||
// 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());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxClassInfo::CleanUpClasses()
|
||||
@ -287,6 +255,22 @@ 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)
|
||||
{
|
||||
#if defined(__WXDEBUG__) || wxUSE_DEBUG_CONTEXT
|
||||
|
@ -548,24 +548,6 @@ void wxSetStringToArray( const wxString &s , wxArrayString &array )
|
||||
// wxClassInfo
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
|
||||
void wxClassInfo::Register(const char *WXUNUSED(name), wxClassInfo *WXUNUSED(info))
|
||||
{
|
||||
/*
|
||||
if (!ExtendedTypeMap)
|
||||
ExtendedTypeMap = new ClassMap;
|
||||
(*ExtendedTypeMap)[string(Name)] = Info;
|
||||
*/
|
||||
}
|
||||
|
||||
void wxClassInfo::Unregister(const char *WXUNUSED(name))
|
||||
{
|
||||
/*
|
||||
assert(ExtendedTypeMap);
|
||||
ExtendedTypeMap->erase(Name);
|
||||
*/
|
||||
}
|
||||
|
||||
const wxPropertyAccessor *wxClassInfo::FindAccessor(const char *PropertyName)
|
||||
{
|
||||
const wxPropertyInfo* info = FindPropertyInfo( PropertyName ) ;
|
||||
|
Loading…
Reference in New Issue
Block a user