- 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.
- */
+#define WX_DEFINE_ARRAY(T, name) \
+ WX_DEFINE_USER_EXPORTED_ARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
+
+#define WX_DEFINE_EXPORTED_ARRAY(T, name) \
+ WX_DEFINE_USER_EXPORTED_ARRAY(T, name, WXDLLEXPORT)
+
+#define WX_DEFINE_USER_EXPORTED_ARRAY(T, name, expmode) \
+ typedef T _wxArray##name; \
+ _WX_DEFINE_ARRAY(_wxArray##name, name, class expmode)
+
+// ----------------------------------------------------------------------------
+// WX_DEFINE_SORTED_ARRAY: this is the same as the previous macro, but it
+// defines a sorted array.
+//
+// Differences:
+// 1) it must be given a COMPARE function in ctor which takes 2 items of type
+// T* and should return -1, 0 or +1 if the first one is less/greater
+// than/equal to the second one.
+// 2) the Add() method inserts the item in such was that the array is always
+// sorted (it uses the COMPARE function)
+// 3) it has no Sort() method because it's always sorted
+// 4) Index() method is much faster (the sorted arrays use binary search
+// instead of linear one), but Add() is slower.
+// 5) there is no Insert() method because you can't insert an item into the
+// given position in a sorted array but there is IndexForInsert()/AddAt()
+// pair which may be used to optimize a common operation of "insert only if
+// not found"
+//
+// Note that you have to specify the comparison function when creating the
+// objects of this array type. If, as in 99% of cases, the comparison function
+// is the same for all objects of a class, WX_DEFINE_SORTED_ARRAY_CMP below is
+// more convenient.
+//
+// Summary: use this class when the speed of Index() function is important, use
+// the normal arrays otherwise.
+// ----------------------------------------------------------------------------
+
+#define wxARRAY_EMPTY_CMP
+
+#define WX_DEFINE_SORTED_ARRAY(T, name) \
+ WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(T, name, wxARRAY_DEFAULT_EXPORT)
+
+#define WX_DEFINE_SORTED_EXPORTED_ARRAY(T, name) \
+ WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(T, name, WXDLLEXPORT)
+
+#define WX_DEFINE_SORTED_USER_EXPORTED_ARRAY(T, name, expmode) \
+ typedef T _wxArray##name; \
+ _WX_DEFINE_SORTED_ARRAY(_wxArray##name, name, wxARRAY_EMPTY_CMP, class expmode)
+
+// ----------------------------------------------------------------------------
+// WX_DEFINE_SORTED_ARRAY_CMP: exactly the same as above but the comparison
+// function is provided by this macro and the objects of this class have a
+// default constructor which just uses it.
+//
+// The arguments are: the element type, the comparison function and the array
+// name
+//
+// NB: this is, of course, how WX_DEFINE_SORTED_ARRAY() should have worked from
+// the very beginning - unfortunately I didn't think about this earlier :-(