Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Value doesn't test operators ==,< and > with itself anymore.

  • Loading branch information...
commit 34b777dc74956e3fd7c55abb7db174ca90ec2832 1 parent e250ede
@madbranch madbranch authored
Showing with 71 additions and 57 deletions.
  1. +71 −57 src/Value.cpp
View
128 src/Value.cpp
@@ -219,123 +219,137 @@ namespace JsonBox {
return *this;
}
-
+
bool Value::operator==(const Value &rhs) const {
- if (type == rhs.type) {
- switch (type) {
+ bool result = true;
+
+ if (this != &rhs) {
+ if (type == rhs.type) {
+ switch (type) {
case STRING:
- return *data.stringValue == *data.stringValue;
+ result = (*data.stringValue == *data.stringValue);
break;
-
+
case INTEGER:
- return *data.intValue == *data.intValue;
+ result = (*data.intValue == *data.intValue);
break;
-
+
case DOUBLE:
- return *data.doubleValue == *data.doubleValue;
+ result = (*data.doubleValue == *data.doubleValue);
break;
-
+
case OBJECT:
- return *data.objectValue == *data.objectValue;
+ result = (*data.objectValue == *data.objectValue);
break;
-
+
case ARRAY:
- return *data.arrayValue == *data.arrayValue;
+ result = (*data.arrayValue == *data.arrayValue);
break;
-
+
case BOOLEAN:
- return *data.boolValue == *data.boolValue;
+ result = (*data.boolValue == *data.boolValue);
break;
-
+
default:
- return true;
break;
+ }
+
+ } else {
+ result = false;
}
- } else {
- return false;
}
+
+ return result;
}
-
+
bool Value::operator!=(const Value &rhs) const {
return !(*this == rhs);
}
-
+
bool Value::operator<(const Value &rhs) const {
- if (type == rhs.type) {
- switch (type) {
+ bool result = false;
+
+ if (this != &rhs) {
+ if (type == rhs.type) {
+ switch (type) {
case STRING:
- return *data.stringValue < *data.stringValue;
+ result = (*data.stringValue < *data.stringValue);
break;
-
+
case INTEGER:
- return *data.intValue < *data.intValue;
+ result = (*data.intValue < *data.intValue);
break;
-
+
case DOUBLE:
- return *data.doubleValue < *data.doubleValue;
+ result = (*data.doubleValue < *data.doubleValue);
break;
-
+
case OBJECT:
- return *data.objectValue < *data.objectValue;
+ result = (*data.objectValue < *data.objectValue);
break;
-
+
case ARRAY:
- return *data.arrayValue < *data.arrayValue;
+ result = (*data.arrayValue < *data.arrayValue);
break;
-
+
case BOOLEAN:
- return *data.boolValue < *data.boolValue;
+ result = (*data.boolValue < *data.boolValue);
break;
-
+
default:
- return false;
break;
+ }
+
}
- } else {
- return false;
}
+
+ return result;
}
-
+
bool Value::operator<=(const Value &rhs) const {
return *this < rhs || *this == rhs;
}
-
+
bool Value::operator>(const Value &rhs) const {
- if (type == rhs.type) {
- switch (type) {
+ bool result = false;
+
+ if (this != &rhs) {
+ if (type == rhs.type) {
+ switch (type) {
case STRING:
- return *data.stringValue > *data.stringValue;
+ result = (*data.stringValue > *data.stringValue);
break;
-
+
case INTEGER:
- return *data.intValue > *data.intValue;
+ result = (*data.intValue > *data.intValue);
break;
-
+
case DOUBLE:
- return *data.doubleValue > *data.doubleValue;
+ result = (*data.doubleValue > *data.doubleValue);
break;
-
+
case OBJECT:
- return *data.objectValue > *data.objectValue;
+ result = (*data.objectValue > *data.objectValue);
break;
-
+
case ARRAY:
- return *data.arrayValue > *data.arrayValue;
+ result = (*data.arrayValue > *data.arrayValue);
break;
-
+
case BOOLEAN:
- return *data.boolValue > *data.boolValue;
+ result = (*data.boolValue > *data.boolValue);
break;
-
+
default:
- return false;
break;
+ }
+
}
- } else {
- return false;
}
+
+ return result;
}
-
+
bool Value::operator>=(const Value &rhs) const {
return *this > rhs || *this == rhs;
}
Please sign in to comment.
Something went wrong with that request. Please try again.