summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-11-17 10:02:37 -0800
committerJosh Blum <josh@joshknows.com>2010-11-17 10:02:37 -0800
commitdaa537d329f8e758b86db3d98500f211e4736f55 (patch)
tree433e85b99e02dbaee599590c8c4313ca2da8d5ba
parent755569e66f7a939aa9392a79bf637d823fb78b84 (diff)
downloaduhd-daa537d329f8e758b86db3d98500f211e4736f55.tar.gz
uhd-daa537d329f8e758b86db3d98500f211e4736f55.tar.bz2
uhd-daa537d329f8e758b86db3d98500f211e4736f55.zip
uhd: added to printable string methods for ranges
-rw-r--r--host/include/uhd/types/ranges.hpp9
-rw-r--r--host/include/uhd/types/ranges.ipp19
2 files changed, 26 insertions, 2 deletions
diff --git a/host/include/uhd/types/ranges.hpp b/host/include/uhd/types/ranges.hpp
index 25120de40..8a7ca0310 100644
--- a/host/include/uhd/types/ranges.hpp
+++ b/host/include/uhd/types/ranges.hpp
@@ -21,6 +21,7 @@
#include <uhd/config.hpp>
#include <uhd/utils/pimpl.hpp>
#include <vector>
+#include <string>
namespace uhd{
@@ -55,8 +56,11 @@ namespace uhd{
//! Get the step value for this range.
const T step(void) const;
+ //! Convert this range to a printable string
+ const std::string to_pp_string(void) const;
+
private:
- UHD_PIMPL_DECL(impl) _impl;
+ UHD_PIMPL_DECL(impl) _impl;
};
/*!
@@ -102,6 +106,9 @@ namespace uhd{
*/
const T clip(const T &value, bool clip_step = false) const;
+ //! Convert this meta-range to a printable string
+ const std::string to_pp_string(void) const;
+
};
//! export a symbol for the gain range type
diff --git a/host/include/uhd/types/ranges.ipp b/host/include/uhd/types/ranges.ipp
index 8b602a24d..29f389fca 100644
--- a/host/include/uhd/types/ranges.ipp
+++ b/host/include/uhd/types/ranges.ipp
@@ -22,7 +22,7 @@
#include <boost/foreach.hpp>
#include <algorithm>
#include <stdexcept>
-#include <iostream>
+#include <sstream>
namespace uhd{
@@ -66,6 +66,15 @@ namespace uhd{
return _impl->step;
}
+ template <typename T> const std::string range_t<T>::to_pp_string(void) const{
+ std::stringstream ss;
+ ss << "(" << this->start();
+ if (this->start() != this->stop()) ss << ", " << this->stop();
+ if (this->step() != T(0)) ss << ", " << this->step();
+ ss << ")";
+ return ss.str();
+ }
+
/*******************************************************************
* meta_range_t implementation code
******************************************************************/
@@ -163,6 +172,14 @@ namespace uhd{
return last_stop;
}
+ template <typename T> const std::string meta_range_t<T>::to_pp_string(void) const{
+ std::stringstream ss;
+ BOOST_FOREACH(const range_t<T> &r, (*this)){
+ ss << r.to_pp_string() << std::endl;
+ }
+ return ss.str();
+ }
+
} //namespace uhd
#endif /* INCLUDED_UHD_TYPES_RANGES_IPP */