diff --git a/src/evhelper.cpp b/src/evhelper.cpp index 66cb52b..d036a2f 100644 --- a/src/evhelper.cpp +++ b/src/evhelper.cpp @@ -20,6 +20,7 @@ #include "evhelper.h" #include "pvaproto.h" +#include "utilpvt.h" #include namespace pvxsimpl { diff --git a/src/evhelper.h b/src/evhelper.h index 1e7cb6d..c19470a 100644 --- a/src/evhelper.h +++ b/src/evhelper.h @@ -17,23 +17,13 @@ #include #include -#include +#include #include "pvaproto.h" namespace pvxsimpl { using namespace pvxs; -//! in-line string builder (eg. for exception messages) -//! eg. @code throw std::runtime_error(SB()<<"Some message"<<42); @endcode -struct SB { - std::ostringstream strm; - SB() {} - operator std::string() const { return strm.str(); } - template - SB& operator<<(T i) { strm< +#include + #include +#include "utilpvt.h" namespace pvxs { @@ -218,3 +221,19 @@ std::ostream& operator<<(std::ostream& strm, const SockAddr& addr) } } + +namespace pvxsimpl { +namespace detail { + +template<> +unsigned short as_str::op(const char *s) +{ + epicsUInt16 ret; + if(int err = epicsParseUInt16(s, &ret, 0, nullptr)) { + (void)err; + throw std::runtime_error(SB()<<"Unable to parse as uint16 : "< +#include + +#include +#include + +namespace pvxsimpl { +using namespace pvxs; + +//! in-line string builder (eg. for exception messages) +//! eg. @code throw std::runtime_error(SB()<<"Some message"<<42); @endcode +struct SB { + std::ostringstream strm; + SB() {} + operator std::string() const { return strm.str(); } + template + SB& operator<<(T i) { strm< +struct as_str {PVXS_API static T op(const char *s);}; +} // namespace detail + +template +inline T lexical_cast(const char *s) +{ + return detail::as_str::op(s); +} + +template +inline T lexical_cast(const std::string& s) +{ + return detail::as_str::op(s.c_str()); +} + +} // namespace pvxsimpl + +#endif // UTILPVT_H diff --git a/tools/pvxvct.cpp b/tools/pvxvct.cpp index bf4ac8d..0fa0670 100644 --- a/tools/pvxvct.cpp +++ b/tools/pvxvct.cpp @@ -27,6 +27,7 @@ #include #include +#include #include namespace pva = pvxsimpl;