]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix wx[Sorted]ArrayString::Index when wxUSE_STL=1, because
authorMattia Barbon <mbarbon@cpan.org>
Sat, 19 Jul 2003 22:01:14 +0000 (22:01 +0000)
committerMattia Barbon <mbarbon@cpan.org>
Sat, 19 Jul 2003 22:01:14 +0000 (22:01 +0000)
it is different than wxArray::Index (second argument is for
case sensitivity, not search direction).
  Use forward declaration for wx[Sorted]ArrayString, where
possible.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22128 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

13 files changed:
include/wx/arrstr.h
include/wx/confbase.h
include/wx/dir.h
include/wx/generic/grid.h
include/wx/generic/gridctrl.h
include/wx/generic/statusbr.h
include/wx/utils.h
src/common/dynarray.cpp
src/generic/choicdgg.cpp
src/gtk/choice.cpp
src/gtk/listbox.cpp
src/gtk1/choice.cpp
src/gtk1/listbox.cpp

index d46e291df52f3c570feff382452b6dafa31683f6..de3508e9c8ea7d05d70854249f5878e4013a4edb 100644 (file)
@@ -38,6 +38,8 @@ class WXDLLIMPEXP_BASE wxArrayString : public wxArrayStringBase
 public:
     wxArrayString() { }
     wxArrayString(const wxArrayString& a) : wxArrayStringBase(a) { }
+
+    int Index(const wxChar* sz, bool bCase = true, bool bFromEnd = false) const;
 };
 
 class WXDLLIMPEXP_BASE wxSortedArrayString : public wxSortedArrayStringBase
@@ -56,6 +58,8 @@ public:
         for ( size_t n = 0; n < src.size(); n++ )
             Add(src[n]);
     }
+
+    int Index(const wxChar* sz, bool bCase = true, bool bFromEnd = false) const;
 };
 
 #else // if !wxUSE_STL
index 503247fd56aaf8a506812ee96ba755c202e8bdd4..16b7ba3a883eaac34a1baa7dc2f0f2433f0d0578 100644 (file)
@@ -20,7 +20,8 @@
 
 #include "wx/defs.h"
 #include "wx/string.h"
-#include "wx/arrstr.h"
+
+class WXDLLIMPEXP_BASE wxArrayString;
 
 // ----------------------------------------------------------------------------
 // constants
index 7cb355ff5b278ec825964fb08160fd57bab6b69a..0d68eb59fb21bdf01b33962a051b8456975bfcf1 100644 (file)
 #endif
 
 #ifndef WX_PRECOMP
-    #include  "wx/string.h"
-    #include "wx/arrstr.h"
+    #include "wx/string.h"
 #endif
 
+class WXDLLIMPEXP_BASE wxArrayString;
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
index 5f4aa749af9c78ad9721e9885cf19f6ddd53201b..05451555f08bd1745fbe7aa05bde9e74fd8705ee 100644 (file)
@@ -22,6 +22,7 @@
 #include "wx/panel.h"
 #include "wx/scrolwin.h"
 #include "wx/string.h"
+#include "wx/arrstr.h"
 #include "wx/scrolbar.h"
 #include "wx/event.h"
 #include "wx/combobox.h"
index b607c326075f22117700c49787975048893167c8..5df562eb3cd93be86fefd4ec3b7dd72b04ddf500 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "wx/grid.h"
 #include "wx/string.h"
+#include "wx/arrstr.h"
 #include "wx/datetime.h"
 
 #define wxGRID_VALUE_CHOICEINT    _T("choiceint")
index 9b07b714693be60530df6d1fb811f79ed6088ba9..f203e174d6945b26ce68b8a0feff5b674dd9b767 100644 (file)
@@ -19,6 +19,7 @@
 #include "wx/pen.h"
 #include "wx/font.h"
 #include "wx/statusbr.h"
+#include "wx/arrstr.h"
 
 WXDLLEXPORT_DATA(extern const wxChar*) wxPanelNameStr;
 
index 988754c1b68370a0c45efa98e7da91c595d03938..a6582b767989db0e76654f707fb802ab702afd16 100644 (file)
@@ -23,7 +23,8 @@
 #include "wx/object.h"
 #include "wx/list.h"
 #include "wx/filefn.h"
-#include "wx/arrstr.h"
+
+class WXDLLIMPEXP_BASE wxArrayString;
 
 // need this for wxGetDiskSpace() as we can't, unfortunately, forward declare
 // wxLongLong
