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:
Mattia Barbon 2004-07-22 19:08:21 +00:00
parent 36ca94a260
commit 4e75b65f7c
2 changed files with 40 additions and 8 deletions

View File

@ -36,10 +36,17 @@ _WX_DEFINE_SORTED_TYPEARRAY_2(wxString, wxSortedArrayStringBase,
class WXDLLIMPEXP_BASE wxArrayString : public wxArrayStringBase
{
public:
// type of function used by wxArrayString::Sort()
typedef int (wxCMPFUNC_CONV *CompareFunction)(const wxString& first,
const wxString& second);
wxArrayString() { }
wxArrayString(const wxArrayString& a) : wxArrayStringBase(a) { }
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

View File

@ -470,28 +470,53 @@ int wxArrayString::Index(const wxChar* sz, bool bCase, bool WXUNUSED(bFromEnd))
return it == end() ? wxNOT_FOUND : it - begin();
}
template<class F>
class wxStringCompareLess
{
public:
typedef int (wxCMPFUNC_CONV * fnc)(const wxChar*, const wxChar*);
public:
wxStringCompareLess(fnc f) : m_f(f) { }
wxStringCompareLess(F f) : m_f(f) { }
bool operator()(const wxChar* s1, const wxChar* s2)
{ return m_f(s1, s2) < 0; }
bool operator()(const wxString& s1, const wxString& s2)
{ return m_f(s1, s2) < 0; }
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
{
wxSortedArrayString::const_iterator it;
wxString s(sz);
if (bCase)
it = std::lower_bound(begin(), end(), sz,
wxStringCompareLess(wxStrcmpCppWrapper));
it = std::lower_bound(begin(), end(), s,
wxStringCompare(wxStrcmpCppWrapper));
else
it = std::lower_bound(begin(), end(), sz,
wxStringCompareLess(wxStricmpCppWrapper));
it = std::lower_bound(begin(), end(), s,
wxStringCompare(wxStricmpCppWrapper));
if (it == end())
return wxNOT_FOUND;