From ae9ecbf51767a7d4e5298ff5dab27c39a801d0aa Mon Sep 17 00:00:00 2001
From: Olivier Stasse <olivier.stasse@laas.fr>
Date: Sun, 9 Jan 2022 22:47:32 +0100
Subject: [PATCH] [value] Add operators() for Value with unsigned long int, add
 handling of None as void. While here fix the exception message for int
 (remove the second int). Fix the test accordingly.

---
 include/dynamic-graph/value.h |   4 +-
 src/command/value.cpp         | 345 +++++++++++++++++-----------------
 tests/value.cpp               |   2 +-
 3 files changed, 176 insertions(+), 175 deletions(-)

diff --git a/include/dynamic-graph/value.h b/include/dynamic-graph/value.h
index fc905b5..a9d5a98 100644
--- a/include/dynamic-graph/value.h
+++ b/include/dynamic-graph/value.h
@@ -69,7 +69,7 @@ class DYNAMIC_GRAPH_DLLAPI Value {
   void deleteValue();
   explicit Value(const bool &value);
   explicit Value(const unsigned &value);
-  explicit Value(const unsigned long &value);
+  explicit Value(const unsigned long int&value);
   explicit Value(const int &value);
   explicit Value(const long int &value);
   explicit Value(const float &value);
@@ -113,7 +113,7 @@ class DYNAMIC_GRAPH_DLLAPI Value {
   friend class EitherType;
   bool boolValue() const;
   unsigned unsignedValue() const;
-  unsigned long unsignedlongintValue() const;
+  unsigned long int unsignedlongintValue() const;
   int intValue() const;
   long int longintValue() const;
   float floatValue() const;
diff --git a/src/command/value.cpp b/src/command/value.cpp
index aed6c24..748ae16 100644
--- a/src/command/value.cpp
+++ b/src/command/value.cpp
@@ -36,45 +36,47 @@ EitherType::operator Values() const { return value_->valuesValue(); }
 
 void Value::deleteValue() {
   switch (type_) {
-    case BOOL:
-      delete (const bool *)value_;
-      break;
-    case UNSIGNED:
-      delete (const unsigned *)value_;
-      break;
-    case UNSIGNEDLONGINT:
-      delete (const unsigned long int*)value_;
-      break;
-    case INT:
-      delete (const int *)value_;
-      break;
-    case LONGINT:
-      delete (const long int *)value_;
-      break;
-    case FLOAT:
-      delete (const float *)value_;
-      break;
-    case DOUBLE:
-      delete (const double *)value_;
-      break;
-    case STRING:
-      delete (const std::string *)value_;
-      break;
-    case VECTOR:
-      delete (const Vector *)value_;
-      break;
-    case MATRIX:
-      delete (const Eigen::MatrixXd *)value_;
-      break;
-    case MATRIX4D:
-      delete (const Eigen::Matrix4d *)value_;
-      break;
-    case VALUES:
-      delete (const Values *)value_;
-      break;
-    default:
-      throw "Value::deleteValue : Undefined type";
-      ;
+  case BOOL:
+    delete (const bool *)value_;
+    break;
+  case UNSIGNED:
+    delete (const unsigned *)value_;
+    break;
+  case UNSIGNEDLONGINT:
+    delete (const unsigned long int*)value_;
+    break;
+  case INT:
+    delete (const int *)value_;
+    break;
+  case LONGINT:
+    delete (const long int *)value_;
+    break;
+  case FLOAT:
+    delete (const float *)value_;
+    break;
+  case DOUBLE:
+    delete (const double *)value_;
+    break;
+  case STRING:
+    delete (const std::string *)value_;
+    break;
+  case VECTOR:
+    delete (const Vector *)value_;
+    break;
+  case MATRIX:
+    delete (const Eigen::MatrixXd *)value_;
+    break;
+  case MATRIX4D:
+    delete (const Eigen::Matrix4d *)value_;
+    break;
+  case VALUES:
+    delete (const Values *)value_;
+    break;
+  case NONE: /* Equivalent to void */
+    break;
+  default:
+    throw "Value::deleteValue : Undefined type";
+    ;
   }
 }
 
@@ -83,8 +85,8 @@ Value::~Value() { deleteValue(); }
 Value::Value(const bool &value) : type_(BOOL), value_(new bool(value)) {}
 Value::Value(const unsigned &value)
     : type_(UNSIGNED), value_(new unsigned(value)) {}
-Value::Value(const unsigned long &value)
-    : type_(UNSIGNED), value_(new unsigned long(value)) {}
+Value::Value(const unsigned long int &value)
+    : type_(UNSIGNEDLONGINT), value_(new unsigned long int(value)) {}
 Value::Value(const int &value) : type_(INT), value_(new int(value)) {}
 Value::Value(const float &value) : type_(FLOAT), value_(new float(value)) {}
 Value::Value(const double &value) : type_(DOUBLE), value_(new double(value)) {}
@@ -103,48 +105,47 @@ Value::Value(const Value &value)
 void *copyValue(const Value &value) {
   void *copy;
   switch (value.type()) {
-
-    case Value::NONE:
-      copy = NULL;
-      break;
-    case Value::BOOL:
-      copy = new bool(value.boolValue());
-      break;
-    case Value::UNSIGNED:
-      copy = new unsigned(value.unsignedValue());
-      break;
-    case Value::UNSIGNEDLONGINT:
-      copy = new unsigned long int(value.unsignedlongintValue());
-      break;
-    case Value::INT:
-      copy = new int(value.intValue());
-      break;
-    case Value::LONGINT:
-      copy = new long int(value.longintValue());
-      break;
-    case Value::FLOAT:
-      copy = new float(value.floatValue());
-      break;
-    case Value::DOUBLE:
-      copy = new double(value.doubleValue());
-      break;
-    case Value::STRING:
-      copy = new std::string(value.stringValue());
-      break;
-    case Value::VECTOR:
-      copy = new Vector(value.vectorValue());
-      break;
-    case Value::MATRIX:
-      copy = new Eigen::MatrixXd(value.matrixXdValue());
-      break;
-    case Value::MATRIX4D:
-      copy = new Eigen::Matrix4d(value.matrix4dValue());
-      break;
-    case Value::VALUES:
-      copy = new Values(value.valuesValue());
-      break;
-    default:
-      abort();
+  case Value::NONE:
+    copy = NULL;
+    break;
+  case Value::BOOL:
+    copy = new bool(value.boolValue());
+    break;
+  case Value::UNSIGNED:
+    copy = new unsigned(value.unsignedValue());
+    break;
+  case Value::UNSIGNEDLONGINT:
+    copy = new unsigned long int(value.unsignedlongintValue());
+    break;
+  case Value::INT:
+    copy = new int(value.intValue());
+    break;
+  case Value::LONGINT:
+    copy = new long int(value.longintValue());
+    break;
+  case Value::FLOAT:
+    copy = new float(value.floatValue());
+    break;
+  case Value::DOUBLE:
+    copy = new double(value.doubleValue());
+    break;
+  case Value::STRING:
+    copy = new std::string(value.stringValue());
+    break;
+  case Value::VECTOR:
+    copy = new Vector(value.vectorValue());
+    break;
+  case Value::MATRIX:
+    copy = new Eigen::MatrixXd(value.matrixXdValue());
+    break;
+  case Value::MATRIX4D:
+    copy = new Eigen::Matrix4d(value.matrix4dValue());
+    break;
+  case Value::VALUES:
+    copy = new Values(value.valuesValue());
+    break;
+  default:
+    abort();
   }
   return copy;
 }
@@ -164,32 +165,32 @@ Value Value::operator=(const Value &value) {
 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::UNSIGNEDLONGINT:
-      return unsignedlongintValue() == other.unsignedlongintValue();
-    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;
+  case Value::BOOL:
+    return boolValue() == other.boolValue();
+  case Value::UNSIGNED:
+    return unsignedValue() == other.unsignedValue();
+  case Value::UNSIGNEDLONGINT:
+    return unsignedlongintValue() == other.unsignedlongintValue();
+  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;
 }
@@ -280,75 +281,75 @@ const Values &Value::constValuesValue() const {
 
 std::string Value::typeName(Type type) {
   switch (type) {
-    case BOOL:
-      return std::string("bool");
-    case UNSIGNED:
-      return std::string("unsigned int");
-    case UNSIGNEDLONGINT:
-      return std::string("unsigned long int");
-    case INT:
-      return std::string("int");
-    case FLOAT:
-      return std::string("float");
-    case DOUBLE:
-      return std::string("double");
-    case STRING:
-      return std::string("string");
-    case VECTOR:
-      return std::string("vector");
-    case MATRIX:
-      return std::string("matrixXd");
-    case MATRIX4D:
-      return std::string("matrix4d");
-    case VALUES:
-      return std::string("values");
-    default:
-      return std::string("unknown");
+  case BOOL:
+    return std::string("bool");
+  case UNSIGNED:
+    return std::string("unsigned int");
+  case UNSIGNEDLONGINT:
+    return std::string("unsigned long int");
+  case INT:
+    return std::string("int");
+  case FLOAT:
+    return std::string("float");
+  case DOUBLE:
+    return std::string("double");
+  case STRING:
+    return std::string("string");
+  case VECTOR:
+    return std::string("vector");
+  case MATRIX:
+    return std::string("matrixXd");
+  case MATRIX4D:
+    return std::string("matrix4d");
+  case VALUES:
+    return std::string("values");
+  default:
+    return std::string("unknown");
   }
 }
 
 std::ostream &operator<<(std::ostream &os, const Value &value) {
   os << "Type=" << Value::typeName(value.type_) << ", value=";
   switch (value.type_) {
-    case Value::BOOL:
-      os << value.boolValue();
-      break;
-    case Value::UNSIGNED:
-      os << value.unsignedValue();
-      break;
-    case Value::UNSIGNEDLONGINT:
-      os << value.unsignedlongintValue();
-      break;
-    case Value::INT:
-      os << value.intValue();
-      break;
-    case Value::DOUBLE:
-      os << value.doubleValue();
-      break;
-    case Value::FLOAT:
-      os << value.floatValue();
-      break;
-    case Value::STRING:
-      os << value.stringValue();
-      break;
-    case Value::VECTOR:
-      os << value.vectorValue();
-      break;
-    case Value::MATRIX:
-      os << value.matrixXdValue();
-      break;
-    case Value::MATRIX4D:
-      os << value.matrix4dValue();
-      break;
-    case Value::VALUES: {
-      const std::vector<Value> &vals = value.constValuesValue();
-      os << "[ ";
-      for (std::size_t i = 0; i < vals.size(); ++i)
-        os << "Value(" << vals[i] << "), ";
-      os << "]";
-    } break;
-    default:
-      return os;
+  case Value::BOOL:
+    os << value.boolValue();
+    break;
+  case Value::UNSIGNED:
+    os << value.unsignedValue();
+    break;
+  case Value::UNSIGNEDLONGINT:
+    os << value.unsignedlongintValue();
+    break;
+  case Value::INT:
+    os << value.intValue();
+    break;
+  case Value::DOUBLE:
+    os << value.doubleValue();
+    break;
+  case Value::FLOAT:
+    os << value.floatValue();
+    break;
+  case Value::STRING:
+    os << value.stringValue();
+    break;
+  case Value::VECTOR:
+    os << value.vectorValue();
+    break;
+  case Value::MATRIX:
+    os << value.matrixXdValue();
+    break;
+  case Value::MATRIX4D:
+    os << value.matrix4dValue();
+    break;
+  case Value::VALUES: {
+    const std::vector<Value> &vals = value.constValuesValue();
+    os << "[ ";
+    for (std::size_t i = 0; i < vals.size(); ++i)
+      os << "Value(" << vals[i] << "), ";
+    os << "]";
+  } break;
+  default:
+    return os;
 
   }
   return os;
diff --git a/tests/value.cpp b/tests/value.cpp
index 6707453..608b62a 100644
--- a/tests/value.cpp
+++ b/tests/value.cpp
@@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(value_exceptions) {
   }
   BOOST_CHECK(res);
   BOOST_CHECK(output.is_equal("Abstract"));
-  BOOST_CHECK(output2.is_equal("value is not an int int"));
+  BOOST_CHECK(output2.is_equal("value is not an int"));
 
   // Check if the exception is working when calling boolValue
   // while we are having a none.
-- 
GitLab