diff options
| author | Josh Blum <josh@joshknows.com> | 2011-01-19 22:23:46 -0800 | 
|---|---|---|
| committer | Josh Blum <josh@joshknows.com> | 2011-01-19 22:23:46 -0800 | 
| commit | 9239878b0b81c3a368bf11cfc2fe48bfb05ff902 (patch) | |
| tree | f41a5e58eac89b35cb99537a0a0b64662384a9f2 /host/lib/utils | |
| parent | fc138381ee4bd8d191795230b7447071a85e1f28 (diff) | |
| parent | 7d918c5f6acc9a5d2c8ae03e2e67b403f7efd5ff (diff) | |
| download | uhd-9239878b0b81c3a368bf11cfc2fe48bfb05ff902.tar.gz uhd-9239878b0b81c3a368bf11cfc2fe48bfb05ff902.tar.bz2 uhd-9239878b0b81c3a368bf11cfc2fe48bfb05ff902.zip  | |
Merge branch 'next'
Conflicts:
	host/lib/usrp/usrp2/codec_impl.cpp
Diffstat (limited to 'host/lib/utils')
| -rw-r--r-- | host/lib/utils/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | host/lib/utils/gain_group.cpp | 20 | ||||
| -rw-r--r-- | host/lib/utils/paths.cpp | 10 | ||||
| -rw-r--r-- | host/lib/utils/static.cpp | 32 | ||||
| -rw-r--r-- | host/lib/utils/warning.cpp | 10 | 
5 files changed, 58 insertions, 17 deletions
diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 60df24eef..5fa5b4d6d 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -1,5 +1,5 @@  # -# Copyright 2010 Ettus Research LLC +# Copyright 2010-2011 Ettus Research LLC  #  # This program is free software: you can redistribute it and/or modify  # it under the terms of the GNU General Public License as published by @@ -87,6 +87,7 @@ LIBUHD_APPEND_SOURCES(      ${CMAKE_CURRENT_SOURCE_DIR}/load_modules.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/paths.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/props.cpp +    ${CMAKE_CURRENT_SOURCE_DIR}/static.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/thread_priority.cpp      ${CMAKE_CURRENT_SOURCE_DIR}/warning.cpp  ) diff --git a/host/lib/utils/gain_group.cpp b/host/lib/utils/gain_group.cpp index 11bbb8c0a..07aa21115 100644 --- a/host/lib/utils/gain_group.cpp +++ b/host/lib/utils/gain_group.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC  //  // This program is free software: you can redistribute it and/or modify  // it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ static bool compare_by_step_size(   * Get a multiple of step with the following relation:   *     result = step*floor(num/step)   * - * Due to small floating-point inaccuracies: + * Due to small doubleing-point inaccuracies:   *     num = n*step + e, where e is a small inaccuracy.   * When e is negative, floor would yeild (n-1)*step,   * despite that n*step is really the desired result. @@ -66,7 +66,7 @@ public:      gain_range_t get_range(const std::string &name){          if (not name.empty()) return _name_to_fcns[name].get_range(); -        float overall_min = 0, overall_max = 0, overall_step = 0; +        double overall_min = 0, overall_max = 0, overall_step = 0;          BOOST_FOREACH(const gain_fcns_t &fcns, get_all_fcns()){              const gain_range_t range = fcns.get_range();              overall_min += range.start(); @@ -78,33 +78,33 @@ public:          return gain_range_t(overall_min, overall_max, overall_step);      } -    float get_value(const std::string &name){ +    double get_value(const std::string &name){          if (not name.empty()) return _name_to_fcns[name].get_value(); -        float overall_gain = 0; +        double overall_gain = 0;          BOOST_FOREACH(const gain_fcns_t &fcns, get_all_fcns()){              overall_gain += fcns.get_value();          }          return overall_gain;      } -    void set_value(float gain, const std::string &name){ +    void set_value(double gain, const std::string &name){          if (not name.empty()) return _name_to_fcns[name].set_value(gain);          std::vector<gain_fcns_t> all_fcns = get_all_fcns();          if (all_fcns.size() == 0) return; //nothing to set!          //get the max step size among the gains -        float max_step = 0; +        double max_step = 0;          BOOST_FOREACH(const gain_fcns_t &fcns, all_fcns){              max_step = std::max(max_step, fcns.get_range().step());          }          //create gain bucket to distribute power -        std::vector<float> gain_bucket; +        std::vector<double> gain_bucket;          //distribute power according to priority (round to max step) -        float gain_left_to_distribute = gain; +        double gain_left_to_distribute = gain;          BOOST_FOREACH(const gain_fcns_t &fcns, all_fcns){              const gain_range_t range = fcns.get_range();              gain_bucket.push_back(floor_step(std::clip( @@ -131,7 +131,7 @@ public:          //fill in the largest step sizes first that are less than the remainder          BOOST_FOREACH(size_t i, indexes_step_size_dec){              const gain_range_t range = all_fcns.at(i).get_range(); -            float additional_gain = floor_step(std::clip( +            double additional_gain = floor_step(std::clip(                  gain_bucket.at(i) + gain_left_to_distribute, range.start(), range.stop()              ), range.step()) - gain_bucket.at(i);              gain_bucket.at(i) += additional_gain; diff --git a/host/lib/utils/paths.cpp b/host/lib/utils/paths.cpp index 9e9525caf..93d15d290 100644 --- a/host/lib/utils/paths.cpp +++ b/host/lib/utils/paths.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC  //  // This program is free software: you can redistribute it and/or modify  // it under the terms of the GNU General Public License as published by @@ -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/static.cpp b/host/lib/utils/static.cpp new file mode 100644 index 000000000..a0dea3372 --- /dev/null +++ b/host/lib/utils/static.cpp @@ -0,0 +1,32 @@ +// +// Copyright 2011 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.  If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/utils/static.hpp> +#include <stdexcept> +#include <iostream> +_uhd_static_fixture::_uhd_static_fixture(void (*fcn)(void), const char *name){ +    try{ +        fcn(); +    } +    catch(const std::exception &e){ +        std::cerr << "Exception in static block " << name << std::endl; +        std::cerr << "  " << e.what() << std::endl; +    } +    catch(...){ +        std::cerr << "Exception in static block " << name << std::endl; +    } +} diff --git a/host/lib/utils/warning.cpp b/host/lib/utils/warning.cpp index 05be7ae4d..bc4c79b6e 100644 --- a/host/lib/utils/warning.cpp +++ b/host/lib/utils/warning.cpp @@ -1,5 +1,5 @@  // -// Copyright 2010 Ettus Research LLC +// Copyright 2010-2011 Ettus Research LLC  //  // This program is free software: you can redistribute it and/or modify  // it under the terms of the GNU General Public License as published by @@ -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;      }  | 
