USRP Hardware Driver and USRP Manual  Version: 3.11.0.HEAD-0-gdca39145
UHD and USRP Manual
device_addr.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2010-2011 Ettus Research LLC
3 //
4 // SPDX-License-Identifier: GPL-3.0
5 //
6 
7 #ifndef INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP
8 #define INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP
9 
10 #include <uhd/config.hpp>
11 #include <uhd/types/dict.hpp>
12 #include <boost/lexical_cast.hpp>
13 #include <stdexcept>
14 #include <vector>
15 #include <string>
16 
17 namespace uhd{
18 
36  class UHD_API device_addr_t : public dict<std::string, std::string>{
37  public:
42  device_addr_t(const std::string &args = "");
43 
48  std::string to_pp_string(void) const;
49 
55  std::string to_string(void) const;
56 
65  template <typename T> T cast(const std::string &key, const T &def) const{
66  if (not this->has_key(key)) return def;
67  try{
68  return boost::lexical_cast<T>((*this)[key]);
69  }
70  catch(const boost::bad_lexical_cast &){
71  throw std::runtime_error("cannot cast " + key + " = " + (*this)[key]);
72  }
73  }
74  };
75 
77  typedef std::vector<device_addr_t> device_addrs_t;
78 
80  UHD_API device_addrs_t separate_device_addr(const device_addr_t &dev_addr);
81 
83  UHD_API device_addr_t combine_device_addrs(const device_addrs_t &dev_addrs);
84 
85 } //namespace uhd
86 
87 #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: dict.hpp:19
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:65
std::vector< device_addr_t > device_addrs_t
A typedef for a vector of device addresses.
Definition: device_addr.hpp:77
#define UHD_API
Definition: config.h:62
Definition: device_addr.hpp:36