Make wxClassInfo attributes private. Replace

direct access to sm_classTable with a (const) iterator
interface.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45478 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2007-04-15 11:43:37 +00:00
parent a4a44612a6
commit 644cb5372c
10 changed files with 109 additions and 45 deletions

View File

@@ -82,8 +82,8 @@ public:
private: private:
wxClassInfo *m_before; // sm_first before loading this lib const wxClassInfo *m_before; // sm_first before loading this lib
wxClassInfo *m_after; // ..and after. const wxClassInfo *m_after; // ..and after.
size_t m_linkcount; // Ref count of library link calls size_t m_linkcount; // Ref count of library link calls
size_t m_objcount; // ..and (pluggable) object instantiations. size_t m_objcount; // ..and (pluggable) object instantiations.

View File

@@ -335,6 +335,8 @@ private:
#else // if wxUSE_OLD_HASH_TABLE #else // if wxUSE_OLD_HASH_TABLE
typedef wxNode wxHashTable_Node;
class WXDLLIMPEXP_BASE wxHashTable : public wxObject class WXDLLIMPEXP_BASE wxHashTable : public wxObject
{ {
public: public:

View File

@@ -171,7 +171,7 @@ public:
const wxValidator& validator = wxDefaultValidator, const wxValidator& validator = wxDefaultValidator,
const wxString& name = wxT("mediaCtrl")); const wxString& name = wxT("mediaCtrl"));
bool DoCreate(wxClassInfo* instance, bool DoCreate(const wxClassInfo* instance,
wxWindow* parent, wxWindowID winid, wxWindow* parent, wxWindowID winid,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
@@ -213,7 +213,7 @@ public:
{ return Load(wxURI(fileName), wxURI(proxy)); } { return Load(wxURI(fileName), wxURI(proxy)); }
protected: protected:
static wxClassInfo* NextBackend(); static const wxClassInfo* NextBackend(wxClassInfo::const_iterator* it);
void OnMediaFinished(wxMediaEvent& evt); void OnMediaFinished(wxMediaEvent& evt);
virtual void DoMoveWindow(int x, int y, int w, int h); virtual void DoMoveWindow(int x, int y, int w, int h);

View File

@@ -25,6 +25,37 @@ class WXDLLIMPEXP_BASE wxObject;
#define wxUSE_EXTENDED_RTTI 0 #define wxUSE_EXTENDED_RTTI 0
#endif #endif
#define DECLARE_CLASS_INFO_ITERATORS() \
class WXDLLIMPEXP_BASE const_iterator \
{ \
typedef wxHashTable_Node Node; \
public: \
typedef const wxClassInfo* value_type; \
typedef const value_type& const_reference; \
typedef const_iterator itor; \
typedef value_type* ptr_type; \
\
Node* m_node; \
wxHashTable* m_table; \
public: \
typedef const_reference reference_type; \
typedef ptr_type pointer_type; \
\
const_iterator(Node* node, wxHashTable* table) \
: m_node(node), m_table(table) { } \
const_iterator() : m_node(NULL), m_table(NULL) { } \
value_type operator*() const; \
itor& operator++(); \
const itor operator++(int); \
bool operator!=(const itor& it) const \
{ return it.m_node != m_node; } \
bool operator==(const itor& it) const \
{ return it.m_node == m_node; } \
}; \
\
static const_iterator begin_classinfo(); \
static const_iterator end_classinfo();
#if wxUSE_EXTENDED_RTTI #if wxUSE_EXTENDED_RTTI
#include "wx/xti.h" #include "wx/xti.h"
#else #else
@@ -35,7 +66,10 @@ class WXDLLIMPEXP_BASE wxObject;
class WXDLLIMPEXP_BASE wxClassInfo; class WXDLLIMPEXP_BASE wxClassInfo;
class WXDLLIMPEXP_BASE wxHashTable; class WXDLLIMPEXP_BASE wxHashTable;
class WXDLLIMPEXP_BASE wxObject;
class WXDLLIMPEXP_BASE wxPluginLibrary;
class WXDLLIMPEXP_BASE wxObjectRefData; class WXDLLIMPEXP_BASE wxObjectRefData;
class WXDLLIMPEXP_BASE wxHashTable_Node;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxClassInfo // wxClassInfo
@@ -45,6 +79,8 @@ typedef wxObject *(*wxObjectConstructorFn)(void);
class WXDLLIMPEXP_BASE wxClassInfo class WXDLLIMPEXP_BASE wxClassInfo
{ {
friend class WXDLLIMPEXP_BASE wxObject;
friend wxObject *wxCreateDynamicObject(const wxChar *name);
public: public:
wxClassInfo( const wxChar *className, wxClassInfo( const wxChar *className,
const wxClassInfo *baseInfo1, const wxClassInfo *baseInfo1,
@@ -94,7 +130,8 @@ public:
( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) ); ( m_baseInfo2 && m_baseInfo2->IsKindOf(info) ) );
} }
public: DECLARE_CLASS_INFO_ITERATORS()
private:
const wxChar *m_className; const wxChar *m_className;
int m_objectSize; int m_objectSize;
wxObjectConstructorFn m_objectConstructor; wxObjectConstructorFn m_objectConstructor;
@@ -110,8 +147,6 @@ public:
static wxClassInfo *sm_first; static wxClassInfo *sm_first;
wxClassInfo *m_next; wxClassInfo *m_next;
// FIXME: this should be private (currently used directly by way too
// many clients)
static wxHashTable *sm_classTable; static wxHashTable *sm_classTable;
protected: protected:

View File

@@ -84,6 +84,7 @@ class WXDLLIMPEXP_BASE wxObject;
class WXDLLIMPEXP_BASE wxClassInfo; class WXDLLIMPEXP_BASE wxClassInfo;
class WXDLLIMPEXP_BASE wxDynamicClassInfo; class WXDLLIMPEXP_BASE wxDynamicClassInfo;
class WXDLLIMPEXP_BASE wxHashTable; class WXDLLIMPEXP_BASE wxHashTable;
class WXDLLIMPEXP_BASE wxHashTable_Node;
class WXDLLIMPEXP_BASE wxObjectRefData; class WXDLLIMPEXP_BASE wxObjectRefData;
class WXDLLIMPEXP_BASE wxEvent; class WXDLLIMPEXP_BASE wxEvent;
class WXDLLIMPEXP_BASE wxEvtHandler; class WXDLLIMPEXP_BASE wxEvtHandler;
@@ -1601,6 +1602,7 @@ class WXDLLIMPEXP_BASE wxClassInfo
{ {
friend class WXDLLIMPEXP_BASE wxPropertyInfo ; friend class WXDLLIMPEXP_BASE wxPropertyInfo ;
friend class WXDLLIMPEXP_BASE wxHandlerInfo ; friend class WXDLLIMPEXP_BASE wxHandlerInfo ;
friend wxObject *wxCreateDynamicObject(const wxChar *name);
public: public:
wxClassInfo(const wxClassInfo **_Parents, wxClassInfo(const wxClassInfo **_Parents,
const wxChar *_UnitName, const wxChar *_UnitName,
@@ -1718,6 +1720,8 @@ public:
return false ; return false ;
} }
DECLARE_CLASS_INFO_ITERATORS()
// if there is a callback registered with that class it will be called // if there is a callback registered with that class it will be called
// before this object will be written to disk, it can veto streaming out // before this object will be written to disk, it can veto streaming out
// this object by returning false, if this class has not registered a // this object by returning false, if this class has not registered a
@@ -1788,7 +1792,7 @@ public:
// puts all the properties of this class and its superclasses in the map, as long as there is not yet // puts all the properties of this class and its superclasses in the map, as long as there is not yet
// an entry with the same name (overriding mechanism) // an entry with the same name (overriding mechanism)
void GetProperties( wxPropertyInfoMap &map ) const ; void GetProperties( wxPropertyInfoMap &map ) const ;
public: private:
const wxChar *m_className; const wxChar *m_className;
int m_objectSize; int m_objectSize;
wxObjectConstructorFn m_objectConstructor; wxObjectConstructorFn m_objectConstructor;
@@ -1799,8 +1803,6 @@ public:
static wxClassInfo *sm_first; static wxClassInfo *sm_first;
wxClassInfo *m_next; wxClassInfo *m_next;
// FIXME: this should be private (currently used directly by way too
// many clients)
static wxHashTable *sm_classTable; static wxHashTable *sm_classTable;
protected : protected :

View File

@@ -77,9 +77,9 @@ wxPluginLibrary::wxPluginLibrary(const wxString &libname, int flags)
: m_linkcount(1) : m_linkcount(1)
, m_objcount(0) , m_objcount(0)
{ {
m_before = wxClassInfo::sm_first; m_before = wxClassInfo::GetFirst();
Load( libname, flags ); Load( libname, flags );
m_after = wxClassInfo::sm_first; m_after = wxClassInfo::GetFirst();
if( m_handle != 0 ) if( m_handle != 0 )
{ {
@@ -131,7 +131,7 @@ bool wxPluginLibrary::UnrefLib()
void wxPluginLibrary::UpdateClasses() void wxPluginLibrary::UpdateClasses()
{ {
for (wxClassInfo *info = m_after; info != m_before; info = info->m_next) for (const wxClassInfo *info = m_after; info != m_before; info = info->GetNext())
{ {
if( info->GetClassName() ) if( info->GetClassName() )
{ {
@@ -148,7 +148,7 @@ void wxPluginLibrary::RestoreClasses()
if (!ms_classes) if (!ms_classes)
return; return;
for(wxClassInfo *info = m_after; info != m_before; info = info->m_next) for(const wxClassInfo *info = m_after; info != m_before; info = info->GetNext())
{ {
ms_classes->erase(ms_classes->find(info->GetClassName())); ms_classes->erase(ms_classes->find(info->GetClassName()));
} }
@@ -167,7 +167,7 @@ void wxPluginLibrary::RegisterModules()
wxASSERT_MSG( m_linkcount == 1, wxASSERT_MSG( m_linkcount == 1,
_T("RegisterModules should only be called for the first load") ); _T("RegisterModules should only be called for the first load") );
for ( wxClassInfo *info = m_after; info != m_before; info = info->m_next) for ( const wxClassInfo *info = m_after; info != m_before; info = info->GetNext())
{ {
if( info->IsKindOf(CLASSINFO(wxModule)) ) if( info->IsKindOf(CLASSINFO(wxModule)) )
{ {

View File

@@ -120,12 +120,13 @@ bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id,
} }
else else
{ {
wxClassInfo::sm_classTable->BeginFind(); wxClassInfo::const_iterator it = wxClassInfo::begin_classinfo();
wxClassInfo* classInfo; const wxClassInfo* classInfo;
while((classInfo = NextBackend()) != NULL) while((classInfo = NextBackend(&it)) != NULL)
{ {
wxLogMessage( classInfo->GetClassName() );
if(!DoCreate(classInfo, parent, id, if(!DoCreate(classInfo, parent, id,
pos, size, style, validator, name)) pos, size, style, validator, name))
continue; continue;
@@ -183,11 +184,11 @@ bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id,
} }
else else
{ {
wxClassInfo::sm_classTable->BeginFind(); wxClassInfo::const_iterator it = wxClassInfo::begin_classinfo();
wxClassInfo* classInfo; const wxClassInfo* classInfo;
while((classInfo = NextBackend()) != NULL) while((classInfo = NextBackend(&it)) != NULL)
{ {
if(!DoCreate(classInfo, parent, id, if(!DoCreate(classInfo, parent, id,
pos, size, style, validator, name)) pos, size, style, validator, name))
@@ -212,7 +213,7 @@ bool wxMediaCtrl::Create(wxWindow* parent, wxWindowID id,
// //
// Attempts to create the control from a backend // Attempts to create the control from a backend
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
bool wxMediaCtrl::DoCreate(wxClassInfo* classInfo, bool wxMediaCtrl::DoCreate(const wxClassInfo* classInfo,
wxWindow* parent, wxWindowID id, wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxPoint& pos,
const wxSize& size, const wxSize& size,
@@ -246,19 +247,17 @@ bool wxMediaCtrl::DoCreate(wxClassInfo* classInfo,
// incompatible with the old 2.4 stable version - but since // incompatible with the old 2.4 stable version - but since
// we're in 2.5+ only we don't need to worry about the new version // we're in 2.5+ only we don't need to worry about the new version
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxClassInfo* wxMediaCtrl::NextBackend() const wxClassInfo* wxMediaCtrl::NextBackend(wxClassInfo::const_iterator* it)
{ {
wxHashTable::compatibility_iterator for ( wxClassInfo::const_iterator end = wxClassInfo::end_classinfo();
node = wxClassInfo::sm_classTable->Next(); *it != end; ++(*it) )
while (node)
{ {
wxClassInfo* classInfo = (wxClassInfo *)node->GetData(); const wxClassInfo* classInfo = **it;
if ( classInfo->IsKindOf(CLASSINFO(wxMediaBackend)) && if ( classInfo->IsKindOf(CLASSINFO(wxMediaBackend)) &&
classInfo != CLASSINFO(wxMediaBackend) ) classInfo != CLASSINFO(wxMediaBackend) )
{ {
return classInfo; return classInfo;
} }
node = wxClassInfo::sm_classTable->Next();
} }
// //

View File

@@ -746,14 +746,13 @@ bool wxDebugContext::PrintClasses(void)
} }
int n = 0; int n = 0;
wxHashTable::compatibility_iterator node; const wxClassInfo *info;
wxClassInfo *info;
wxClassInfo::sm_classTable->BeginFind(); for (wxClassInfo::const_iterator node = wxClassInfo::begin_classinfo(),
node = wxClassInfo::sm_classTable->Next(); end = wxClassInfo::end_classinfo();
while (node) node != end; ++node)
{ {
info = (wxClassInfo *)node->GetData(); info = *node;
if (info->GetClassName()) if (info->GetClassName())
{ {
wxString msg(info->GetClassName()); wxString msg(info->GetClassName());
@@ -776,7 +775,6 @@ bool wxDebugContext::PrintClasses(void)
wxLogMessage(msg); wxLogMessage(msg);
} }
node = wxClassInfo::sm_classTable->Next();
n ++; n ++;
} }
wxLogMessage(wxEmptyString); wxLogMessage(wxEmptyString);

View File

@@ -50,23 +50,20 @@ void wxModule::UnregisterModule(wxModule* module)
// and register them. // and register them.
void wxModule::RegisterModules() void wxModule::RegisterModules()
{ {
wxHashTable::compatibility_iterator node; for (wxClassInfo::const_iterator it = wxClassInfo::begin_classinfo(),
wxClassInfo* classInfo; end = wxClassInfo::end_classinfo();
it != end; ++it)
wxClassInfo::sm_classTable->BeginFind();
node = wxClassInfo::sm_classTable->Next();
while (node)
{ {
classInfo = (wxClassInfo *)node->GetData(); const wxClassInfo* classInfo = *it;
if ( classInfo->IsKindOf(CLASSINFO(wxModule)) && if ( classInfo->IsKindOf(CLASSINFO(wxModule)) &&
(classInfo != (& (wxModule::ms_classInfo))) ) (classInfo != (& (wxModule::ms_classInfo))) )
{ {
wxLogTrace(TRACE_MODULE, wxT("Registering module %s"), wxLogTrace(TRACE_MODULE, wxT("Registering module %s"),
classInfo->GetClassName()); classInfo->GetClassName());
wxModule* module = (wxModule *)classInfo->CreateObject(); wxModule* module = (wxModule *)classInfo->CreateObject();
RegisterModule(module); wxModule::RegisterModule(module);
} }
node = wxClassInfo::sm_classTable->Next();
} }
} }

View File

@@ -288,6 +288,37 @@ wxObject *wxCreateDynamicObject(const wxChar *name)
} }
} }
// iterator interface
wxClassInfo::const_iterator::value_type
wxClassInfo::const_iterator::operator*() const
{
return (wxClassInfo*)m_node->GetData();
}
wxClassInfo::const_iterator& wxClassInfo::const_iterator::operator++()
{
m_node = m_table->Next();
return *this;
}
const wxClassInfo::const_iterator wxClassInfo::const_iterator::operator++(int)
{
wxClassInfo::const_iterator tmp = *this;
m_node = m_table->Next();
return tmp;
}
wxClassInfo::const_iterator wxClassInfo::begin_classinfo()
{
sm_classTable->BeginFind();
return const_iterator(sm_classTable->Next(), sm_classTable);
}
wxClassInfo::const_iterator wxClassInfo::end_classinfo()
{
return const_iterator(NULL, NULL);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxObjectRefData // wxObjectRefData