Use template functions instead of WX_XXX_ARRAY() macros

Trivially rewrite macros as functions.

No real changes.
This commit is contained in:
Vadim Zeitlin
2018-06-01 18:13:35 +02:00
parent 97684a9267
commit 0e99ab2c49

View File

@@ -864,32 +864,34 @@ WX_DEFINE_USER_EXPORTED_ARRAY_LONG(long, wxArrayLong, class WXDLLIMPEXP_BASE);
WX_DEFINE_USER_EXPORTED_ARRAY_PTR(void *, wxArrayPtrVoid, class WXDLLIMPEXP_BASE); WX_DEFINE_USER_EXPORTED_ARRAY_PTR(void *, wxArrayPtrVoid, class WXDLLIMPEXP_BASE);
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// convenience macros // convenience functions: they used to be macros, hence the naming convention
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// prepend all element of one array to another one; e.g. if first array contains // prepend all element of one array to another one; e.g. if first array contains
// elements X,Y,Z and the second contains A,B,C (in those orders), then the // elements X,Y,Z and the second contains A,B,C (in those orders), then the
// first array will be result as A,B,C,X,Y,Z // first array will be result as A,B,C,X,Y,Z
#define WX_PREPEND_ARRAY(array, other) \ template <typename A1, typename A2>
{ \ inline void WX_PREPEND_ARRAY(A1& array, const A2& other)
size_t wxAAcnt = (other).size(); \ {
(array).reserve(wxAAcnt); \ const size_t size = other.size();
for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \ array.reserve(size);
{ \ for ( size_t n = 0; n < size; n++ )
(array).Insert((other)[wxAAn], wxAAn); \ {
} \ array.Insert(other[n], n);
} }
}
// append all element of one array to another one // append all element of one array to another one
#define WX_APPEND_ARRAY(array, other) \ template <typename A1, typename A2>
{ \ inline void WX_APPEND_ARRAY(A1& array, const A2& other)
size_t wxAAcnt = (other).size(); \ {
(array).reserve(wxAAcnt); \ size_t size = other.size();
for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \ array.reserve(size);
{ \ for ( size_t n = 0; n < size; n++ )
(array).push_back((other)[wxAAn]); \ {
} \ array.push_back(other[n]);
} }
}
// delete all array elements // delete all array elements
// //
@@ -897,15 +899,16 @@ WX_DEFINE_USER_EXPORTED_ARRAY_PTR(void *, wxArrayPtrVoid, class WXDLLIMPEXP_BASE
// place where you use this macro, otherwise the proper destructor may not // place where you use this macro, otherwise the proper destructor may not
// be called (a decent compiler should give a warning about it, but don't // be called (a decent compiler should give a warning about it, but don't
// count on it)! // count on it)!
#define WX_CLEAR_ARRAY(array) \ template <typename A>
{ \ inline void WX_CLEAR_ARRAY(A& array)
size_t wxAAcnt = (array).size(); \ {
for ( size_t wxAAn = 0; wxAAn < wxAAcnt; wxAAn++ ) \ size_t size = array.size();
{ \ for ( size_t n = 0; n < size; n++ )
delete (array)[wxAAn]; \ {
} \ delete array[n];
\
(array).clear(); \
} }
array.clear();
}
#endif // _DYNARRAY_H #endif // _DYNARRAY_H