Added compatibility functions for wxUSE_STL = 1:
void wxArrayString::Sort(CompareFunction function) void wxArrayString::Sort(bool reverseOrder). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28404 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -36,10 +36,17 @@ _WX_DEFINE_SORTED_TYPEARRAY_2(wxString, wxSortedArrayStringBase,
|
|||||||
class WXDLLIMPEXP_BASE wxArrayString : public wxArrayStringBase
|
class WXDLLIMPEXP_BASE wxArrayString : public wxArrayStringBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
// type of function used by wxArrayString::Sort()
|
||||||
|
typedef int (wxCMPFUNC_CONV *CompareFunction)(const wxString& first,
|
||||||
|
const wxString& second);
|
||||||
|
|
||||||
wxArrayString() { }
|
wxArrayString() { }
|
||||||
wxArrayString(const wxArrayString& a) : wxArrayStringBase(a) { }
|
wxArrayString(const wxArrayString& a) : wxArrayStringBase(a) { }
|
||||||
|
|
||||||
int Index(const wxChar* sz, bool bCase = true, bool bFromEnd = false) const;
|
int Index(const wxChar* sz, bool bCase = true, bool bFromEnd = false) const;
|
||||||
|
|
||||||
|
void Sort(bool reverseOrder = false);
|
||||||
|
void Sort(CompareFunction function);
|
||||||
};
|
};
|
||||||
|
|
||||||
class WXDLLIMPEXP_BASE wxSortedArrayString : public wxSortedArrayStringBase
|
class WXDLLIMPEXP_BASE wxSortedArrayString : public wxSortedArrayStringBase
|
||||||
|
@@ -470,28 +470,53 @@ int wxArrayString::Index(const wxChar* sz, bool bCase, bool WXUNUSED(bFromEnd))
|
|||||||
return it == end() ? wxNOT_FOUND : it - begin();
|
return it == end() ? wxNOT_FOUND : it - begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class F>
|
||||||
class wxStringCompareLess
|
class wxStringCompareLess
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef int (wxCMPFUNC_CONV * fnc)(const wxChar*, const wxChar*);
|
wxStringCompareLess(F f) : m_f(f) { }
|
||||||
public:
|
|
||||||
wxStringCompareLess(fnc f) : m_f(f) { }
|
|
||||||
bool operator()(const wxChar* s1, const wxChar* s2)
|
bool operator()(const wxChar* s1, const wxChar* s2)
|
||||||
{ return m_f(s1, s2) < 0; }
|
{ return m_f(s1, s2) < 0; }
|
||||||
|
bool operator()(const wxString& s1, const wxString& s2)
|
||||||
|
{ return m_f(s1, s2) < 0; }
|
||||||
private:
|
private:
|
||||||
fnc m_f;
|
F m_f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<class F>
|
||||||
|
wxStringCompareLess<F> wxStringCompare(F f)
|
||||||
|
{
|
||||||
|
return wxStringCompareLess<F>(f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxArrayString::Sort(CompareFunction function)
|
||||||
|
{
|
||||||
|
std::sort(begin(), end(), wxStringCompare(function));
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxArrayString::Sort(bool reverseOrder)
|
||||||
|
{
|
||||||
|
if (reverseOrder)
|
||||||
|
{
|
||||||
|
std::sort(begin(), end(), std::greater<wxString>());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::sort(begin(), end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int wxSortedArrayString::Index(const wxChar* sz, bool bCase, bool WXUNUSED(bFromEnd)) const
|
int wxSortedArrayString::Index(const wxChar* sz, bool bCase, bool WXUNUSED(bFromEnd)) const
|
||||||
{
|
{
|
||||||
wxSortedArrayString::const_iterator it;
|
wxSortedArrayString::const_iterator it;
|
||||||
|
wxString s(sz);
|
||||||
|
|
||||||
if (bCase)
|
if (bCase)
|
||||||
it = std::lower_bound(begin(), end(), sz,
|
it = std::lower_bound(begin(), end(), s,
|
||||||
wxStringCompareLess(wxStrcmpCppWrapper));
|
wxStringCompare(wxStrcmpCppWrapper));
|
||||||
else
|
else
|
||||||
it = std::lower_bound(begin(), end(), sz,
|
it = std::lower_bound(begin(), end(), s,
|
||||||
wxStringCompareLess(wxStricmpCppWrapper));
|
wxStringCompare(wxStricmpCppWrapper));
|
||||||
|
|
||||||
if (it == end())
|
if (it == end())
|
||||||
return wxNOT_FOUND;
|
return wxNOT_FOUND;
|
||||||
|
Reference in New Issue
Block a user