added macros to avoid code repetition when defining comparison operators; use them to replace existing operators in wxUniChar and wxUniCharRef (fixing bug in the operator== and != of the latter) and added comparison operators for const wxChar * and wxCStrData which are needed to compile existing code comparing pointers with s.c_str()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45019 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-03-22 18:03:02 +00:00
parent dbea442a15
commit fb52c2b671
3 changed files with 131 additions and 210 deletions

View File

@@ -547,6 +547,52 @@ typedef int wxWindowID;
/* integer on success as failure indicator */
#define wxNOT_FOUND (-1)
/* ---------------------------------------------------------------------------- */
/* macros dealing with comparison operators */
/* ---------------------------------------------------------------------------- */
/*
Expands into m(op, args...) for each op in the set { ==, !=, <, <=, >, >= }.
*/
#define wxFOR_ALL_COMPARISONS(m) \
m(==) m(!=) m(>=) m(<=) m(>) m(<)
#define wxFOR_ALL_COMPARISONS_1(m, x) \
m(==,x) m(!=,x) m(>=,x) m(<=,x) m(>,x) m(<,x)
#define wxFOR_ALL_COMPARISONS_2(m, x, y) \
m(==,x,y) m(!=,x,y) m(>=,x,y) m(<=,x,y) m(>,x,y) m(<,x,y)
#define wxFOR_ALL_COMPARISONS_3(m, x, y, z) \
m(==,x,y,z) m(!=,x,y,z) m(>=,x,y,z) m(<=,x,y,z) m(>,x,y,z) m(<,x,y,z)
#define wxDEFINE_COMPARISON(op, T1, T2, cmp) \
inline bool operator op(T1 x, T2 y) { return cmp(x, y, op); }
#define wxDEFINE_COMPARISON_REV(op, T1, T2, cmp) \
inline bool operator op(T2 y, T1 x) { return cmp(x, y, op); }
/*
Define all 6 comparison operators (==, !=, <, <=, >, >=) for the given
types in the specified order. The implementation is provided by the cmp
macro. Normally wxDEFINE_ALL_COMPARISONS should be used as comparison
operators are usually symmetric.
*/
#define wxDEFINE_COMPARISONS(T1, T2, cmp) \
wxFOR_ALL_COMPARISONS_3(wxDEFINE_COMPARISON, T1, T2, cmp)
/*
This macro allows to define all 12 comparison operators (6 operators for
both orders of arguments) for the given types using the provided "cmp"
macro to implement the actual comparison: the macro is called with the 2
arguments names, the first of type T1 and the second of type T2, and the
comparison operator being implemented.
*/
#define wxDEFINE_ALL_COMPARISONS(T1, T2, cmp) \
wxFOR_ALL_COMPARISONS_3(wxDEFINE_COMPARISON, T1, T2, cmp) \
wxFOR_ALL_COMPARISONS_3(wxDEFINE_COMPARISON_REV, T1, T2, cmp)
/* ---------------------------------------------------------------------------- */
/* macros to avoid compiler warnings */
/* ---------------------------------------------------------------------------- */