USRP Hardware Driver and USRP Manual  Version: 4.4.0.HEAD-0-g5fac246b
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 #pragma once
9 
10 #include <uhd/config.hpp>
11 #include <uhd/types/dict.hpp>
12 #include <boost/lexical_cast.hpp>
13 #include <map>
14 #include <stdexcept>
15 #include <string>
16 #include <vector>
17 
18 namespace uhd {
19 
37 class UHD_API device_addr_t : public dict<std::string, std::string>
38 {
39 public:
44  device_addr_t(const std::string& args = "");
45 
50  device_addr_t(const char* args);
51 
56  device_addr_t(const std::map<std::string, std::string>& info);
57 
62  std::string to_pp_string(void) const;
63 
69  std::string to_string(void) const;
70 
79  template <typename T>
80  T cast(const std::string& key, const T& def) const
81  {
82  if (not this->has_key(key))
83  return def;
84  try {
85  return boost::lexical_cast<T>((*this)[key]);
86  } catch (const boost::bad_lexical_cast&) {
87  throw std::runtime_error("cannot cast " + key + " = " + (*this)[key]);
88  }
89  }
90 };
91 
93 typedef std::vector<device_addr_t> device_addrs_t;
94 
97 
100 
101 } // namespace uhd
uhd::log::info
@ info
Definition: log.hpp:119
config.hpp
uhd::device_addrs_t
std::vector< device_addr_t > device_addrs_t
A typedef for a vector of device addresses.
Definition: device_addr.hpp:93
UHD_API
#define UHD_API
Definition: config.h:87
uhd::device_addr_t
Definition: device_addr.hpp:37
uhd
Definition: build_info.hpp:12
uhd::device_addr_t::cast
T cast(const std::string &key, const T &def) const
Definition: device_addr.hpp:80
uhd::combine_device_addrs
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.
uhd::dict
Definition: dict.hpp:21
dict.hpp
uhd::separate_device_addr
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.