diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd/config.hpp | 4 | ||||
-rw-r--r-- | host/include/uhd/types/dict.hpp | 4 | ||||
-rw-r--r-- | host/include/uhd/utils/algorithm.hpp | 30 | ||||
-rw-r--r-- | host/include/uhd/utils/assert.hpp | 18 |
4 files changed, 19 insertions, 37 deletions
diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp index 941219ac7..227c473ce 100644 --- a/host/include/uhd/config.hpp +++ b/host/include/uhd/config.hpp @@ -46,12 +46,12 @@ // http://gcc.gnu.org/wiki/Visibility // Generic helper definitions for shared library support -#if defined _WIN32 || defined __CYGWIN__ +#if BOOST_HAS_DECLSPEC #define UHD_HELPER_DLL_IMPORT __declspec(dllimport) #define UHD_HELPER_DLL_EXPORT __declspec(dllexport) #define UHD_HELPER_DLL_LOCAL #else - #if __GNUC__ >= 4 + #if __GNUG__ >= 4 #define UHD_HELPER_DLL_IMPORT __attribute__ ((visibility("default"))) #define UHD_HELPER_DLL_EXPORT __attribute__ ((visibility("default"))) #define UHD_HELPER_DLL_LOCAL __attribute__ ((visibility("hidden"))) diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp index c8fbc5a9f..b5fb11120 100644 --- a/host/include/uhd/types/dict.hpp +++ b/host/include/uhd/types/dict.hpp @@ -29,7 +29,7 @@ namespace uhd{ /*! * A templated dictionary class with a python-like interface. */ - template <class Key, class Val> class dict{ + template <typename Key, typename Val> class dict{ public: typedef std::pair<Key, Val> pair_t; @@ -130,7 +130,7 @@ namespace uhd{ BOOST_FOREACH(pair_t &p, _map){ if (p.first == key) return p.second; } - _map.push_back(pair_t(key, Val())); + _map.push_back(std::make_pair(key, Val())); return _map.back().second; } diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp index 8fe9cde82..72b655745 100644 --- a/host/include/uhd/utils/algorithm.hpp +++ b/host/include/uhd/utils/algorithm.hpp @@ -19,43 +19,25 @@ #define INCLUDED_UHD_UTILS_ALGORITHM_HPP #include <algorithm> +#include <boost/range/functions.hpp> /*! * Useful templated functions and classes that I like to pretend are part of stl */ namespace std{ - 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<typename Range, typename T> inline + bool has(const Range &range, const T &value){ + return boost::end(range) != std::find(boost::begin(range), boost::end(range), value); } - template<class T, class Iterable, class Function> - T reduce(Iterable iterable, Function fcn, T init = 0){ - return reduce(iterable.begin(), iterable.end(), fcn, init); - } - - template<class T, class InputIterator> - bool has(InputIterator first, InputIterator last, const T &elem){ - return last != std::find(first, last, elem); - } - - template<class T, class Iterable> - bool has(const Iterable &iterable, const T &elem){ - return has(iterable.begin(), iterable.end(), elem); - } - - template<class T> T signum(T n){ + template<typename T> inline T signum(T n){ if (n < 0) return -1; if (n > 0) return 1; return 0; } - template<class T> T clip(T val, T minVal, T maxVal){ + template<typename T> inline T clip(T val, T minVal, T maxVal){ return std::min(std::max(val, minVal), maxVal); } diff --git a/host/include/uhd/utils/assert.hpp b/host/include/uhd/utils/assert.hpp index 01beed757..ed0a95535 100644 --- a/host/include/uhd/utils/assert.hpp +++ b/host/include/uhd/utils/assert.hpp @@ -46,28 +46,28 @@ namespace uhd{ * The "what" in the error will show what is * being set and a list of known good values. * - * \param iterable a list of possible settings - * \param elem an element that may be in the list + * \param range a list of possible settings + * \param value an element that may be in the list * \param what a description of what is being set * \throw assertion_error when elem not in list */ - template<class T, class Iterable> void assert_has( - const Iterable &iterable, - const T &elem, + template<typename T, typename Range> void assert_has( + const Range &range, + const T &value, const std::string &what = "unknown" ){ - if (std::has(iterable, elem)) return; + if (std::has(range, value)) return; std::string possible_values = ""; size_t i = 0; - BOOST_FOREACH(const T &e, iterable){ + BOOST_FOREACH(const T &v, range){ if (i++ > 0) possible_values += ", "; - possible_values += boost::lexical_cast<std::string>(e); + possible_values += boost::lexical_cast<std::string>(v); } boost::throw_exception(uhd::assert_error() << assert_info(str(boost::format( "Error: %s is not a valid %s. " "Possible values are: [%s]." ) - % boost::lexical_cast<std::string>(elem) + % boost::lexical_cast<std::string>(value) % what % possible_values ))); } |