aboutsummaryrefslogtreecommitdiffstats
path: root/host/include
diff options
context:
space:
mode:
Diffstat (limited to 'host/include')
-rw-r--r--host/include/uhd/utils/cast.hpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/host/include/uhd/utils/cast.hpp b/host/include/uhd/utils/cast.hpp
index d6d86d119..fd591dae7 100644
--- a/host/include/uhd/utils/cast.hpp
+++ b/host/include/uhd/utils/cast.hpp
@@ -1,6 +1,7 @@
//
// Copyright 2014-2015 Ettus Research LLC
// Copyright 2018 Ettus Research, a National Instruments Company
+// Copyright 2019 Ettus Research, a National Instruments Brand
//
// SPDX-License-Identifier: GPL-3.0-or-later
//
@@ -9,6 +10,7 @@
#define INCLUDED_UHD_UTILS_CAST_HPP
#include <uhd/config.hpp>
+#include <uhd/exception.hpp>
#include <sstream>
#include <string>
@@ -18,7 +20,8 @@ namespace uhd { namespace cast {
// Example:
// uint16_t x = hexstr_cast<uint16_t>("0xDEADBEEF");
// Uses stringstream.
-template <typename T> UHD_INLINE T hexstr_cast(const std::string& in)
+template <typename T>
+inline T hexstr_cast(const std::string& in)
{
T x;
std::stringstream ss;
@@ -27,6 +30,22 @@ template <typename T> UHD_INLINE T hexstr_cast(const std::string& in)
return x;
}
+//! Generic cast-from-string function
+template <typename data_t>
+data_t from_str(const std::string&)
+{
+ throw uhd::runtime_error("Cannot convert from string!");
+}
+
+template <>
+UHD_API double from_str(const std::string& val);
+
+template <>
+UHD_API int from_str(const std::string& val);
+
+template <>
+UHD_API std::string from_str(const std::string& val);
+
}} // namespace uhd::cast
#endif /* INCLUDED_UHD_UTILS_CAST_HPP */