summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-06 15:38:56 -0800
committerJosh Blum <josh@joshknows.com>2011-01-06 15:38:56 -0800
commit771b5cebda250f2a6a65aa7788e9051c94974c2b (patch)
tree78856934a0786b962d5acafde2eb3338ab5df582
parent3d02c07470e83edfa118c7ff36e793ffa883ceff (diff)
downloaduhd-771b5cebda250f2a6a65aa7788e9051c94974c2b.tar.gz
uhd-771b5cebda250f2a6a65aa7788e9051c94974c2b.tar.bz2
uhd-771b5cebda250f2a6a65aa7788e9051c94974c2b.zip
uhd: integrated boost split or tokenizer into source files, remove string split from algorithms header
-rw-r--r--host/include/uhd/utils/algorithm.hpp29
-rw-r--r--host/lib/types/device_addr.cpp14
-rw-r--r--host/lib/usrp/subdev_spec.cpp12
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp7
-rw-r--r--host/lib/utils/paths.cpp8
-rw-r--r--host/lib/utils/warning.cpp8
-rw-r--r--host/utils/uhd_usrp_probe.cpp5
7 files changed, 39 insertions, 44 deletions
diff --git a/host/include/uhd/utils/algorithm.hpp b/host/include/uhd/utils/algorithm.hpp
index 53c571e4e..ed0220a25 100644
--- a/host/include/uhd/utils/algorithm.hpp
+++ b/host/include/uhd/utils/algorithm.hpp
@@ -22,9 +22,6 @@
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/size.hpp>
-#include <boost/algorithm/string.hpp>
-#include <vector>
-#include <string>
/*! \file algorithm.hpp
* Useful templated functions and classes that I like to pretend are part of stl.
@@ -33,24 +30,6 @@
namespace std{
/*!
- * Split a string at the separation characters.
- * \param string the string to split
- * \param sep the separator characters
- * \return a range of strings
- */
- inline std::vector<std::string> split_string(
- const std::string &string, const std::string &sep = "\t "
- ){
- std::vector<std::string> strings;
- if (not string.empty()) boost::split(
- // do not split an empty string:
- // let me tell you about the time when boost::split segfaulted...
- strings, string, boost::is_any_of(sep)
- );
- return strings;
- }
-
- /*!
* A wrapper around std::copy that takes ranges instead of iterators.
*
* Copy the elements of the source range into the destination range.
@@ -164,8 +143,12 @@ namespace std{
* \param bound2 the upper or lower bound
* \return the value clipped at the bounds
*/
- template<typename T> inline T clip(T val, T bound1, T bound2){
- return std::min(std::max(val, std::min(bound1, bound2)), std::max(bound1, bound2));
+ template<typename T> inline T clip(const T &val, const T &bound1, const T &bound2){
+ const T minimum = std::min(bound1, bound2);
+ if (val < minimum) return minimum;
+ const T maximum = std::max(bound1, bound2);
+ if (val > maximum) return maximum;
+ return val;
}
}//namespace std
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp
index 4fdce097b..14afaa24b 100644
--- a/host/lib/types/device_addr.cpp
+++ b/host/lib/types/device_addr.cpp
@@ -32,19 +32,15 @@ static std::string trim(const std::string &in){
return boost::algorithm::trim_copy(in);
}
-static boost::tokenizer<boost::char_separator<char> > tokenize(
- const std::string &input, const std::string &tok
-){
- return boost::tokenizer<boost::char_separator<char> >(
- input, boost::char_separator<char>(tok.c_str())
- );
-}
+#define tokenizer(inp, sep) \
+ boost::tokenizer<boost::char_separator<char> > \
+ (inp, boost::char_separator<char>(sep.c_str()))
device_addr_t::device_addr_t(const std::string &args){
- BOOST_FOREACH(const std::string &pair, tokenize(args, arg_delim)){
+ BOOST_FOREACH(const std::string &pair, tokenizer(args, arg_delim)){
if (trim(pair) == "") continue;
std::string key;
- BOOST_FOREACH(const std::string &tok, tokenize(pair, pair_delim)){
+ BOOST_FOREACH(const std::string &tok, tokenizer(pair, pair_delim)){
if (key.empty()) key = tok;
else{
this->set(trim(key), trim(tok));
diff --git a/host/lib/usrp/subdev_spec.cpp b/host/lib/usrp/subdev_spec.cpp
index 95d2cbb12..c905eab7d 100644
--- a/host/lib/usrp/subdev_spec.cpp
+++ b/host/lib/usrp/subdev_spec.cpp
@@ -16,15 +16,21 @@
//
#include <uhd/usrp/subdev_spec.hpp>
-#include <uhd/utils/algorithm.hpp>
+#include <boost/algorithm/string.hpp> //for split
+#include <boost/tokenizer.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <stdexcept>
#include <sstream>
+#include <vector>
using namespace uhd;
using namespace uhd::usrp;
+#define pair_tokenizer(inp) \
+ boost::tokenizer<boost::char_separator<char> > \
+ (inp, boost::char_separator<char>(" "))
+
subdev_spec_pair_t::subdev_spec_pair_t(
const std::string &db_name, const std::string &sd_name
):
@@ -39,9 +45,9 @@ bool usrp::operator==(const subdev_spec_pair_t &lhs, const subdev_spec_pair_t &r
}
subdev_spec_t::subdev_spec_t(const std::string &markup){
- BOOST_FOREACH(const std::string &pair, std::split_string(markup)){
+ BOOST_FOREACH(const std::string &pair, pair_tokenizer(markup)){
if (pair == "") continue;
- std::vector<std::string> db_sd = std::split_string(pair, ":");
+ std::vector<std::string> db_sd; boost::split(db_sd, pair, boost::is_any_of(":"));
switch(db_sd.size()){
case 1: this->push_back(subdev_spec_pair_t("", db_sd.front())); break;
case 2: this->push_back(subdev_spec_pair_t(db_sd.front(), db_sd.back())); break;
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index f910999d4..06ca61e13 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -22,7 +22,7 @@
#include <uhd/utils/assert.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/warning.hpp>
-#include <uhd/utils/algorithm.hpp>
+#include <boost/algorithm/string.hpp> //for split
#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
@@ -31,6 +31,7 @@
#include <boost/bind.hpp>
#include <boost/asio.hpp> //htonl and ntohl
#include <iostream>
+#include <vector>
using namespace uhd;
using namespace uhd::usrp;
@@ -47,8 +48,8 @@ template <class T> std::string num2str(T num){
//! separate indexed device addresses into a vector of device addresses
device_addrs_t sep_indexed_dev_addrs(const device_addr_t &dev_addr){
//------------ support old deprecated way and print warning --------
- if (dev_addr.has_key("addr")){
- std::vector<std::string> addrs = std::split_string(dev_addr["addr"]);
+ if (dev_addr.has_key("addr") and not dev_addr["addr"].empty()){
+ std::vector<std::string> addrs; boost::split(addrs, dev_addr["addr"], boost::is_any_of(" "));
if (addrs.size() > 1){
device_addr_t fixed_dev_addr = dev_addr;
fixed_dev_addr.pop("addr");
diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp
index 9e9525caf..f2037a38d 100644
--- a/host/lib/utils/paths.cpp
+++ b/host/lib/utils/paths.cpp
@@ -17,7 +17,7 @@
#include "constants.hpp"
#include <uhd/config.hpp>
-#include <uhd/utils/algorithm.hpp>
+#include <boost/tokenizer.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>
@@ -38,6 +38,10 @@ namespace fs = boost::filesystem;
static const std::string env_path_sep = ":";
#endif /*UHD_PLATFORM_WIN32*/
+#define path_tokenizer(inp) \
+ boost::tokenizer<boost::char_separator<char> > \
+ (inp, boost::char_separator<char>(env_path_sep.c_str()))
+
/***********************************************************************
* Get a list of paths for an environment variable
**********************************************************************/
@@ -60,7 +64,7 @@ static std::vector<fs::path> get_env_paths(const std::string &var_name){
//convert to filesystem path, filter blank paths
std::vector<fs::path> paths;
- BOOST_FOREACH(const std::string &path_string, std::split_string(var_value, env_path_sep)){
+ BOOST_FOREACH(const std::string &path_string, path_tokenizer(var_value)){
if (path_string.empty()) continue;
paths.push_back(fs::system_complete(path_string));
}
diff --git a/host/lib/utils/warning.cpp b/host/lib/utils/warning.cpp
index 05be7ae4d..09a12aba5 100644
--- a/host/lib/utils/warning.cpp
+++ b/host/lib/utils/warning.cpp
@@ -16,7 +16,7 @@
//
#include <uhd/utils/warning.hpp>
-#include <uhd/utils/algorithm.hpp>
+#include <boost/tokenizer.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/types/dict.hpp>
#include <boost/foreach.hpp>
@@ -27,6 +27,10 @@
using namespace uhd;
+#define tokenizer(inp, sep) \
+ boost::tokenizer<boost::char_separator<char> > \
+ (inp, boost::char_separator<char>(sep))
+
/***********************************************************************
* Registry implementation
**********************************************************************/
@@ -52,7 +56,7 @@ void warning::post(const std::string &msg){
//format the warning message
ss << std::endl << "Warning:" << std::endl;
- BOOST_FOREACH(const std::string &line, std::split_string(msg, "\n")){
+ BOOST_FOREACH(const std::string &line, tokenizer(msg, "\n")){
ss << " " << line << std::endl;
}
diff --git a/host/utils/uhd_usrp_probe.cpp b/host/utils/uhd_usrp_probe.cpp
index 5cba7c362..8b28e8280 100644
--- a/host/utils/uhd_usrp_probe.cpp
+++ b/host/utils/uhd_usrp_probe.cpp
@@ -18,7 +18,7 @@
#include <uhd/utils/safe_main.hpp>
#include <uhd/device.hpp>
#include <uhd/types/ranges.hpp>
-#include <uhd/utils/algorithm.hpp>
+#include <boost/algorithm/string.hpp> //for split
#include <uhd/usrp/device_props.hpp>
#include <uhd/usrp/mboard_props.hpp>
#include <uhd/usrp/dboard_props.hpp>
@@ -32,6 +32,7 @@
#include <boost/foreach.hpp>
#include <iostream>
#include <sstream>
+#include <vector>
namespace po = boost::program_options;
using namespace uhd;
@@ -44,7 +45,7 @@ static std::string make_border(const std::string &text){
std::stringstream ss;
ss << boost::format(" _____________________________________________________") << std::endl;
ss << boost::format(" /") << std::endl;
- std::vector<std::string> lines = std::split_string(text, "\n");
+ std::vector<std::string> lines; boost::split(lines, text, boost::is_any_of("\n"));
while (lines.back() == "") lines.pop_back(); //strip trailing newlines
if (lines.size()) lines[0] = " " + lines[0]; //indent the title line
BOOST_FOREACH(const std::string &line, lines){