From d7c19c0c58432ba8a0f299d37ff6940a1003fa21 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 25 Feb 2020 15:14:46 -0800 Subject: [PATCH] Value parse string -> scalar --- src/data.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/data.cpp b/src/data.cpp index 1445f23..ebb3538 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -435,6 +435,32 @@ bool Value::tryCopyOut(void *ptr, StoreType type) const } namespace { + +bool parseScalar(double& dest, const std::string& inp) +{ + return 0==epicsParseDouble(inp.c_str(), &dest, nullptr); +} + +bool parseScalar(int64_t& dest, const std::string& inp) +{ + epicsInt64 t; + if(epicsParseInt64(inp.c_str(), &t, 0, nullptr)==0) { + dest = t; + return true; + } + return false; +} + +bool parseScalar(uint64_t& dest, const std::string& inp) +{ + epicsUInt64 t; + if(epicsParseUInt64(inp.c_str(), &t, 0, nullptr)==0) { + dest = t; + return true; + } + return false; +} + // C-style cast between scalar storage types, and print to string (base 10) template bool copyInScalar(Dest& dest, const void *ptr, StoreType type) @@ -444,7 +470,7 @@ bool copyInScalar(Dest& dest, const void *ptr, StoreType type) case StoreType::Integer: dest = *reinterpret_cast(ptr); return true; case StoreType::UInteger: dest = *reinterpret_cast(ptr); return true; case StoreType::Bool: dest = *reinterpret_cast(ptr); return true; - case StoreType::String: // TODO: parse from string + case StoreType::String: return parseScalar(dest, *reinterpret_cast(ptr)); case StoreType::Null: case StoreType::Compound: case StoreType::Array: