X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/31222b7cfa9aedad2a4d39e5fdafa540eb4c7c79..e14d10b039e68a701a447043a4031cf43e9fa90b:/include/wx/dynarray.h diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index 3228aee579..b06a1c2221 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -24,9 +24,6 @@ #include #include #include "wx/afterstd.h" - #if defined(__WXMSW__) && defined(__MINGW32__) - #include "wx/msw/winundef.h" - #endif #endif /* @@ -89,9 +86,43 @@ typedef int (wxCMPFUNC_CONV *CMPFUNC)(const void* pItem1, const void* pItem2); #if wxUSE_STL +template +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 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) \ + typedef int (wxCMPFUNC_CONV *CMPFUN##name)(T pItem1, T pItem2); \ + typedef wxSortedArray_SortFunction 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 \ { \ + typedef predicate Predicate; \ + typedef predicate::CMPFUNC SCMPFUNC; \ + typedef wxArray_SortFunction::CMPFUNC CMPFUNC; \ public: \ void Empty() { clear(); } \ void Clear() { clear(); } \ @@ -123,19 +154,9 @@ protected: \ \ void Sort(CMPFUNC fCmp) \ { \ - Predicate p(fCmp); \ + wxArray_SortFunction p(fCmp); \ 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 @@ -143,6 +164,7 @@ private: \ #define _WX_DECLARE_BASEARRAY(T, name, classexp) \ classexp name \ { \ + typedef CMPFUNC SCMPFUNC; /* for compatibility wuth wxUSE_STL */ \ public: \ name(); \ name(const name& array); \ @@ -457,11 +479,12 @@ public: \ // ---------------------------------------------------------------------------- #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 \ { \ + typedef comptype SCMPFUNC; \ public: \ name(comptype fn defcomp) { m_fnCompare = fn; } \ \