diff --git a/include/dynamic-graph/value.h b/include/dynamic-graph/value.h index 5d3569ded03e0d03573b8b92a3469e73a54de58d..047434859b0440850b77be68bd22ba05deb418f5 100644 --- a/include/dynamic-graph/value.h +++ b/include/dynamic-graph/value.h @@ -72,6 +72,8 @@ public: explicit Value(); // operator assignement Value operator=(const Value &value); + // Equality operator + bool operator==(const Value &other) const; /// Return the type of the value Type type() const; diff --git a/src/command/value.cpp b/src/command/value.cpp index a64957b318f1cffe80058922a438e697445eea0d..d950ca2f274f1594b01de083bc4144d4d749a885 100644 --- a/src/command/value.cpp +++ b/src/command/value.cpp @@ -144,6 +144,25 @@ Value Value::operator=(const Value &value) { return *this; } +bool Value::operator==(const Value &other) const { + if (type_ != other.type_) return false; + switch (type_) { + case Value::BOOL: return boolValue() == other.boolValue(); + case Value::UNSIGNED: return unsignedValue() == other.unsignedValue(); + case Value::INT: return intValue() == other.intValue(); + case Value::DOUBLE: return doubleValue() == other.doubleValue(); + case Value::FLOAT: return floatValue() == other.floatValue(); + case Value::STRING: return stringValue() == other.stringValue(); + case Value::VECTOR: return vectorValue() == other.vectorValue(); + case Value::MATRIX: return matrixXdValue() == other.matrixXdValue(); + case Value::MATRIX4D: return matrix4dValue() == other.matrix4dValue(); + case Value::VALUES: return constValuesValue() == other.constValuesValue(); + case Value::NONE: break; + default: break; + } + return false; +} + const EitherType Value::value() const { return EitherType(*this); } Value::Type Value::type() const { return type_; } diff --git a/tests/value.cpp b/tests/value.cpp index fe5eb6407e79778e4ed729b7900b4851c8c718ac..af321174f7909471ac0f328937c29f6e83db999b 100644 --- a/tests/value.cpp +++ b/tests/value.cpp @@ -371,4 +371,5 @@ BOOST_AUTO_TEST_CASE(value_values) { const Values& vs = vvalues.constValuesValue(); BOOST_CHECK_EQUAL(vs.size(), values.size()); + BOOST_CHECK(vs == values); }