USRP Hardware Driver and USRP Manual  Version: 3.15.0.0-4+b1satnogs1
UHD and USRP Manual
device_addr.hpp
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_TYPES_DEVICE_ADDR_HPP
9 #define INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP
10 
11 #include <uhd/config.hpp>
12 #include <uhd/types/dict.hpp>
13 #include <boost/lexical_cast.hpp>
14 #include <map>
15 #include <stdexcept>
16 #include <string>
17 #include <vector>
18 
19 namespace uhd {
20 
38 class UHD_API device_addr_t : public dict<std::string, std::string>
39 {
40 public:
45  device_addr_t(const std::string& args = "");
46 
51  device_addr_t(const std::map<std::string, std::string>& info);
52 
57  std::string to_pp_string(void) const;
58 
64  std::string to_string(void) const;
65 
74  template <typename T>
75  T cast(const std::string& key, const T& def) const
76  {
77  if (not this->has_key(key))
78  return def;
79  try {
80  // Avoid Boost warnings from lexical_cast. Some Boost versions use
81  // default-initializers, which can throw off the compiler if they're
82  // not defined.
83 #if defined(__clang__) || defined(__GNUC__)
84 # pragma GCC diagnostic push
85 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
86 #endif
87  return boost::lexical_cast<T>((*this)[key]);
88 #if defined(__clang__) || defined(__GNUC__)
89 # pragma GCC diagnostic pop
90 #endif
91  } catch (const boost::bad_lexical_cast&) {
92  throw std::runtime_error("cannot cast " + key + " = " + (*this)[key]);
93  }
94  }
95 };
96 
98 typedef std::vector<device_addr_t> device_addrs_t;
99 
102 
105 
106 } // namespace uhd
107 
108 #endif /* INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP */
Definition: device_addr.hpp:39
device_addr_t(const std::string &args="")
T cast(const std::string &key, const T &def) const
Definition: device_addr.hpp:75
std::string to_string(void) const
device_addr_t(const std::map< std::string, std::string > &info)
std::string to_pp_string(void) const
Definition: dict.hpp:23
#define UHD_API
Definition: config.h:68
@ info
Definition: log.hpp:107
Definition: build_info.hpp:13
UHD_API device_addrs_t separate_device_addr(const device_addr_t &dev_addr)
Separate an indexed device address into a vector of device addresses.
UHD_API device_addr_t combine_device_addrs(const device_addrs_t &dev_addrs)
Combine a vector of device addresses into an indexed device address.
std::vector< device_addr_t > device_addrs_t
A typedef for a vector of device addresses.
Definition: device_addr.hpp:98