From c86f795914bd221738bba439c8fe082a8b74ef2e Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 10 Nov 2018 21:20:06 +0100 Subject: [PATCH] Move shared wxVector utilities to one place --- include/wx/propgrid/propgriddefs.h | 61 ++++++++++++++++++++++++++++++ src/propgrid/property.cpp | 42 -------------------- src/propgrid/propgrid.cpp | 16 -------- src/propgrid/propgridpagestate.cpp | 38 ------------------- 4 files changed, 61 insertions(+), 96 deletions(-) diff --git a/include/wx/propgrid/propgriddefs.h b/include/wx/propgrid/propgriddefs.h index 868f355357..6eebf00177 100644 --- a/include/wx/propgrid/propgriddefs.h +++ b/include/wx/propgrid/propgriddefs.h @@ -699,6 +699,67 @@ protected: #define WX_PG_TOKENIZER2_END() \ } +// ----------------------------------------------------------------------- +// wxVector utilities + +// Utility to check if specific item is in a vector. +template +inline bool wxPGItemExistsInVector(const wxVector& vector, const T& item) +{ +#if wxUSE_STL + return std::find(vector.begin(), vector.end(), item) != vector.end(); +#else + for (typename wxVector::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 +inline int wxPGItemIndexInVector(const wxVector& vector, const T& item) +{ +#if wxUSE_STL + typename wxVector::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::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 +inline void wxPGRemoveItemFromVector(wxVector& vector, const T& item) +{ +#if wxUSE_STL + typename wxVector::iterator it = std::find(vector.begin(), vector.end(), item); + if ( it != vector.end() ) + { + vector.erase(it); + } +#else + for (typename wxVector::iterator it = vector.begin(); it != vector.end(); ++it) + { + if ( *it == item ) + { + vector.erase(it); + return; + } + } +#endif // wxUSE_STL/!wxUSE_STL +} + // ----------------------------------------------------------------------- #endif // wxUSE_PROPGRID diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 5f46ee783f..9716d3676d 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -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 -static int wxPGItemIndexInVector(const wxVector& vector, const T& item) -{ -#if wxUSE_STL - typename wxVector::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::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 -static void wxPGRemoveItemFromVector(wxVector& vector, const T& item) -{ -#if wxUSE_STL - typename wxVector::iterator it = std::find(vector.begin(), vector.end(), item); - if ( it != vector.end() ) - { - vector.erase(it); - } -#else - for (typename wxVector::iterator it = vector.begin(); it != vector.end(); ++it) - { - if ( *it == item ) - { - vector.erase(it); - return; - } - } -#endif // wxUSE_STL/!wxUSE_STL -} - // ----------------------------------------------------------------------- // wxPGCellRenderer // ----------------------------------------------------------------------- diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index b910fe5d5e..e4e4639084 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -137,22 +137,6 @@ DeletedObjects gs_deletedEditorObjects; } // anonymous namespace #endif - // Utility to check if specific item is in a vector. -template -static bool wxPGItemExistsInVector(const wxVector& vector, const T& item) -{ -#if wxUSE_STL - return std::find(vector.begin(), vector.end(), item) != vector.end(); -#else - for (typename wxVector::const_iterator it = vector.begin(); it != vector.end(); ++it) - { - if ( *it == item ) - return true; - } - return false; -#endif // wxUSE_STL/!wxUSE_STL -} - // ----------------------------------------------------------------------- #if wxUSE_INTL diff --git a/src/propgrid/propgridpagestate.cpp b/src/propgrid/propgridpagestate.cpp index e87a34a115..6d11d450a1 100644 --- a/src/propgrid/propgridpagestate.cpp +++ b/src/propgrid/propgridpagestate.cpp @@ -43,44 +43,6 @@ #define wxPG_DEFAULT_SPLITTERX 110 -// Utility to remove given item from the vector. -template -static void wxPGRemoveItemFromVector(wxVector& vector, const T& item) -{ -#if wxUSE_STL - typename wxVector::iterator it = std::find(vector.begin(), vector.end(), item); - if ( it != vector.end() ) - { - vector.erase(it); - } -#else - for (typename wxVector::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 -static bool wxPGItemExistsInVector(const wxVector& vector, const T& item) -{ -#if wxUSE_STL - return std::find(vector.begin(), vector.end(), item) != vector.end(); -#else - for (typename wxVector::const_iterator it = vector.begin(); it != vector.end(); ++it) - { - if ( *it == item ) - return true; - } - return false; -#endif // wxUSE_STL/!wxUSE_STL -} - // ----------------------------------------------------------------------- // wxPropertyGridIterator // -----------------------------------------------------------------------