diff options
| author | Jonathan Robie <jonathan@apache.org> | 2010-10-29 17:26:05 +0000 |
|---|---|---|
| committer | Jonathan Robie <jonathan@apache.org> | 2010-10-29 17:26:05 +0000 |
| commit | 35e0d495a6b5a00f6ce8476476a06e0527164617 (patch) | |
| tree | 930484ef4e02e68d7d8dd79008ee6a09d11b9de5 /cpp/src/qpid | |
| parent | 88d0fc0f70daab03c9302ffa5af30d551372dac2 (diff) | |
| download | qpid-python-35e0d495a6b5a00f6ce8476476a06e0527164617.tar.gz | |
Corrects AddressParser to use typed simple values.
Adds Variant::fromString().
Resolves QPID-2896 and QPID-2908.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1028860 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid')
| -rw-r--r-- | cpp/src/qpid/messaging/AddressParser.cpp | 7 | ||||
| -rw-r--r-- | cpp/src/qpid/types/Variant.cpp | 37 |
2 files changed, 41 insertions, 3 deletions
diff --git a/cpp/src/qpid/messaging/AddressParser.cpp b/cpp/src/qpid/messaging/AddressParser.cpp index c34c9c0f56..d088b94f32 100644 --- a/cpp/src/qpid/messaging/AddressParser.cpp +++ b/cpp/src/qpid/messaging/AddressParser.cpp @@ -196,13 +196,14 @@ bool AddressParser::readQuotedValue(Variant& value) return false; } } - -bool AddressParser::readSimpleValue(Variant& value) + +bool AddressParser::readSimpleValue(Variant& value) { std::string s; if (readWord(s)) { - value = s; + value.fromString(s); return true; + } else { return false; } diff --git a/cpp/src/qpid/types/Variant.cpp b/cpp/src/qpid/types/Variant.cpp index bf255b4423..ea4f5ffbbf 100644 --- a/cpp/src/qpid/types/Variant.cpp +++ b/cpp/src/qpid/types/Variant.cpp @@ -23,6 +23,7 @@ #include "qpid/log/Statement.h" #include <boost/format.hpp> #include <boost/lexical_cast.hpp> +#include <boost/algorithm/string.hpp> #include <algorithm> #include <limits> #include <sstream> @@ -766,6 +767,42 @@ Variant& Variant::operator=(const Variant& v) return *this; } + +template <class T> +bool from_string(T& t, const std::string& s) +{ + char c; // Make sure there are no extra characters + + std::istringstream iss(s); + return !(iss >> t).fail() && (iss>>c).fail(); +} + +Variant& Variant::fromString(const std::string& s) +{ + double d; + int i; + + if (from_string<int>(i, s)) { + return operator=(i); + } + else if (from_string<double>(d, s)) { + return operator=(d); + } + else { + std::string upper(boost::to_upper_copy(s)); + if (upper == "TRUE") { + return operator=(true); + } + else if (upper == "FALSE") { + return operator=(false); + } + else { + return operator=(s); + } + } +} + + VariantType Variant::getType() const { return impl ? impl->getType() : VAR_VOID; } bool Variant::isVoid() const { return getType() == VAR_VOID; } bool Variant::asBool() const { return impl && impl->asBool(); } |
