From 28e306bc6e0f6efa836d0b1eb39998bb744851ab Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Thu, 16 Jan 2020 17:56:40 +0100 Subject: [PATCH] Add Value::operator== --- include/dynamic-graph/value.h | 2 ++ src/command/value.cpp | 19 +++++++++++++++++++ tests/value.cpp | 1 + 3 files changed, 22 insertions(+) diff --git a/include/dynamic-graph/value.h b/include/dynamic-graph/value.h index 5d3569d..0474348 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 a64957b..d950ca2 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 fe5eb64..af32117 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); } -- GitLab