Replace most of _WX_DEFINE_SORTED_TYPEARRAY_2 with template too

Add wxBaseSortedArray<> template instead of putting all the code inside
_WX_DEFINE_SORTED_TYPEARRAY_2 macro.

There should be no changes, but the code is now easier to read and
modify.
This commit is contained in:
Vadim Zeitlin
2018-06-01 16:24:23 +02:00
parent b0d6b11ebe
commit aaa9c80d66

View File

@@ -212,52 +212,52 @@ public:
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#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(base::base_type), \ typedef wxBaseSortedArray<T, comptype> wxBaseSortedArrayFor##name; \
TypeTooBigToBeStoredInSorted##base, \ classexp name : public wxBaseSortedArrayFor##name \
name); \ { \
classexp name : public base \ public: \
{ \ name(comptype fn defcomp) : wxBaseSortedArrayFor##name(fn) { } \
typedef comptype SCMPFUNC; \ }
public: \
name(comptype fn defcomp) { m_fnCompare = fn; } \
\ template <typename T, typename Cmp>
name& operator=(const name& src) \ class wxBaseSortedArray : public wxBaseArray<T>
{ base* temp = (base*) this; \ {
(*temp) = ((const base&)src); \ typedef typename wxBaseArray<T>::CMPFUNC CMPFUNC;
m_fnCompare = src.m_fnCompare; \
return *this; } \ public:
\ explicit wxBaseSortedArray(Cmp fn) : m_fnCompare(fn) { }
T& operator[](size_t uiIndex) const \
{ return (T&)(base::operator[](uiIndex)); } \ wxBaseSortedArray& operator=(const wxBaseSortedArray& src)
T& Item(size_t uiIndex) const \ {
{ return (T&)(base::operator[](uiIndex)); } \ wxBaseArray<T>::operator=(src);
T& Last() const \ m_fnCompare = src.m_fnCompare;
{ return (T&)(base::operator[](size() - 1)); } \ return *this;
\ }
int Index(T lItem) const \
{ return base::Index(lItem, (CMPFUNC)m_fnCompare); } \ size_t IndexForInsert(T item) const
\ {
size_t IndexForInsert(T lItem) const \ return this->IndexForInsert(item, (CMPFUNC)m_fnCompare);
{ return base::IndexForInsert(lItem, (CMPFUNC)m_fnCompare); } \ }
\
void AddAt(T item, size_t index) \ void AddAt(T item, size_t index)
{ base::insert(begin() + index, item); } \ {
\ this->insert(this->begin() + index, item);
size_t Add(T lItem) \ }
{ return base::Add(lItem, (CMPFUNC)m_fnCompare); } \
void push_back(T lItem) \ size_t Add(T item)
{ Add(lItem); } \ {
\ return this->wxBaseArray<T>::Add(item, (CMPFUNC)m_fnCompare);
void RemoveAt(size_t uiIndex, size_t nRemove = 1) \ }
{ base::erase(begin() + uiIndex, begin() + uiIndex + nRemove); } \
void Remove(T lItem) \ void push_back(T item)
{ int iIndex = Index(lItem); \ {
wxCHECK_RET( iIndex != wxNOT_FOUND, _WX_ERROR_REMOVE ); \ Add(item);
base::erase(begin() + iIndex); } \ }
\
private: \ private:
comptype m_fnCompare; \ Cmp m_fnCompare;
} };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------