- These macros are ugly (especially if you look in the sources ;-), but they
- allow us to define 'template' classes without actually using templates.
- <BR>
- <BR>
- Range checking is performed in debug build for both arrays and lists. Type
- checking is done at compile-time. Warning: arrays <I>never</I> shrink, they
- only grow, so loading 10 millions in an array only to delete them 2 lines
- below is <I>not</I> recommended. However, it does free memory when it's
- destroyed, so if you destroy array also, it's ok.
- */
-// ----------------------------------------------------------------------------
-
-//@{
- /**
- This macro generates a new array class. It is intended for storage of simple
- types of sizeof()<=sizeof(long) or pointers if sizeof(pointer)<=sizeof(long)
- <BR>
- NB: it has only inline functions => takes no space at all
- <BR>
-
- @memo declare and define array class 'name' containing elements of type 'T'
- */
-#define WX_DEFINE_ARRAY(T, name) typedef T _A##name; \
- _WX_DEFINE_ARRAY(_A##name, name)
-
- /**
- This macro does the same as WX_DEFINE_ARRAY except that the array will be
- sorted with the specified compare function.
- */
-#define WX_DEFINE_SORTED_ARRAY(T, name) typedef T _A##name; \
- _WX_DEFINE_SORTED_ARRAY(_A##name, name)
-
- /**
- This macro generates a new list class which owns the objects it contains,
- i.e. it will delete them when it is destroyed. An element is of type T*,
- but arguments of type T& are taken (see below!) and T& is returned.
- <BR>
- Don't use this for simple types such as "int" or "long"!
- You _may_ use it for "double" but it's awfully inefficient.
- <BR>
- <BR>
- Note on Add/Insert functions:
- <BR>
- 1) function(T*) gives the object to the list, i.e. it will delete the
- object when it's removed or in the list's dtor
- <BR>
- 2) function(T&) will create a copy of the object and work with it
- <BR>
- <BR>
- Also:
- <BR>
- 1) Remove() will delete the object after removing it from the list
- <BR>
- 2) Detach() just removes the object from the list (returning pointer to it)
- <BR>
- <BR>
- NB1: Base type T should have an accessible copy ctor if Add(T&) is used,
- <BR>
- NB2: Never ever cast a list to it's base type: as dtor is <B>not</B> virtual
- it will provoke memory leaks
- <BR>
- <BR>
- some functions of this class are not inline, so it takes some space to
- define new class from this template.
-
- @memo declare list class 'name' containing elements of type 'T'
- */
-#define WX_DECLARE_LIST(T, name) typedef T _L##name; \
- _WX_DECLARE_LIST(_L##name, name)
- /**
- To use a list class you must
- <ll>
- <li>#include "dynarray.h"
- <li>DECLARE_LIST(element_type, list_class_name)
- <li>#include "listimpl.cpp"
- <li>DEFINE_LIST(list_class_name) // same as above!
- </ll>
- <BR><BR>
- This is necessary because at the moment of DEFINE_LIST class element_type
- must be fully defined (i.e. forward declaration is not enough), while
- DECLARE_LIST may be done anywhere. The separation of two allows to break
- cicrcular dependencies with classes which have member variables of list
- type.
-
- @memo define (must include listimpl.cpp!) list class 'name'
- */
-#define WX_DEFINE_LIST(name) "don't forget to include listimpl.cpp!"
-//@}
-
-// ----------------------------------------------------------------------------
-/** @name Some commonly used predefined arrays */
-// # overhead if not used?
-// ----------------------------------------------------------------------------
-
-//@{
- /** @name ArrayInt */
-WX_DEFINE_ARRAY(int, wxArrayInt);
- /** @name ArrayLong */
-WX_DEFINE_ARRAY(long, wxArrayLong);
- /** @name ArrayPtrVoid */
-WX_DEFINE_ARRAY(void *, wxArrayPtrVoid);
-//@}
-
-//@}
+WX_DECLARE_USER_EXPORTED_BASEARRAY(const void *, wxBaseArrayPtrVoid,
+ WXDLLIMPEXP_BASE);
+WX_DECLARE_USER_EXPORTED_BASEARRAY(short, wxBaseArrayShort, WXDLLIMPEXP_BASE);
+WX_DECLARE_USER_EXPORTED_BASEARRAY(int, wxBaseArrayInt, WXDLLIMPEXP_BASE);
+WX_DECLARE_USER_EXPORTED_BASEARRAY(long, wxBaseArrayLong, WXDLLIMPEXP_BASE);
+WX_DECLARE_USER_EXPORTED_BASEARRAY(size_t, wxBaseArraySizeT, WXDLLIMPEXP_BASE);
+WX_DECLARE_USER_EXPORTED_BASEARRAY(double, wxBaseArrayDouble, WXDLLIMPEXP_BASE);
+
+// ----------------------------------------------------------------------------
+// Convenience macros to define arrays from base arrays
+// ----------------------------------------------------------------------------
+
+#define WX_DEFINE_ARRAY(T, name) \
+ WX_DEFINE_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
+#define WX_DEFINE_ARRAY_PTR(T, name) \
+ WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayPtrVoid)
+#define WX_DEFINE_EXPORTED_ARRAY(T, name) \
+ WX_DEFINE_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
+#define WX_DEFINE_EXPORTED_ARRAY_PTR(T, name) \
+ WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayPtrVoid)
+#define WX_DEFINE_ARRAY_WITH_DECL_PTR(T, name, decl) \
+ WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayPtrVoid, decl)
+#define WX_DEFINE_USER_EXPORTED_ARRAY(T, name, expmode) \
+ WX_DEFINE_TYPEARRAY_WITH_DECL(T, name, wxBaseArrayPtrVoid, expmode)
+#define WX_DEFINE_USER_EXPORTED_ARRAY_PTR(T, name, expmode) \
+ WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayPtrVoid, expmode)
+
+#define WX_DEFINE_ARRAY_SHORT(T, name) \
+ WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayShort)
+#define WX_DEFINE_EXPORTED_ARRAY_SHORT(T, name) \
+ WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayShort)
+#define WX_DEFINE_USER_EXPORTED_ARRAY_SHORT(T, name, expmode) \
+ WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayShort, expmode)
+
+#define WX_DEFINE_ARRAY_INT(T, name) \
+ WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayInt)
+#define WX_DEFINE_EXPORTED_ARRAY_INT(T, name) \
+ WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayInt)
+#define WX_DEFINE_USER_EXPORTED_ARRAY_INT(T, name, expmode) \
+ WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayInt, expmode)
+
+#define WX_DEFINE_ARRAY_LONG(T, name) \
+ WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayLong)
+#define WX_DEFINE_EXPORTED_ARRAY_LONG(T, name) \
+ WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayLong)
+#define WX_DEFINE_USER_EXPORTED_ARRAY_LONG(T, name, expmode) \
+ WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayLong, expmode)
+
+#define WX_DEFINE_ARRAY_SIZE_T(T, name) \
+ WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArraySizeT)
+#define WX_DEFINE_EXPORTED_ARRAY_SIZE_T(T, name) \
+ WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArraySizeT)
+#define WX_DEFINE_USER_EXPORTED_ARRAY_SIZE_T(T, name, expmode) \
+ WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArraySizeT, expmode)
+
+#define WX_DEFINE_ARRAY_DOUBLE(T, name) \
+ WX_DEFINE_TYPEARRAY_PTR(T, name, wxBaseArrayDouble)
+#define WX_DEFINE_EXPORTED_ARRAY_DOUBLE(T, name) \
+ WX_DEFINE_EXPORTED_TYPEARRAY_PTR(T, name, wxBaseArrayDouble)
+#define WX_DEFINE_USER_EXPORTED_ARRAY_DOUBLE(T, name, expmode) \
+ WX_DEFINE_TYPEARRAY_WITH_DECL_PTR(T, name, wxBaseArrayDouble, expmode)
+
+// ----------------------------------------------------------------------------
+// Convenience macros to define sorted arrays from base arrays
+// ----------------------------------------------------------------------------
+
+#define WX_DEFINE_SORTED_ARRAY(T, name) \
+ WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY(T, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(T, name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayPtrVoid, expmode)
+
+#define WX_DEFINE_SORTED_ARRAY_SHORT(T, name) \
+ WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayShort)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_SHORT(T, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayShort)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SHORT(T, name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayShort, expmode)
+
+#define WX_DEFINE_SORTED_ARRAY_INT(T, name) \
+ WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayInt)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_INT(T, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayInt)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_INT(T, name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayInt, expmode)
+
+#define WX_DEFINE_SORTED_ARRAY_LONG(T, name) \
+ WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArrayLong)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_LONG(T, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArrayLong)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_LONG(T, name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArrayLong, expmode)
+
+#define WX_DEFINE_SORTED_ARRAY_SIZE_T(T, name) \
+ WX_DEFINE_SORTED_TYPEARRAY(T, name, wxBaseArraySizeT)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_SIZE_T(T, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY(T, name, wxBaseArraySizeT)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_SIZE_T(T, name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY(T, name, wxBaseArraySizeT, expmode)
+
+// ----------------------------------------------------------------------------
+// Convenience macros to define sorted arrays from base arrays
+// ----------------------------------------------------------------------------
+
+#define WX_DEFINE_SORTED_ARRAY_CMP(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayPtrVoid)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayPtrVoid)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP(T, cmpfunc, \
+ name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
+ wxBaseArrayPtrVoid, expmode)
+
+#define WX_DEFINE_SORTED_ARRAY_CMP_SHORT(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayShort)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SHORT(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayShort)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_SHORT(T, cmpfunc, \
+ name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
+ wxBaseArrayShort, expmode)
+
+#define WX_DEFINE_SORTED_ARRAY_CMP_INT(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayInt)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_INT(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayInt)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_INT(T, cmpfunc, \
+ name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
+ wxBaseArrayInt, expmode)
+
+#define WX_DEFINE_SORTED_ARRAY_CMP_LONG(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayLong)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_LONG(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArrayLong)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_LONG(T, cmpfunc, \
+ name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
+ wxBaseArrayLong, expmode)
+
+#define WX_DEFINE_SORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArraySizeT)
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, name) \
+ WX_DEFINE_SORTED_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, wxBaseArraySizeT)
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_CMP_SIZE_T(T, cmpfunc, \
+ name, expmode) \
+ WX_DEFINE_SORTED_USER_EXPORTED_TYPEARRAY_CMP(T, cmpfunc, name, \
+ wxBaseArraySizeT, expmode)
+
+// ----------------------------------------------------------------------------
+// Some commonly used predefined arrays
+// ----------------------------------------------------------------------------
+
+WX_DEFINE_USER_EXPORTED_ARRAY_SHORT(short, wxArrayShort, class WXDLLIMPEXP_BASE);
+WX_DEFINE_USER_EXPORTED_ARRAY_INT(int, wxArrayInt, class WXDLLIMPEXP_BASE);
+WX_DEFINE_USER_EXPORTED_ARRAY_LONG(long, wxArrayLong, class WXDLLIMPEXP_BASE);
+WX_DEFINE_USER_EXPORTED_ARRAY_PTR(void *, wxArrayPtrVoid, class WXDLLIMPEXP_BASE);
+
+// -----------------------------------------------------------------------------
+// convenience macros
+// -----------------------------------------------------------------------------
+
+// append all element of one array to another one
+#define WX_APPEND_ARRAY(array, other) \
+ { \
+ size_t count = (other).size(); \
+ for ( size_t n = 0; n < count; n++ ) \
+ { \
+ (array).push_back((other)[n]); \
+ } \
+ }
+
+// delete all array elements
+//
+// NB: the class declaration of the array elements must be visible from the
+// 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
+// count on it)!
+#define WX_CLEAR_ARRAY(array) \
+ { \
+ size_t count = (array).size(); \
+ for ( size_t n = 0; n < count; n++ ) \
+ { \
+ delete (array)[n]; \
+ } \
+ \
+ (array).clear(); \
+ }