index 63d9e7b5caa59b931f7ec5259b7b8b1a2e4b1c2f..9933c0bc75a7ae6310f43879f826c795f60154e9 100644 (file)
@@ -426,6 +426,52 @@ _WX_DEFINE_BASEARRAY(double,       wxBaseArrayDouble)
 #if wxUSE_STL
 #include "wx/arrstr.h"
 
-_WX_DEFINE_BASEARRAY(wxString, wxBaseArrayStringBase)
+#include "wx/beforestd.h"
+#include <functional>
+#include "wx/afterstd.h"
+
+_WX_DEFINE_BASEARRAY(wxString, wxBaseArrayStringBase);
+
+int wxArrayString::Index(const wxChar* sz, bool bCase, bool bFromEnd) const
+{
+    wxArrayString::const_iterator it;
+
+    if (bCase)
+        it = std::find_if(begin(), end(),
+                          std::not1(std::bind2nd(std::ptr_fun(wxStrcmp), sz)));
+    else
+        it = std::find_if(begin(), end(),
+                          std::not1(std::bind2nd(std::ptr_fun(wxStricmp), sz)));
+
+    return it == end() ? wxNOT_FOUND : it - begin();
+}
+
+class wxStringCompareLess
+{
+public:
+    typedef int (wxCMPFUNC_CONV * fnc)(const wxChar*, const wxChar*);
+public:
+    wxStringCompareLess(fnc f) : m_f(f) { }
+    bool operator()(const wxChar* s1, const wxChar* s2)
+        { return m_f(s1, s2) < 0; }
+private:
+    fnc m_f;
+};
+
+int wxSortedArrayString::Index(const wxChar* sz, bool bCase, bool bFromEnd) const
+{
+    wxSortedArrayString::const_iterator it;
+
+    if (bCase)
+        it = std::lower_bound(begin(), end(), sz,
+                              wxStringCompareLess(wxStrcmp));
+    else
+        it = std::lower_bound(begin(), end(), sz,
+                              wxStringCompareLess(wxStricmp));
+
+    if (it == end() || (bCase ? wxStrcmp : wxStricmp)(it->c_str(), sz) != 0)
+        return wxNOT_FOUND;
+    return it - begin();
+}
 
 #endif
index 1c270386e120e460b73a7b3ac9b6860d9ce9e21a..695b283eefbb26ecf45a0f7932338dd9e9f753c1 100644 (file)
@@ -39,6 +39,7 @@
     #include "wx/stattext.h"
     #include "wx/intl.h"
     #include "wx/sizer.h"
+    #include "wx/arrstr.h"
 #endif
 
 #if wxUSE_STATLINE
index 05b88cc2ae702c37f9b29a45687a49d1f321f6f2..5cda4d680880bae5adad7fe82e36963b568bf6bf 100644 (file)
@@ -17,6 +17,7 @@
 #if wxUSE_CHOICE
 
 #include "wx/choice.h"
+#include "wx/arrstr.h"
 
 #include "wx/gtk/private.h"
 
index fc1783f95459a5ac3fd05d00c10d44410636896f..e9540a1e4465624029bea7b50555c593117fc7fe 100644 (file)
 #pragma implementation "listbox.h"
 #endif
 
-#include "wx/listbox.h"
+#include "wx/defs.h"
 
 #if wxUSE_LISTBOX
 
+#include "wx/listbox.h"
 #include "wx/dynarray.h"
+#include "wx/arrstr.h"
 #include "wx/utils.h"
 #include "wx/intl.h"
 #include "wx/checklst.h"
index 05b88cc2ae702c37f9b29a45687a49d1f321f6f2..5cda4d680880bae5adad7fe82e36963b568bf6bf 100644 (file)
@@ -17,6 +17,7 @@
 #if wxUSE_CHOICE
 
 #include "wx/choice.h"
+#include "wx/arrstr.h"
 
 #include "wx/gtk/private.h"
 
index fc1783f95459a5ac3fd05d00c10d44410636896f..e9540a1e4465624029bea7b50555c593117fc7fe 100644 (file)
 #pragma implementation "listbox.h"
 #endif
 
-#include "wx/listbox.h"
+#include "wx/defs.h"
 
 #if wxUSE_LISTBOX
 
+#include "wx/listbox.h"
 #include "wx/dynarray.h"
+#include "wx/arrstr.h"
 #include "wx/utils.h"
 #include "wx/intl.h"
 #include "wx/checklst.h"