Move shared wxVector utilities to one place

This commit is contained in:
Artur Wieczorek
2018-11-10 21:20:06 +01:00
parent 43f7e35c52
commit c86f795914
4 changed files with 61 additions and 96 deletions

View File

@@ -699,6 +699,67 @@ protected:
#define WX_PG_TOKENIZER2_END() \
}
// -----------------------------------------------------------------------
// wxVector utilities
// Utility to check if specific item is in a vector.
template<typename T>
inline bool wxPGItemExistsInVector(const wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
return std::find(vector.begin(), vector.end(), item) != vector.end();
#else
for (typename wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
return true;
}
return false;
#endif // wxUSE_STL/!wxUSE_STL
}
// Utility to determine the index of the item in the vector.
template<typename T>
inline int wxPGItemIndexInVector(const wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
typename wxVector<T>::const_iterator it = std::find(vector.begin(), vector.end(), item);
if ( it != vector.end() )
return (int)(it - vector.begin());
return wxNOT_FOUND;
#else
for (typename wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
return (int)(it - vector.begin());
}
return wxNOT_FOUND;
#endif // wxUSE_STL/!wxUSE_STL
}
// Utility to remove given item from the vector.
template<typename T>
inline void wxPGRemoveItemFromVector(wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
typename wxVector<T>::iterator it = std::find(vector.begin(), vector.end(), item);
if ( it != vector.end() )
{
vector.erase(it);
}
#else
for (typename wxVector<T>::iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
{
vector.erase(it);
return;
}
}
#endif // wxUSE_STL/!wxUSE_STL
}
// -----------------------------------------------------------------------
#endif // wxUSE_PROPGRID

View File

@@ -104,48 +104,6 @@ static void wxPGDrawFocusRect(wxWindow *win, wxDC& dc,
#endif // wxPG_USE_NATIVE_FOCUS_RECT_RENDERER/!wxPG_USE_NATIVE_FOCUS_RECT_RENDERER
}
// Utility to determine the index of the item in the vector.
template<typename T>
static int wxPGItemIndexInVector(const wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
typename wxVector<T>::const_iterator it = std::find(vector.begin(), vector.end(), item);
if ( it != vector.end() )
return (int)(it - vector.begin());
return wxNOT_FOUND;
#else
for (typename wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
return (int)(it - vector.begin());
}
return wxNOT_FOUND;
#endif // wxUSE_STL/!wxUSE_STL
}
// Utility to remove given item from the vector.
template<typename T>
static void wxPGRemoveItemFromVector(wxVector<T>& vector, const T& item)
{
#if wxUSE_STL
typename wxVector<T>::iterator it = std::find(vector.begin(), vector.end(), item);
if ( it != vector.end() )
{
vector.erase(it);
}
#else
for (typename wxVector<T>::iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
{
vector.erase(it);
return;
}
}
#endif // wxUSE_STL/!wxUSE_STL
}
// -----------------------------------------------------------------------
// wxPGCellRenderer
// -----------------------------------------------------------------------

View File

@@ -137,22 +137,6 @@ DeletedObjects gs_deletedEditorObjects;
} // anonymous namespace
#endif
// 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 (typename wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
return true;
}
return false;
#endif // wxUSE_STL/!wxUSE_STL
}
// -----------------------------------------------------------------------
#if wxUSE_INTL

View File

@@ -43,44 +43,6 @@
#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
typename wxVector<T>::iterator it = std::find(vector.begin(), vector.end(), item);
if ( it != vector.end() )
{
vector.erase(it);
}
#else
for (typename 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 (typename wxVector<T>::const_iterator it = vector.begin(); it != vector.end(); ++it)
{
if ( *it == item )
return true;
}
return false;
#endif // wxUSE_STL/!wxUSE_STL
}
// -----------------------------------------------------------------------
// wxPropertyGridIterator
// -----------------------------------------------------------------------