hidl_string: relational operators
Fixes: 34524287
Test: libhidl_test
Change-Id: Id0731e6df1fc1831d8c1bdf35b3aa17abd5273d2
diff --git a/base/include/hidl/HidlSupport.h b/base/include/hidl/HidlSupport.h
index 17951f7..6c00c3d 100644
--- a/base/include/hidl/HidlSupport.h
+++ b/base/include/hidl/HidlSupport.h
@@ -157,8 +157,6 @@
// to maintain this hidl_string alive.
operator const char *() const;
- bool operator< (const hidl_string &rhs) const;
-
void clear();
// Reference an external char array. Ownership is _not_ transferred.
@@ -181,29 +179,25 @@
void moveFrom(hidl_string &&);
};
-inline bool operator==(const hidl_string &hs1, const hidl_string &hs2) {
- return strcmp(hs1.c_str(), hs2.c_str()) == 0;
-}
+#define HIDL_STRING_OPERATOR(OP) \
+ inline bool operator OP(const hidl_string &hs1, const hidl_string &hs2) { \
+ return strcmp(hs1.c_str(), hs2.c_str()) OP 0; \
+ } \
+ inline bool operator OP(const hidl_string &hs, const char *s) { \
+ return strcmp(hs.c_str(), s) OP 0; \
+ } \
+ inline bool operator OP(const char *s, const hidl_string &hs) { \
+ return strcmp(hs.c_str(), s) OP 0; \
+ }
-inline bool operator!=(const hidl_string &hs1, const hidl_string &hs2) {
- return !(hs1 == hs2);
-}
+HIDL_STRING_OPERATOR(==)
+HIDL_STRING_OPERATOR(!=)
+HIDL_STRING_OPERATOR(<)
+HIDL_STRING_OPERATOR(<=)
+HIDL_STRING_OPERATOR(>)
+HIDL_STRING_OPERATOR(>=)
-inline bool operator==(const hidl_string &hs, const char *s) {
- return strcmp(hs.c_str(), s) == 0;
-}
-
-inline bool operator!=(const hidl_string &hs, const char *s) {
- return !(hs == s);
-}
-
-inline bool operator==(const char *s, const hidl_string &hs) {
- return strcmp(hs.c_str(), s) == 0;
-}
-
-inline bool operator!=(const char *s, const hidl_string &hs) {
- return !(s == hs);
-}
+#undef HIDL_STRING_OPERATOR
// hidl_memory is a structure that can be used to transfer
// pieces of shared memory between processes. The assumption