Safeguard against redundant registration of the same wxAnyValueType instance (by storing pointers in a set instead of a vector)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64159 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
8c3017fe4f
commit
ee7bcb842c
@ -28,6 +28,7 @@
|
|||||||
#include "wx/vector.h"
|
#include "wx/vector.h"
|
||||||
#include "wx/module.h"
|
#include "wx/module.h"
|
||||||
#include "wx/hashmap.h"
|
#include "wx/hashmap.h"
|
||||||
|
#include "wx/hashset.h"
|
||||||
|
|
||||||
using namespace wxPrivate;
|
using namespace wxPrivate;
|
||||||
|
|
||||||
@ -45,6 +46,11 @@ WX_DECLARE_HASH_MAP(wxAnyValueType*,
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
WX_DECLARE_HASH_SET(wxAnyValueType*,
|
||||||
|
wxPointerHash,
|
||||||
|
wxPointerEqual,
|
||||||
|
wxAnyValueTypePtrSet);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Helper class to manage wxAnyValueType instances and and other
|
// Helper class to manage wxAnyValueType instances and and other
|
||||||
// related global variables (such as wxAny<->wxVariant type association).
|
// related global variables (such as wxAny<->wxVariant type association).
|
||||||
@ -65,13 +71,20 @@ public:
|
|||||||
#if wxUSE_VARIANT
|
#if wxUSE_VARIANT
|
||||||
m_anyToVariant.clear();
|
m_anyToVariant.clear();
|
||||||
#endif
|
#endif
|
||||||
for ( size_t i=0; i<m_valueTypes.size(); i++ )
|
|
||||||
delete m_valueTypes[i];
|
wxAnyValueTypePtrSet::iterator it;
|
||||||
|
for ( it = m_valueTypes.begin(); it != m_valueTypes.end(); ++it )
|
||||||
|
{
|
||||||
|
delete *it;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterValueType(wxAnyValueType* valueType)
|
void RegisterValueType(wxAnyValueType* valueType)
|
||||||
{
|
{
|
||||||
m_valueTypes.push_back(valueType);
|
// Let's store value types in set to prevent deleting the same object
|
||||||
|
// several times (it may be possible, under certain conditions, that
|
||||||
|
// the same wxAnyValueType instance gets registered twice)
|
||||||
|
m_valueTypes.insert(valueType);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_VARIANT
|
#if wxUSE_VARIANT
|
||||||
@ -134,7 +147,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxVector<wxAnyValueType*> m_valueTypes;
|
wxAnyValueTypePtrSet m_valueTypes;
|
||||||
#if wxUSE_VARIANT
|
#if wxUSE_VARIANT
|
||||||
wxAnyTypeToVariantDataFactoryMap m_anyToVariant;
|
wxAnyTypeToVariantDataFactoryMap m_anyToVariant;
|
||||||
wxVector<wxAnyToVariantRegistration*> m_anyToVariantRegs;
|
wxVector<wxAnyToVariantRegistration*> m_anyToVariantRegs;
|
||||||
|
Loading…
Reference in New Issue
Block a user