From 61c3fe95f85fb16d5fef682c7e135d38fe0f6a69 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 2 May 2014 14:11:36 +0200 Subject: [PATCH] feature #2858: Convert to unsigned int from vector attributes --- include/Attribute.h | 10 ++++++++++ src/common/Attribute.cc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/Attribute.h b/include/Attribute.h index 174612a6c4..97e4bbaeec 100644 --- a/include/Attribute.h +++ b/include/Attribute.h @@ -265,6 +265,16 @@ public: */ int vector_value(const char *name, int& value) const; + /** + * Returns the unsigned integer value + * + * @param name Name of the attribute + * @param value Integer value + * + * @return 0 on success, -1 otherwise + */ + int vector_value(const char *name, unsigned int& value) const; + /** * Returns the long long value * diff --git a/src/common/Attribute.cc b/src/common/Attribute.cc index edc4a0df87..dcc0cd3837 100644 --- a/src/common/Attribute.cc +++ b/src/common/Attribute.cc @@ -281,6 +281,36 @@ int VectorAttribute::vector_value(const char *name, int & value) const /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int VectorAttribute::vector_value(const char *name, unsigned int & value) const +{ + map::const_iterator it; + + it = attribute_value.find(name); + + if ( it == attribute_value.end() ) + { + return -1; + } + + if ( it->second.empty() ) + { + return -1; + } + + istringstream iss(it->second); + iss >> value; + + if (iss.fail() || !iss.eof()) + { + return -1; + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + int VectorAttribute::vector_value(const char *name, long long& value) const { map::const_iterator it;