From 063ab2e40f5fb9570ed7a7232f6d98b9e4547cda Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 30 Dec 2011 11:37:43 -0800 Subject: [PATCH] cmp.h: define macros for creating comparison operators Signed-off-by: Sage Weil --- src/Makefile.am | 1 + src/include/cmp.h | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/include/cmp.h diff --git a/src/Makefile.am b/src/Makefile.am index 9aaf5835f1066..e2b69c8b2c75e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1148,6 +1148,7 @@ noinst_HEADERS = \ include/ceph_frag.h\ include/ceph_fs.h\ include/ceph_hash.h\ + include/cmp.h\ include/color.h\ include/compat.h\ include/crc32c.h\ diff --git a/src/include/cmp.h b/src/include/cmp.h new file mode 100644 index 0000000000000..e72d8cd7ee897 --- /dev/null +++ b/src/include/cmp.h @@ -0,0 +1,105 @@ +#ifndef __CEPH_CMP_H +#define __CEPH_CMP_H + +/* + * macros to define comparison operators for classes with small numbers of members. + */ + +#define WRITE_EQ_OPERATORS_2(type, a, b) \ + inline bool operator==(const type &l, const type &r) { \ + return l.a == r.a && l.b == r.b; \ + } \ + inline bool operator!=(const type &l, const type &r) { \ + return l.a != r.a || l.b != r.b; \ + } + +#define WRITE_CMP_OPERATORS_2(type, a, b) \ + inline bool operator>(const type &l, const type &r) { \ + return l.a > r.a || \ + (l.a == r.a && (l.b > r.b)); \ + } \ + inline bool operator<(const type &l, const type &r) { \ + return l.a < r.a || \ + (l.a == r.a && (l.b < r.b)); \ + } \ + inline bool operator>=(const type &l, const type &r) { \ + return l.a > r.a || \ + (l.a == r.a && (l.b >= r.b)); \ + } \ + inline bool operator<=(const type &l, const type &r) { \ + return l.a < r.a || \ + (l.a == r.a && (l.b <= r.b)); \ + } + + +#define WRITE_EQ_OPERATORS_3(type, a, b, c) \ + inline bool operator==(const type &l, const type &r) { \ + return l.a == r.a && l.b == r.b && l.c == r.c; \ + } \ + inline bool operator!=(const type &l, const type &r) { \ + return l.a != r.a || l.b != r.b || l.c != r.c; \ + } + +#define WRITE_CMP_OPERATORS_3(type, a, b, c) \ + inline bool operator>(const type &l, const type &r) { \ + return l.a > r.a || \ + (l.a == r.a && (l.b > r.b || \ + (l.b == r.b && (l.c > r.c)))); \ + } \ + inline bool operator<(const type &l, const type &r) { \ + return l.a < r.a || \ + (l.a == r.a && (l.b < r.b || \ + (l.b == r.b && (l.c < r.c)))); \ + } \ + inline bool operator>=(const type &l, const type &r) { \ + return l.a > r.a || \ + (l.a == r.a && (l.b > r.b || \ + (l.b == r.b && (l.c >= r.c)))); \ + } \ + inline bool operator<=(const type &l, const type &r) { \ + return l.a < r.a || \ + (l.a == r.a && (l.b < r.b || \ + (l.b == r.b && (l.c <= r.c)))); \ + } + + + +#define WRITE_EQ_OPERATORS_5(type, a, b, c, d, e) \ + inline bool operator==(const type &l, const type &r) { \ + return l.a == r.a && l.b == r.b && l.c == r.c && l.d == r.e && l.e == r.e; \ + } \ + inline bool operator!=(const type &l, const type &r) { \ + return l.a != r.a || l.b != r.b || l.c != r.c || l.d != r.d || l.e != r.e; \ + } + +#define WRITE_CMP_OPERATORS_5(type, a, b, c, d, e) \ + inline bool operator>(const type &l, const type &r) { \ + return l.a > r.a || \ + (l.a == r.a && (l.b > r.b || \ + (l.b == r.b && (l.c > r.c || \ + (l.c == r.c && (l.d > r.d || \ + (l.d == r.d && l.e > r.e))))))); \ + } \ + inline bool operator<(const type &l, const type &r) { \ + return l.a < r.a || \ + (l.a == r.a && (l.b < r.b || \ + (l.b == r.b && (l.c < r.c || \ + (l.c == r.c && (l.d < r.d || \ + (l.d == r.d && (l.e < r.e)))))))); \ + } \ + inline bool operator>=(const type &l, const type &r) { \ + return l.a > r.a || \ + (l.a == r.a && (l.b > r.b || \ + (l.b == r.b && (l.c > r.c || \ + (l.c == r.c && (l.d > r.d || \ + (l.d == r.d && l.e >= r.e))))))); \ + } \ + inline bool operator<=(const type &l, const type &r) { \ + return l.a < r.a || \ + (l.a == r.a && (l.b < r.b || \ + (l.b == r.b && (l.c < r.c || \ + (l.c == r.c && (l.d < r.d || \ + (l.d == r.d && l.e <= r.e))))))); \ + } + +#endif -- 2.39.5