UHD 003.002.002

include/uhd/types/device_addr.hpp

Go to the documentation of this file.
00001 //
00002 // Copyright 2010-2011 Ettus Research LLC
00003 //
00004 // This program is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP
00019 #define INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP
00020 
00021 #include <uhd/config.hpp>
00022 #include <uhd/types/dict.hpp>
00023 #include <boost/lexical_cast.hpp>
00024 #include <stdexcept>
00025 #include <vector>
00026 #include <string>
00027 
00028 namespace uhd{
00029 
00047     class UHD_API device_addr_t : public dict<std::string, std::string>{
00048     public:
00053         device_addr_t(const std::string &args = "");
00054 
00059         std::string to_pp_string(void) const;
00060 
00066         std::string to_string(void) const;
00067 
00076         template <typename T> T cast(const std::string &key, const T &def) const{
00077             if (not this->has_key(key)) return def;
00078             try{
00079                 return boost::lexical_cast<T>((*this)[key]);
00080             }
00081             catch(const boost::bad_lexical_cast &){
00082                 throw std::runtime_error("cannot cast " + key + " = " + (*this)[key]);
00083             }
00084         }
00085     };
00086 
00088     typedef std::vector<device_addr_t> device_addrs_t;
00089 
00091     UHD_API device_addrs_t separate_device_addr(const device_addr_t &dev_addr);
00092 
00094     UHD_API device_addr_t combine_device_addrs(const device_addrs_t &dev_addrs);
00095 
00096 } //namespace uhd
00097 
00098 #endif /* INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines