USRP Hardware Driver and USRP Manual  Version: 003.010.003.HEAD-0-gef157678
UHD and USRP Manual
device_addr.hpp
Go to the documentation of this file.
1 //
2 // Copyright 2010-2011 Ettus Research LLC
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 //
17 
18 #ifndef INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP
19 #define INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP
20 
21 #include <uhd/config.hpp>
22 #include <uhd/types/dict.hpp>
23 #include <boost/lexical_cast.hpp>
24 #include <stdexcept>
25 #include <vector>
26 #include <string>
27 
28 namespace uhd{
29 
47  class UHD_API device_addr_t : public dict<std::string, std::string>{
48  public:
53  device_addr_t(const std::string &args = "");
54 
59  std::string to_pp_string(void) const;
60 
66  std::string to_string(void) const;
67 
76  template <typename T> T cast(const std::string &key, const T &def) const{
77  if (not this->has_key(key)) return def;
78  try{
79  return boost::lexical_cast<T>((*this)[key]);
80  }
81  catch(const boost::bad_lexical_cast &){
82  throw std::runtime_error("cannot cast " + key + " = " + (*this)[key]);
83  }
84  }
85  };
86 
88  typedef std::vector<device_addr_t> device_addrs_t;
89 
91  UHD_API device_addrs_t separate_device_addr(const device_addr_t &dev_addr);
92 
94  UHD_API device_addr_t combine_device_addrs(const device_addrs_t &dev_addrs);
95 
96 } //namespace uhd
97 
98 #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:30
Definition: build_info.hpp:25
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:76
std::vector< device_addr_t > device_addrs_t
A typedef for a vector of device addresses.
Definition: device_addr.hpp:88
#define UHD_API
Definition: config.h:73
Definition: device_addr.hpp:47