From d5d9da3114bf069c05a8dcb7fca32ccd70405512 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 28 Jan 2010 19:54:55 -0800 Subject: Added gain handler class to manage wildcard gain settings. Gets overall gains and sets overall gains when used. Wild card gain will be a gain with an empty string name. --- include/usrp_uhd/utils.hpp | 47 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'include/usrp_uhd/utils.hpp') diff --git a/include/usrp_uhd/utils.hpp b/include/usrp_uhd/utils.hpp index a45473ab4..c1b2bad5c 100644 --- a/include/usrp_uhd/utils.hpp +++ b/include/usrp_uhd/utils.hpp @@ -3,15 +3,19 @@ // #include -#include +#include +#include +#include +#include #include +#include #ifndef INCLUDED_USRP_UHD_UTILS_HPP #define INCLUDED_USRP_UHD_UTILS_HPP namespace usrp_uhd{ -template +template //TODO template this better std::vector get_map_keys(const std::map &m){ std::vector v; std::pair p; @@ -21,12 +25,43 @@ std::vector get_map_keys(const std::map &m){ return v; } -//TODO implement a set and get gains that takes a wx obj ptr, and gain properties +} //namespace usrp_uhd + +/*! + * Useful templated functions and classes that I like to pretend are part of stl + */ +namespace std{ -//TODO check name in vector of names + class assert_error : public std::logic_error{ + public: + explicit assert_error(const string& what_arg) : logic_error(what_arg){ + /* NOP */ + } + }; -//TODO optionally extract a name from the named_prop_t + #define ASSERT_THROW(_x) if (not (_x)) { \ + throw std::assert_error("Assertion Failed: " + std::string(#_x)); \ + } -} //namespace usrp_uhd + template + T reduce(InputIterator first, InputIterator last, Function fcn, T init = 0){ + T tmp = init; + for ( ; first != last; ++first ){ + tmp = fcn(tmp, *first); + } + return tmp; + } + + template + bool has(InputIterator first, InputIterator last, const T &elem){ + return last != std::find(first, last, elem); + } + + template + T sum(const T &a, const T &b){ + return a + b; + } + +}//namespace std #endif /* INCLUDED_USRP_UHD_UTILS_HPP */ -- cgit v1.2.3