USRP Hardware Driver and USRP Manual  Version: 003.010.000.HEAD-0-g6e1ac3fc
UHD and USRP Manual
algorithm.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_UHD_UTILS_ALGORITHM_HPP
19 #define INCLUDED_UHD_UTILS_ALGORITHM_HPP
20 
21 #include <algorithm>
22 #include <boost/cstdint.hpp>
23 #include <boost/range/begin.hpp>
24 #include <boost/range/end.hpp>
25 
31 namespace uhd{
42  template<typename Range> UHD_INLINE Range sorted(const Range &range){
43  Range r(range); std::sort(boost::begin(r), boost::end(r)); return r;
44  }
45 
56  template<typename Range> UHD_INLINE Range reversed(const Range &range){
57  Range r(range); std::reverse(boost::begin(r), boost::end(r)); return r;
58  }
59 
69  template<typename Range, typename T> UHD_INLINE
70  bool has(const Range &range, const T &value){
71  return boost::end(range) != std::find(boost::begin(range), boost::end(range), value);
72  }
73 
81  template<typename T> UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2){
82  const T minimum = std::min(bound1, bound2);
83  if (val < minimum) return minimum;
84  const T maximum = std::max(bound1, bound2);
85  if (val > maximum) return maximum;
86  return val;
87  }
88 
89 } //namespace uhd
90 
91 #endif /* INCLUDED_UHD_UTILS_ALGORITHM_HPP */
UHD_INLINE Range reversed(const Range &range)
Definition: algorithm.hpp:56
UHD_INLINE bool has(const Range &range, const T &value)
Definition: algorithm.hpp:70
UHD_INLINE T clip(const T &val, const T &bound1, const T &bound2)
Definition: algorithm.hpp:81
Definition: build_info.hpp:25
#define UHD_INLINE
Definition: config.h:63
UHD_INLINE Range sorted(const Range &range)
Definition: algorithm.hpp:42