+// _WX_DEFINE_SORTED_TYPEARRAY: sorted array for simple data types
+// cannot handle types with size greater than pointer because of sorting
+// ----------------------------------------------------------------------------
+
+#define _WX_DEFINE_SORTED_TYPEARRAY(T, name, base, defcomp, classexp) \
+wxCOMPILE_TIME_ASSERT2(sizeof(T) <= sizeof(void *), \
+ TypeTooBigToBeStoredInSorted##base, \
+ name); \
+typedef int (CMPFUNC_CONV *SCMPFUNC##T)(T pItem1, T pItem2); \
+classexp name : public base \
+{ \
+public: \
+ name(SCMPFUNC##T fn defcomp) { m_fnCompare = fn; } \
+ \
+ name& operator=(const name& src) \
+ { base* temp = (base*) this; \
+ (*temp) = ((const base&)src); \
+ m_fnCompare = src.m_fnCompare; \
+ return *this; } \
+ \
+ T& operator[](size_t uiIndex) const \
+ { return (T&)(base::Item(uiIndex)); } \
+ T& Item(size_t uiIndex) const \
+ { return (T&)(base::Item(uiIndex)); } \
+ T& Last() const \
+ { return (T&)(base::Item(Count() - 1)); } \
+ \
+ int Index(T Item) const \
+ { return base::Index(Item, (CMPFUNC)m_fnCompare); } \
+ \
+ size_t IndexForInsert(T Item) const \
+ { return base::IndexForInsert(Item, (CMPFUNC)m_fnCompare); } \
+ \
+ void AddAt(T item, size_t index) \
+ { base::Insert(item, index); } \
+ \
+ void Add(T Item) \
+ { base::Add(Item, (CMPFUNC)m_fnCompare); } \
+ \
+ void RemoveAt(size_t uiIndex, size_t nRemove = 1) \
+ { base::RemoveAt(uiIndex, nRemove); } \
+ void Remove(T Item) \
+ { int iIndex = Index(Item); \
+ wxCHECK2_MSG( iIndex != wxNOT_FOUND, return, \
+ _WX_ERROR_REMOVE ); \
+ base::RemoveAt((size_t)iIndex); } \
+ \
+private: \
+ SCMPFUNC##T m_fnCompare; \
+}
+
+// ----------------------------------------------------------------------------
+// _WX_DECLARE_OBJARRAY: an array for pointers to type T with owning semantics
+// ----------------------------------------------------------------------------
+
+#define _WX_DECLARE_OBJARRAY(T, name, base, classexp) \
+typedef int (CMPFUNC_CONV *CMPFUNC##T)(T **pItem1, T **pItem2); \
+classexp name : public base \
+{ \
+typedef int (CMPFUNC_CONV *CMPFUNC##base)(void **pItem1, void **pItem2); \
+public: \
+ name() { } \
+ name(const name& src); \
+ name& operator=(const name& src); \
+ \
+ ~name(); \
+ \
+ T& operator[](size_t uiIndex) const \
+ { return *(T*)base::Item(uiIndex); } \
+ T& Item(size_t uiIndex) const \
+ { return *(T*)base::Item(uiIndex); } \
+ T& Last() const \
+ { return *(T*)(base::Item(Count() - 1)); } \
+ \
+ int Index(const T& Item, bool bFromEnd = FALSE) const; \
+ \
+ void Add(const T& Item, size_t nInsert = 1); \
+ void Add(const T* pItem) \
+ { base::Add((T*)pItem); } \
+ \
+ void Insert(const T& Item, size_t uiIndex, size_t nInsert = 1); \
+ void Insert(const T* pItem, size_t uiIndex) \
+ { base::Insert((T*)pItem, uiIndex); } \
+ \
+ void Empty() { DoEmpty(); base::Empty(); } \
+ void Clear() { DoEmpty(); base::Clear(); } \
+ \
+ T* Detach(size_t uiIndex) \
+ { T* p = (T*)base::Item(uiIndex); \
+ base::RemoveAt(uiIndex); return p; } \
+ void RemoveAt(size_t uiIndex, size_t nRemove = 1); \
+ \
+ void Sort(CMPFUNC##T fCmp) { base::Sort((CMPFUNC##base)fCmp); } \
+ \
+private: \
+ void DoEmpty(); \
+ void DoCopy(const name& src); \
+}
+
+// ============================================================================
+// The public macros for declaration and definition of the dynamic arrays
+// ============================================================================
+
+// Please note that for each macro WX_FOO_ARRAY we also have
+// WX_FOO_EXPORTED_ARRAY and WX_FOO_USER_EXPORTED_ARRAY which are exactly the
+// same except that they use an additional __declspec(dllexport) or equivalent
+// under Windows if needed.
+//
+// The first (just EXPORTED) macros do it if wxWindows was compiled as a DLL
+// and so must be used used inside the library. The second kind (USER_EXPORTED)
+// allow the user code to do it when it wants. This is needed if you have a dll
+// that wants to export a wxArray daubed with your own import/export goo.
+//
+// Finally, you can define the macro below as something special to modify the
+// arrays defined by a simple WX_FOO_ARRAY as well. By default is is empty.
+#define wxARRAY_DEFAULT_EXPORT
+
+// ----------------------------------------------------------------------------
+// WX_DECLARE_BASEARRAY(T, name) declare an array class named "name" containing
+// the elements of type T
+// ----------------------------------------------------------------------------
+
+#define WX_DECLARE_BASEARRAY(T, name) \
+ WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
+
+#define WX_DECLARE_EXPORTED_BASEARRAY(T, name) \
+ WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, WXDLLEXPORT)
+
+#define WX_DECLARE_USER_EXPORTED_BASEARRAY(T, name, expmode) \
+ typedef T _wxArray##name; \
+ _WX_DECLARE_BASEARRAY(_wxArray##name, name, class expmode)
+
+// ----------------------------------------------------------------------------
+// WX_DEFINE_TYPEARRAY(T, name, base) define an array class named "name" deriving
+// from class "base" containing the elements of type T
+//
+// Note that the class defined has only inline function and doesn't take any
+// space at all so there is no size penalty for defining multiple array classes
+// ----------------------------------------------------------------------------
+
+#define WX_DEFINE_TYPEARRAY(T, name, base) \
+ WX_DEFINE_USER_EXPORTED_TYPEARRAY(T, name, base, wxARRAY_DEFAULT_EXPORT)
+
+#define WX_DEFINE_EXPORTED_TYPEARRAY(T, name, base) \
+ WX_DEFINE_USER_EXPORTED_TYPEARRAY(T, name, base, WXDLLEXPORT)
+
+#define WX_DEFINE_USER_EXPORTED_TYPEARRAY(T, name, base, expmode) \
+ typedef T _wxArray##name; \
+ _WX_DEFINE_TYPEARRAY(_wxArray##name, name, base, class expmode)
+
+// ----------------------------------------------------------------------------
+// WX_DEFINE_SORTED_TYPEARRAY: this is the same as the previous macro, but it
+// defines a sorted array.
+//