Declare array explicitly as a wxVector instead of using wxArrayPGProperty alias

This commit is contained in:
Artur Wieczorek 2018-11-01 18:19:55 +01:00
parent 5fbe3cab76
commit e7357eafa2
3 changed files with 65 additions and 46 deletions

View File

@ -1572,8 +1572,8 @@ protected:
wxPGCell m_unspecifiedAppearance;
// List of properties to be deleted/removed in idle event handler.
wxArrayPGProperty m_deletedProperties;
wxArrayPGProperty m_removedProperties;
wxVector<wxPGProperty*> m_deletedProperties;
wxVector<wxPGProperty*> m_removedProperties;
#if !WXWIN_COMPATIBILITY_3_0
// List of editors and their event handlers to be deleted in idle event handler.
@ -2280,7 +2280,7 @@ public:
// added.
wxPGProperty* GetCurParent() const
{
return (wxPGProperty*) m_propHierarchy[m_propHierarchy.size()-1];
return m_propHierarchy.back();
}
wxPropertyGridPageState* GetState() { return m_state; }
@ -2309,7 +2309,7 @@ protected:
wxPropertyGridPageState* m_state;
// Tree-hierarchy of added properties (that can have children).
wxArrayPGProperty m_propHierarchy;
wxVector<wxPGProperty*> m_propHierarchy;
// Hashmap for string-id to wxPGChoicesData mapping.
wxPGHashMapS2P m_dictIdChoices;

View File

@ -5588,17 +5588,20 @@ void wxPropertyGrid::ClearActionTriggers( int action )
}
#if WXWIN_COMPATIBILITY_3_0
// Utility to find if specific item is in a vector. Returns index to
// the item, or wxNOT_FOUND if not present.
template<typename CONTAINER, typename T>
int wxPGFindInVector( CONTAINER vector, const T& item )
// Utility to check if specific item is in a vector.
template<typename T>
static bool wxPGItemExistsInVector(const wxVector<T>& vector, const T& item)
{
for ( unsigned int i=0; i<vector.size(); i++ )
#if wxUSE_STL
return std::find(vector.begin(), vector.end(), item) != vector.end();
#else
for (wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( vector[i] == item )
return (int) i;
if ( *it == item )
return true;
}
return wxNOT_FOUND;
return false;
#endif // wxUSE_STL/!wxUSE_STL
}
#endif // WXWIN_COMPATIBILITY_3_0
@ -5706,7 +5709,7 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild )
if ( fromChild &&
#if WXWIN_COMPATIBILITY_3_0
// Deprecated: use a hash set instead.
wxPGFindInVector(m_dedicatedKeys, keycode) == wxNOT_FOUND )
!wxPGItemExistsInVector<int>(m_dedicatedKeys, keycode) )
#else
m_dedicatedKeys.find(keycode) == m_dedicatedKeys.end() )
#endif
@ -6602,11 +6605,10 @@ bool wxPropertyGridPopulator::AddAttribute( const wxString& name,
const wxString& type,
const wxString& value )
{
int l = m_propHierarchy.size();
if ( !l )
if ( m_propHierarchy.empty() )
return false;
wxPGProperty* p = m_propHierarchy[l-1];
wxPGProperty* p = m_propHierarchy.back();
wxString valuel = value.Lower();
wxVariant variant;

View File

@ -43,6 +43,43 @@
#define wxPG_DEFAULT_SPLITTERX 110
// Utility to remove given item from the vector.
template<typename T>
static void wxPGRemoveItemFromVector(wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
wxVector<T>::iterator it = std::find(vector.begin(), vector.end(), item);
if ( it != vector.end() )
{
vector.erase(it);
}
#else
for (wxVector<T>::iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
{
vector.erase(it);
return;
}
}
#endif // wxUSE_STL/!wxUSE_STL
}
// Utility to check if specific item is in a vector.
template<typename T>
static bool wxPGItemExistsInVector(const wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
return std::find(vector.begin(), vector.end(), item) != vector.end();
#else
for (wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
return true;
}
return false;
#endif // wxUSE_STL/!wxUSE_STL
}
// -----------------------------------------------------------------------
// wxPropertyGridIterator
@ -303,16 +340,8 @@ void wxPropertyGridPageState::DoClear()
for (unsigned int i = 0; i < m_regularArray.GetChildCount(); i++)
{
wxPGProperty* p = m_regularArray.Item(i);
int index = m_pPropGrid->m_deletedProperties.Index(p);
if (index != wxNOT_FOUND)
{
m_pPropGrid->m_deletedProperties.RemoveAt(index);
}
index = m_pPropGrid->m_removedProperties.Index(p);
if (index != wxNOT_FOUND)
{
m_pPropGrid->m_removedProperties.RemoveAt(index);
}
wxPGRemoveItemFromVector<wxPGProperty*>(m_pPropGrid->m_deletedProperties, p);
wxPGRemoveItemFromVector<wxPGProperty*>(m_pPropGrid->m_removedProperties, p);
}
m_regularArray.Empty();
@ -2004,14 +2033,14 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete )
// Prevent adding duplicates to the lists.
if ( doDelete )
{
if ( pg->m_deletedProperties.Index(item) != wxNOT_FOUND )
if ( wxPGItemExistsInVector<wxPGProperty*>(pg->m_deletedProperties, item) )
return;
pg->m_deletedProperties.push_back(item);
}
else
{
if ( pg->m_removedProperties.Index(item) != wxNOT_FOUND )
if ( wxPGItemExistsInVector<wxPGProperty*>(pg->m_removedProperties, item) )
return;
pg->m_removedProperties.push_back(item);
@ -2112,20 +2141,12 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete )
{
// Remove the item from both lists of pending operations.
// (Deleted item cannot be also the subject of further removal.)
int index = pg->m_deletedProperties.Index(item);
if ( index != wxNOT_FOUND )
{
pg->m_deletedProperties.RemoveAt(index);
}
wxASSERT_MSG( pg->m_deletedProperties.Index(item) == wxNOT_FOUND,
wxPGRemoveItemFromVector<wxPGProperty*>(pg->m_deletedProperties, item);
wxASSERT_MSG( !wxPGItemExistsInVector<wxPGProperty*>(pg->m_deletedProperties, item),
wxS("Too many occurrences of the item"));
index = pg->m_removedProperties.Index(item);
if ( index != wxNOT_FOUND )
{
pg->m_removedProperties.RemoveAt(index);
}
wxASSERT_MSG( pg->m_removedProperties.Index(item) == wxNOT_FOUND,
wxPGRemoveItemFromVector<wxPGProperty*>(pg->m_removedProperties, item);
wxASSERT_MSG( !wxPGItemExistsInVector<wxPGProperty*>(pg->m_removedProperties, item),
wxS("Too many occurrences of the item"));
delete item;
@ -2133,12 +2154,8 @@ void wxPropertyGridPageState::DoDelete( wxPGProperty* item, bool doDelete )
else
{
// Remove the item from the list of pending removals.
int index = pg->m_removedProperties.Index(item);
if ( index != wxNOT_FOUND )
{
pg->m_removedProperties.RemoveAt(index);
}
wxASSERT_MSG( pg->m_removedProperties.Index(item) == wxNOT_FOUND,
wxPGRemoveItemFromVector<wxPGProperty*>(pg->m_removedProperties, item);
wxASSERT_MSG( !wxPGItemExistsInVector<wxPGProperty*>(pg->m_removedProperties, item),
wxS("Too many occurrences of the item"));
item->OnDetached(this, pg);