Use correct types for comparison functions in wxArray,
wxSortedArray and wxSortedArrayString, when wxUSE_STL=1. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22063 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -23,8 +23,10 @@ WXDLLIMPEXP_BASE int wxStringSortDescending(wxString*, wxString*);
|
|||||||
#include "wx/dynarray.h"
|
#include "wx/dynarray.h"
|
||||||
|
|
||||||
typedef int (*CMPFUNCwxString)(wxString*, wxString*);
|
typedef int (*CMPFUNCwxString)(wxString*, wxString*);
|
||||||
WX_DECLARE_USER_EXPORTED_BASEARRAY(wxString, wxBaseArrayStringBase,
|
typedef wxString _wxArraywxBaseArrayStringBase;
|
||||||
WXDLLIMPEXP_BASE);
|
_WX_DECLARE_BASEARRAY_2(_wxArraywxBaseArrayStringBase, wxBaseArrayStringBase,
|
||||||
|
wxArray_SortFunction<wxString>,
|
||||||
|
class WXDLLIMPEXP_BASE);
|
||||||
WX_DEFINE_USER_EXPORTED_TYPEARRAY(wxString, wxArrayStringBase,
|
WX_DEFINE_USER_EXPORTED_TYPEARRAY(wxString, wxArrayStringBase,
|
||||||
wxBaseArrayStringBase, WXDLLIMPEXP_BASE);
|
wxBaseArrayStringBase, WXDLLIMPEXP_BASE);
|
||||||
_WX_DEFINE_SORTED_TYPEARRAY_2(wxString, wxSortedArrayStringBase,
|
_WX_DEFINE_SORTED_TYPEARRAY_2(wxString, wxSortedArrayStringBase,
|
||||||
|
@@ -86,9 +86,43 @@ typedef int (wxCMPFUNC_CONV *CMPFUNC)(const void* pItem1, const void* pItem2);
|
|||||||
|
|
||||||
#if wxUSE_STL
|
#if wxUSE_STL
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class WXDLLIMPEXP_BASE wxArray_SortFunction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef int (wxCMPFUNC_CONV *CMPFUNC)(T* pItem1, T* pItem2);
|
||||||
|
|
||||||
|
wxArray_SortFunction(CMPFUNC f) : m_f(f) { }
|
||||||
|
bool operator()(const T& i1, const T& i2)
|
||||||
|
{ return m_f((T*)&i1, (T*)&i2) < 0; }
|
||||||
|
private:
|
||||||
|
CMPFUNC m_f;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<class T, typename F>
|
||||||
|
class WXDLLIMPEXP_BASE wxSortedArray_SortFunction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef F CMPFUNC;
|
||||||
|
|
||||||
|
wxSortedArray_SortFunction(CMPFUNC f) : m_f(f) { }
|
||||||
|
bool operator()(const T& i1, const T& i2)
|
||||||
|
{ return m_f(i1, i2) < 0; }
|
||||||
|
private:
|
||||||
|
CMPFUNC m_f;
|
||||||
|
};
|
||||||
|
|
||||||
#define _WX_DECLARE_BASEARRAY(T, name, classexp) \
|
#define _WX_DECLARE_BASEARRAY(T, name, classexp) \
|
||||||
|
typedef int (wxCMPFUNC_CONV *CMPFUN##name)(T pItem1, T pItem2); \
|
||||||
|
typedef wxSortedArray_SortFunction<T, CMPFUN##name> name##_Predicate; \
|
||||||
|
_WX_DECLARE_BASEARRAY_2(T, name, name##_Predicate, classexp)
|
||||||
|
|
||||||
|
#define _WX_DECLARE_BASEARRAY_2(T, name, predicate, classexp) \
|
||||||
classexp name : public std::vector<T> \
|
classexp name : public std::vector<T> \
|
||||||
{ \
|
{ \
|
||||||
|
typedef predicate Predicate; \
|
||||||
|
typedef predicate::CMPFUNC SCMPFUNC; \
|
||||||
|
typedef wxArray_SortFunction<T>::CMPFUNC CMPFUNC; \
|
||||||
public: \
|
public: \
|
||||||
void Empty() { clear(); } \
|
void Empty() { clear(); } \
|
||||||
void Clear() { clear(); } \
|
void Clear() { clear(); } \
|
||||||
@@ -120,19 +154,9 @@ protected: \
|
|||||||
\
|
\
|
||||||
void Sort(CMPFUNC fCmp) \
|
void Sort(CMPFUNC fCmp) \
|
||||||
{ \
|
{ \
|
||||||
Predicate p(fCmp); \
|
wxArray_SortFunction<T> p(fCmp); \
|
||||||
std::sort(begin(), end(), p); \
|
std::sort(begin(), end(), p); \
|
||||||
} \
|
} \
|
||||||
private: \
|
|
||||||
class Predicate \
|
|
||||||
{ \
|
|
||||||
typedef CMPFUNC fnc; \
|
|
||||||
fnc m_f; \
|
|
||||||
public: \
|
|
||||||
Predicate(fnc f) : m_f(f) { } \
|
|
||||||
bool operator()(const T& i1, const T& i2) \
|
|
||||||
{ return m_f((T*)&i1, (T*)&i2) < 0; /* const cast */ } \
|
|
||||||
}; \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // if !wxUSE_STL
|
#else // if !wxUSE_STL
|
||||||
@@ -140,6 +164,7 @@ private: \
|
|||||||
#define _WX_DECLARE_BASEARRAY(T, name, classexp) \
|
#define _WX_DECLARE_BASEARRAY(T, name, classexp) \
|
||||||
classexp name \
|
classexp name \
|
||||||
{ \
|
{ \
|
||||||
|
typedef CMPFUNC SCMPFUNC; /* for compatibility wuth wxUSE_STL */ \
|
||||||
public: \
|
public: \
|
||||||
name(); \
|
name(); \
|
||||||
name(const name& array); \
|
name(const name& array); \
|
||||||
@@ -459,6 +484,7 @@ wxCOMPILE_TIME_ASSERT2(sizeof(T) <= sizeof(base::base_type), \
|
|||||||
name); \
|
name); \
|
||||||
classexp name : public base \
|
classexp name : public base \
|
||||||
{ \
|
{ \
|
||||||
|
typedef comptype SCMPFUNC; \
|
||||||
public: \
|
public: \
|
||||||
name(comptype fn defcomp) { m_fnCompare = fn; } \
|
name(comptype fn defcomp) { m_fnCompare = fn; } \
|
||||||
\
|
\
|
||||||
|
@@ -90,17 +90,17 @@ size_t name::Add(T lItem, CMPFUNC fnCompare) \
|
|||||||
#define _WX_DEFINE_BASEARRAY_NOCOMMON(T, name) \
|
#define _WX_DEFINE_BASEARRAY_NOCOMMON(T, name) \
|
||||||
size_t name::IndexForInsert(T lItem, CMPFUNC fnCompare) const \
|
size_t name::IndexForInsert(T lItem, CMPFUNC fnCompare) const \
|
||||||
{ \
|
{ \
|
||||||
Predicate p(fnCompare); \
|
Predicate p((SCMPFUNC)fnCompare); \
|
||||||
const_iterator it = std::lower_bound(begin(), end(), lItem, p); \
|
const_iterator it = std::lower_bound(begin(), end(), lItem, p); \
|
||||||
return it - begin(); \
|
return it - begin(); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
int name::Index(T lItem, CMPFUNC fnCompare) const \
|
int name::Index(T lItem, CMPFUNC fnCompare) const \
|
||||||
{ \
|
{ \
|
||||||
size_t n = IndexForInsert(lItem, fnCompare); \
|
Predicate p((SCMPFUNC)fnCompare); \
|
||||||
\
|
const_iterator it = std::lower_bound(begin(), end(), lItem, p); \
|
||||||
return (n >= size() || \
|
return (it != end() && \
|
||||||
(*fnCompare)(&lItem, &(*this)[n])) ? wxNOT_FOUND : (int)n; \
|
p(lItem, *it)) ? (int)(it - begin()) : wxNOT_FOUND; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void name::Shrink() \
|
void name::Shrink() \
|
||||||
|
Reference in New Issue
Block a user