USRP Hardware Driver and USRP Manual Version: 4.1.0.3
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
18namespace uhd {
19
37class UHD_API device_addr_t : public dict<std::string, std::string>
38{
39public:
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>
74 T cast(const std::string& key, const T& def) const
75 {
76 if (not this->has_key(key))
77 return def;
78 try {
79 return boost::lexical_cast<T>((*this)[key]);
80 } catch (const boost::bad_lexical_cast&) {
81 throw std::runtime_error("cannot cast " + key + " = " + (*this)[key]);
82 }
83 }
84};
85
87typedef std::vector<device_addr_t> device_addrs_t;
88
91
94
95} // namespace uhd
Definition: device_addr.hpp:38
device_addr_t(const std::string &args="")
T cast(const std::string &key, const T &def) const
Definition: device_addr.hpp:74
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:22
#define UHD_API
Definition: config.h:70
@ info
Definition: log.hpp:118
Definition: build_info.hpp:12
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:87