diff options
author | Josh Blum <josh@joshknows.com> | 2010-04-20 12:05:33 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-04-20 12:05:33 -0700 |
commit | eae0bec99bca5efa1e86faa03132ec5e8aca5fe5 (patch) | |
tree | 12a51e33d54293e2b7911f202fc5ae233fdae7ae /host/lib/types.cpp | |
parent | 6b015b1c517733e85cb0c08a379e8d20377bf2fa (diff) | |
download | uhd-eae0bec99bca5efa1e86faa03132ec5e8aca5fe5.tar.gz uhd-eae0bec99bca5efa1e86faa03132ec5e8aca5fe5.tar.bz2 uhd-eae0bec99bca5efa1e86faa03132ec5e8aca5fe5.zip |
Created args string contructor for device address.
Using the args string for the find devices app.
Added documentation to simple usrp.
Diffstat (limited to 'host/lib/types.cpp')
-rw-r--r-- | host/lib/types.cpp | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 2a687f34f..91887840c 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -119,46 +119,44 @@ void time_spec_t::set_ticks(boost::uint32_t ticks, double tick_rate){ /*********************************************************************** * device addr **********************************************************************/ -std::string device_addr_t::to_string(void) const{ - std::stringstream ss; - BOOST_FOREACH(std::string key, this->keys()){ - ss << boost::format("%s: %s") % key % (*this)[key] << std::endl; - } - return ss.str(); -} - -static const std::string arg_delim = ";"; +static const std::string arg_delim = ","; static const std::string pair_delim = "="; static std::string trim(const std::string &in){ return boost::algorithm::trim_copy(in); } -std::string device_addr_t::to_args_str(void) const{ - std::string args_str; - BOOST_FOREACH(const std::string &key, this->keys()){ - args_str += key + pair_delim + (*this)[key] + arg_delim; - } - return args_str; -} - -device_addr_t device_addr_t::from_args_str(const std::string &args_str){ - device_addr_t addr; - +device_addr_t::device_addr_t(const std::string &args){ //split the args at the semi-colons std::vector<std::string> pairs; - boost::split(pairs, args_str, boost::is_any_of(arg_delim)); + boost::split(pairs, args, boost::is_any_of(arg_delim)); BOOST_FOREACH(const std::string &pair, pairs){ if (trim(pair) == "") continue; //split the key value pairs at the equals std::vector<std::string> key_val; boost::split(key_val, pair, boost::is_any_of(pair_delim)); - if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args_str); - addr[trim(key_val[0])] = trim(key_val[1]); + if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args); + (*this)[trim(key_val[0])] = trim(key_val[1]); } +} + +std::string device_addr_t::to_string(void) const{ + if (this->size() == 0) return "Empty Device Address"; + + std::stringstream ss; + BOOST_FOREACH(std::string key, this->keys()){ + ss << boost::format("%s: %s") % key % (*this)[key] << std::endl; + } + return ss.str(); +} - return addr; +std::string device_addr_t::to_args_str(void) const{ + std::string args_str; + BOOST_FOREACH(const std::string &key, this->keys()){ + args_str += key + pair_delim + (*this)[key] + arg_delim; + } + return args_str; } /*********************************************************************** |