]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/dynarray.h
Added some standard further identifiers to help with WinCE toolbars
[wxWidgets.git] / include / wx / dynarray.h
index b022b49a9cb978df0052942871e91700f2353a02..b06a1c2221d8caa25762fe3335f1d6a2dfd40549 100644 (file)
@@ -24,9 +24,6 @@
     #include <vector>
     #include <algorithm>
     #include "wx/afterstd.h"
     #include <vector>
     #include <algorithm>
     #include "wx/afterstd.h"
-    #if defined(__WXMSW__) && defined(__MINGW32__)
-        #include "wx/msw/winundef.h"
-    #endif
 #endif
 
 /*
 #endif
 
 /*
@@ -89,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:                                                             \
   void Empty() { clear(); }                                         \
   void Clear() { clear(); }                                         \
 public:                                                             \
   void Empty() { clear(); }                                         \
   void Clear() { clear(); }                                         \
@@ -123,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
@@ -143,6 +164,7 @@ private:                                                            \
 #define  _WX_DECLARE_BASEARRAY(T, name, classexp)                   \
 classexp name                                                       \
 {                                                                   \
 #define  _WX_DECLARE_BASEARRAY(T, name, classexp)                   \
 classexp name                                                       \
 {                                                                   \
+  typedef CMPFUNC SCMPFUNC; /* for compatibility wuth wxUSE_STL */  \
 public:                                                             \
   name();                                                           \
   name(const name& array);                                          \
 public:                                                             \
   name();                                                           \
   name(const name& array);                                          \
@@ -350,10 +372,16 @@ public:                                                               \
     typedef value_type& reference;                                    \
     typedef value_type* pointer;                                      \
     typedef reverse_iterator itor;                                    \
     typedef value_type& reference;                                    \
     typedef value_type* pointer;                                      \
     typedef reverse_iterator itor;                                    \
-    friend itor operator+(int o, const itor& it);                     \
-    friend itor operator+(const itor& it, int o);                     \
-    friend itor operator-(const itor& it, int o);                     \
-    friend difference_type operator -(const itor& i1, const itor& i2);\
+    friend inline itor operator+(int o, const itor& it)               \
+        { return it.m_ptr - o; }                                      \
+    friend inline itor operator+(const itor& it, int o)               \
+        { return it.m_ptr - o; }                                      \
+    friend inline itor operator-(const itor& it, int o)               \
+        { return it.m_ptr + o; }                                      \
+    friend inline difference_type operator-(const itor& i1,           \
+                                            const itor& i2)           \
+        { return i1.m_ptr - i2.m_ptr; }                               \
+                                                                      \
   public:                                                             \
     pointer m_ptr;                                                    \
     reverse_iterator() : m_ptr(NULL) { }                              \
   public:                                                             \
     pointer m_ptr;                                                    \
     reverse_iterator() : m_ptr(NULL) { }                              \
@@ -376,10 +404,16 @@ public:                                                               \
     typedef const value_type& reference;                              \
     typedef const value_type* pointer;                                \
     typedef const_reverse_iterator itor;                              \
     typedef const value_type& reference;                              \
     typedef const value_type* pointer;                                \
     typedef const_reverse_iterator itor;                              \
-    friend itor operator+(int o, const itor& it);                     \
-    friend itor operator+(const itor& it, int o);                     \
-    friend itor operator-(const itor& it, int o);                     \
-    friend difference_type operator -(const itor& i1, const itor& i2);\
+    friend inline itor operator+(int o, const itor& it)               \
+        { return it.m_ptr - o; }                                      \
+    friend inline itor operator+(const itor& it, int o)               \
+        { return it.m_ptr - o; }                                      \
+    friend inline itor operator-(const itor& it, int o)               \
+        { return it.m_ptr + o; }                                      \
+    friend inline difference_type operator-(const itor& i1,           \
+                                            const itor& i2)           \
+        { return i1.m_ptr - i2.m_ptr; }                               \
+                                                                      \
   public:                                                             \
     pointer m_ptr;                                                    \
     const_reverse_iterator() : m_ptr(NULL) { }                        \
   public:                                                             \
     pointer m_ptr;                                                    \
     const_reverse_iterator() : m_ptr(NULL) { }                        \
@@ -434,21 +468,8 @@ public:                                                               \
   void reserve(size_type n) { base::reserve(n); };                    \
   void resize(size_type n, value_type v = value_type());              \
   size_type size() const { return base::size(); }                     \
   void reserve(size_type n) { base::reserve(n); };                    \
   void resize(size_type n, value_type v = value_type());              \
   size_type size() const { return base::size(); }                     \
-};                                                                    \
-                                                                      \
-inline name::reverse_iterator operator+(int o, const name::reverse_iterator& it) { return it.m_ptr - o; } \
-inline name::reverse_iterator operator+(const name::reverse_iterator& it, int o) { return it.m_ptr - o; } \
-inline name::reverse_iterator operator-(const name::reverse_iterator& it, int o) { return it.m_ptr + o; } \
-inline name::difference_type operator -(const name::reverse_iterator& i1, \
-                             const name::reverse_iterator& i2)            \
-    { return i1.m_ptr - i2.m_ptr; }                                       \
-                                                                      \
-inline name::const_reverse_iterator operator+(int o, const name::const_reverse_iterator& it) { return it.m_ptr - o; } \
-inline name::const_reverse_iterator operator+(const name::const_reverse_iterator& it, int o) { return it.m_ptr - o; } \
-inline name::const_reverse_iterator operator-(const name::const_reverse_iterator& it, int o) { return it.m_ptr + o; } \
-inline name::difference_type operator -(const name::const_reverse_iterator& i1,\
-                             const name::const_reverse_iterator& i2)      \
-    { return i1.m_ptr - i2.m_ptr; }                                       \
+}
+
 
 #endif // !wxUSE_STL
 
 
 #endif // !wxUSE_STL
 
@@ -458,11 +479,12 @@ inline name::difference_type operator -(const name::const_reverse_iterator& i1,\
 // ----------------------------------------------------------------------------
 
 #define _WX_DEFINE_SORTED_TYPEARRAY_2(T, name, base, defcomp, classexp, comptype)\
 // ----------------------------------------------------------------------------
 
 #define _WX_DEFINE_SORTED_TYPEARRAY_2(T, name, base, defcomp, classexp, comptype)\
-wxCOMPILE_TIME_ASSERT2(sizeof(T) <= sizeof(void *),                   \
+wxCOMPILE_TIME_ASSERT2(sizeof(T) <= sizeof(base::base_type),          \
                        TypeTooBigToBeStoredInSorted##base,            \
                        name);                                         \
 classexp name : public base                                           \
 {                                                                     \
                        TypeTooBigToBeStoredInSorted##base,            \
                        name);                                         \
 classexp name : public base                                           \
 {                                                                     \
+  typedef comptype SCMPFUNC;                                          \
 public:                                                               \
   name(comptype fn defcomp) { m_fnCompare = fn; }                     \
                                                                       \
 public:                                                               \
   name(comptype fn defcomp) { m_fnCompare = fn; }                     \
                                                                       \