Added tests of comparison operators

This commit is contained in:
Benoit Blanchon
2014-11-03 18:23:39 +01:00
parent 21e073a3b4
commit f224408c07
3 changed files with 168 additions and 2 deletions

View File

@ -78,6 +78,11 @@ class JsonValue {
return static_cast<T>(*this);
}
template <typename T>
bool is() const {
return false;
}
static JsonValue &invalid() { return _invalid; }
bool success() { return _type != Internals::JSON_INVALID; }
@ -93,6 +98,16 @@ class JsonValue {
static JsonValue _invalid;
};
template <>
inline bool JsonValue::is<long>() const {
return _type == Internals::JSON_LONG;
}
template <>
inline bool JsonValue::is<double>() const {
return _type >= Internals::JSON_DOUBLE_0_DECIMALS;
}
template <typename T>
inline bool operator==(const JsonValue &left, T right) {
return left.as<T>() == right;
@ -102,4 +117,54 @@ template <typename T>
inline bool operator==(T left, const JsonValue &right) {
return left == right.as<T>();
}
template <typename T>
inline bool operator!=(const JsonValue &left, T right) {
return left.as<T>() != right;
}
template <typename T>
inline bool operator!=(T left, const JsonValue &right) {
return left != right.as<T>();
}
template <typename T>
inline bool operator<=(const JsonValue &left, T right) {
return left.as<T>() <= right;
}
template <typename T>
inline bool operator<=(T left, const JsonValue &right) {
return left <= right.as<T>();
}
template <typename T>
inline bool operator>=(const JsonValue &left, T right) {
return left.as<T>() >= right;
}
template <typename T>
inline bool operator>=(T left, const JsonValue &right) {
return left >= right.as<T>();
}
template <typename T>
inline bool operator<(const JsonValue &left, T right) {
return left.as<T>() < right;
}
template <typename T>
inline bool operator<(T left, const JsonValue &right) {
return left < right.as<T>();
}
template <typename T>
inline bool operator>(const JsonValue &left, T right) {
return left.as<T>() > right;
}
template <typename T>
inline bool operator>(T left, const JsonValue &right) {
return left > right.as<T>();
}
}