USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-ge00f1f37
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 <stdexcept>
15 #include <vector>
16 #include <string>
17 #include <map>
18 
19 namespace uhd{
20 
38  class UHD_API device_addr_t : public dict<std::string, std::string>{
39  public:
44  device_addr_t(const std::string &args = "");
45 
50  device_addr_t(const std::map<std::string, std::string> &info);
51 
56  std::string to_pp_string(void) const;
57 
63  std::string to_string(void) const;
64 
73  template <typename T> T cast(const std::string &key, const T &def) const{
74  if (not this->has_key(key)) return def;
75  try{
76  return boost::lexical_cast<T>((*this)[key]);
77  }
78  catch(const boost::bad_lexical_cast &){
79  throw std::runtime_error("cannot cast " + key + " = " + (*this)[key]);
80  }
81  }
82  };
83 
85  typedef std::vector<device_addr_t> device_addrs_t;
86 
88  UHD_API device_addrs_t separate_device_addr(const device_addr_t &dev_addr);
89 
91  UHD_API device_addr_t combine_device_addrs(const device_addrs_t &dev_addrs);
92 
93 } //namespace uhd
94 
95 #endif /* INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP */
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.
Definition: log.hpp:107
Definition: dict.hpp:20
Definition: build_info.hpp:14
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.
T cast(const std::string &key, const T &def) const
Definition: device_addr.hpp:73
std::vector< device_addr_t > device_addrs_t
A typedef for a vector of device addresses.
Definition: device_addr.hpp:85
#define UHD_API
Definition: config.h:63
Definition: device_addr.hpp:38