diff options
author | Josh Blum <josh@joshknows.com> | 2010-01-28 19:54:55 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-01-28 19:54:55 -0800 |
commit | d5d9da3114bf069c05a8dcb7fca32ccd70405512 (patch) | |
tree | 5c2c63efe9175ebd2b22c6b4899b997e9fed5b11 /include/usrp_uhd/utils.hpp | |
parent | fc1bffcfd9761c1f60cf322bb58e7f9c8096a5c0 (diff) | |
download | uhd-d5d9da3114bf069c05a8dcb7fca32ccd70405512.tar.gz uhd-d5d9da3114bf069c05a8dcb7fca32ccd70405512.tar.bz2 uhd-d5d9da3114bf069c05a8dcb7fca32ccd70405512.zip |
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.
Diffstat (limited to 'include/usrp_uhd/utils.hpp')
-rw-r--r-- | include/usrp_uhd/utils.hpp | 47 |
1 files changed, 41 insertions, 6 deletions
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 <boost/foreach.hpp> -#include <map> +#include <boost/format.hpp> +#include <boost/function.hpp> +#include <stdexcept> +#include <algorithm> #include <vector> +#include <map> #ifndef INCLUDED_USRP_UHD_UTILS_HPP #define INCLUDED_USRP_UHD_UTILS_HPP namespace usrp_uhd{ -template <class Key, class T> +template <class Key, class T> //TODO template this better std::vector<Key> get_map_keys(const std::map<Key, T> &m){ std::vector<Key> v; std::pair<Key, T> p; @@ -21,12 +25,43 @@ std::vector<Key> get_map_keys(const std::map<Key, T> &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<class T, class InputIterator, class Function> + 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<class T, class InputIterator> + bool has(InputIterator first, InputIterator last, const T &elem){ + return last != std::find(first, last, elem); + } + + template <class T> + T sum(const T &a, const T &b){ + return a + b; + } + +}//namespace std #endif /* INCLUDED_USRP_UHD_UTILS_HPP */ |