diff options
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 */ |