diff --git a/include/dynamic-graph/value.h b/include/dynamic-graph/value.h index cbd5dd110cff6902a7a44701f5b8e7c187e028aa..fc905b568dea187faa5c35fb09df36b5d0bcca4f 100644 --- a/include/dynamic-graph/value.h +++ b/include/dynamic-graph/value.h @@ -27,7 +27,9 @@ class DYNAMIC_GRAPH_DLLAPI EitherType { ~EitherType(); operator bool() const; operator unsigned() const; + operator unsigned long int () const; operator int() const; + operator long int() const; operator float() const; operator double() const; operator std::string() const; @@ -51,7 +53,9 @@ class DYNAMIC_GRAPH_DLLAPI Value { NONE, BOOL, UNSIGNED, + UNSIGNEDLONGINT, INT, + LONGINT, FLOAT, DOUBLE, STRING, @@ -65,7 +69,9 @@ 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 int &value); + explicit Value(const long int &value); explicit Value(const float &value); explicit Value(const double &value); explicit Value(const std::string &value); @@ -107,7 +113,9 @@ class DYNAMIC_GRAPH_DLLAPI Value { friend class EitherType; bool boolValue() const; unsigned unsignedValue() const; + unsigned long unsignedlongintValue() const; int intValue() const; + long int longintValue() const; float floatValue() const; double doubleValue() const; std::string stringValue() const; diff --git a/src/command/value.cpp b/src/command/value.cpp index 8ca36ce41a9e40ec69aaf78567877bf95138369c..aed6c2436afb0145bf6abb9ad4ca0f5410fb1bf8 100644 --- a/src/command/value.cpp +++ b/src/command/value.cpp @@ -22,7 +22,9 @@ EitherType::~EitherType() { EitherType::operator bool() const { return value_->boolValue(); } EitherType::operator unsigned() const { return value_->unsignedValue(); } +EitherType::operator unsigned long int() const { return value_->unsignedlongintValue(); } EitherType::operator int() const { return value_->intValue(); } +EitherType::operator long int() const { return value_->longintValue(); } EitherType::operator float() const { return value_->floatValue(); } EitherType::operator double() const { return value_->doubleValue(); } EitherType::operator std::string() const { return value_->stringValue(); } @@ -40,9 +42,15 @@ void Value::deleteValue() { 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; @@ -64,7 +72,9 @@ void Value::deleteValue() { case VALUES: delete (const Values *)value_; break; - default:; + default: + throw "Value::deleteValue : Undefined type"; + ; } } @@ -73,6 +83,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 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)) {} @@ -91,6 +103,7 @@ Value::Value(const Value &value) void *copyValue(const Value &value) { void *copy; switch (value.type()) { + case Value::NONE: copy = NULL; break; @@ -100,9 +113,15 @@ void *copyValue(const Value &value) { 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; @@ -149,6 +168,8 @@ bool Value::operator==(const Value &other) const { 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: @@ -188,9 +209,23 @@ unsigned Value::unsignedValue() const { "value is not an unsigned int"); } +unsigned long int Value::unsignedlongintValue() const { + if (type_ == UNSIGNEDLONGINT) + return *((const unsigned long int*)value_); + throw ExceptionAbstract(ExceptionAbstract::TOOLS, + "value is not an unsigned long int"); +} + +long int Value::longintValue() const { + if (type_ == LONGINT) + return *((const long int *)value_); + throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an long int"); +} + int Value::intValue() const { - if (type_ == INT) return *((const int *)value_); - throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an int int"); + if (type_ == INT) + return *((const int *)value_); + throw ExceptionAbstract(ExceptionAbstract::TOOLS, "value is not an int"); } float Value::floatValue() const { @@ -249,6 +284,8 @@ std::string Value::typeName(Type type) { 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: @@ -279,6 +316,9 @@ std::ostream &operator<<(std::ostream &os, const Value &value) { case Value::UNSIGNED: os << value.unsignedValue(); break; + case Value::UNSIGNEDLONGINT: + os << value.unsignedlongintValue(); + break; case Value::INT: os << value.intValue(); break; @@ -309,24 +349,20 @@ std::ostream &operator<<(std::ostream &os, const Value &value) { } break; default: return os; + } return os; } -template <> -const Value::Type ValueHelper<bool>::TypeID = Value::BOOL; -template <> -const Value::Type ValueHelper<unsigned>::TypeID = Value::UNSIGNED; -template <> -const Value::Type ValueHelper<int>::TypeID = Value::INT; -template <> -const Value::Type ValueHelper<float>::TypeID = Value::FLOAT; -template <> -const Value::Type ValueHelper<double>::TypeID = Value::DOUBLE; -template <> -const Value::Type ValueHelper<std::string>::TypeID = Value::STRING; -template <> -const Value::Type ValueHelper<Vector>::TypeID = Value::VECTOR; +template <> const Value::Type ValueHelper<bool>::TypeID = Value::BOOL; +template <> const Value::Type ValueHelper<unsigned>::TypeID = Value::UNSIGNED; +template <> const Value::Type ValueHelper<unsigned long int>::TypeID = Value::UNSIGNEDLONGINT; +template <> const Value::Type ValueHelper<int>::TypeID = Value::INT; +template <> const Value::Type ValueHelper<float>::TypeID = Value::FLOAT; +template <> const Value::Type ValueHelper<double>::TypeID = Value::DOUBLE; +template <> const Value::Type ValueHelper<std::string>::TypeID = Value::STRING; +template <> const Value::Type ValueHelper<Vector>::TypeID = Value::VECTOR; + template <> const Value::Type ValueHelper<Eigen::MatrixXd>::TypeID = Value::MATRIX; template <>