USRP Hardware Driver and USRP Manual Version: 3.15.0.0-MacPorts-Release
UHD and USRP Manual
 
Loading...
Searching...
No Matches
assert_has.ipp
Go to the documentation of this file.
1//
2// Copyright 2010-2011 Ettus Research LLC
3// Copyright 2018 Ettus Research, a National Instruments Company
4//
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
7
8#ifndef INCLUDED_UHD_UTILS_ASSERT_HAS_IPP
9#define INCLUDED_UHD_UTILS_ASSERT_HAS_IPP
10
12#include <uhd/exception.hpp>
13#include <boost/format.hpp>
14#include <boost/lexical_cast.hpp>
15#include <boost/foreach.hpp>
16
17namespace uhd{
18
19 template<typename T, typename Range> UHD_INLINE void assert_has(
20 const Range &range,
21 const T &value,
22 const std::string &what
23 ){
24 if (uhd::has(range, value)) return;
25 std::string possible_values = "";
26 size_t i = 0;
27 BOOST_FOREACH(const T &v, range){
28 if (i++ > 0) possible_values += ", ";
29 possible_values += boost::lexical_cast<std::string>(v);
30 }
31 throw uhd::assertion_error(str(boost::format(
32 "assertion failed:\n"
33 " %s is not a valid %s.\n"
34 " possible values are: [%s].\n"
35 )
36 % boost::lexical_cast<std::string>(value)
37 % what % possible_values
38 ));
39 }
40
41}//namespace uhd
42
43#endif /* INCLUDED_UHD_UTILS_ASSERT_HAS_IPP */
#define UHD_INLINE
Definition config.h:53
Definition build_info.hpp:13
UHD_INLINE bool has(const Range &range, const T &value)
Definition algorithm.hpp:66
void assert_has(const Range &range, const T &value, const std::string &what="unknown")
Definition assert_has.ipp:19
Definition exception.hpp:50