diff options
author | Thomas Habets <habets@google.com> | 2021-04-06 21:21:52 +0100 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-05-02 19:00:31 -0400 |
commit | cefe09329bbbec6256e5a1d0efa669f1c5111404 (patch) | |
tree | 272cf163730ebed93fa193d58aaab341b819d198 | |
parent | e396aefe6c4f796da6ce3dcc626615ad8b847e7e (diff) |
runtime: Access d_config_map cleaner
Signed-off-by: Thomas Habets <thomas@habets.se>
-rw-r--r-- | gnuradio-runtime/include/gnuradio/prefs.h | 11 | ||||
-rw-r--r-- | gnuradio-runtime/lib/prefs.cc | 27 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc | 2 |
3 files changed, 11 insertions, 29 deletions
diff --git a/gnuradio-runtime/include/gnuradio/prefs.h b/gnuradio-runtime/include/gnuradio/prefs.h index 2fa6f86bc4..c908c04854 100644 --- a/gnuradio-runtime/include/gnuradio/prefs.h +++ b/gnuradio-runtime/include/gnuradio/prefs.h @@ -14,16 +14,11 @@ #include <gnuradio/api.h> #include <gnuradio/thread/thread.h> #include <map> +#include <mutex> #include <string> namespace gr { -typedef std::map<std::string, std::map<std::string, std::string>> config_map_t; -typedef std::map<std::string, std::map<std::string, std::string>>::iterator - config_map_itr; -typedef std::map<std::string, std::string> config_map_elem_t; -typedef std::map<std::string, std::string>::iterator config_map_elem_itr; - /*! * \brief Base class for representing user preferences a la windows INI files. * \ingroup misc @@ -52,8 +47,6 @@ public: */ prefs(); - virtual ~prefs(); - /*! * If specifying a file name, this opens that specific * configuration file of the standard form containing sections and @@ -155,7 +148,7 @@ protected: private: std::mutex d_mutex; - config_map_t d_config_map; + std::map<std::string, std::map<std::string, std::string>> d_config_map; }; } /* namespace gr */ diff --git a/gnuradio-runtime/lib/prefs.cc b/gnuradio-runtime/lib/prefs.cc index 5236b9c59f..c1d9f9d5cd 100644 --- a/gnuradio-runtime/lib/prefs.cc +++ b/gnuradio-runtime/lib/prefs.cc @@ -20,7 +20,6 @@ #include <filesystem> #include <fstream> #include <iostream> -#include <mutex> #include <boost/program_options.hpp> namespace fs = std::filesystem; @@ -50,11 +49,6 @@ prefs* prefs::singleton() prefs::prefs() { _read_files(_sys_prefs_filenames()); } -prefs::~prefs() -{ - // nop -} - std::vector<std::string> prefs::_sys_prefs_filenames() { std::vector<std::string> fnames; @@ -128,16 +122,13 @@ void prefs::add_config_file(const std::string& configfile) std::string prefs::to_string() { - config_map_itr sections; - config_map_elem_itr options; std::stringstream s; std::lock_guard<std::mutex> lk(d_mutex); - for (sections = d_config_map.begin(); sections != d_config_map.end(); sections++) { - s << "[" << sections->first << "]" << std::endl; - for (options = sections->second.begin(); options != sections->second.end(); - options++) { - s << options->first << " = " << options->second << std::endl; + for (const auto& sections : d_config_map) { + s << "[" << sections.first << "]" << std::endl; + for (const auto& options : sections.second) { + s << options.first << " = " << options.second << std::endl; } s << std::endl; } @@ -170,7 +161,7 @@ bool prefs::has_section(const std::string& section) std::string s = section; stolower(s); std::lock_guard<std::mutex> lk(d_mutex); - return d_config_map.count(s) > 0; + return d_config_map.find(s) != d_config_map.end(); } bool prefs::has_option(const std::string& section, const std::string& option) @@ -188,8 +179,8 @@ bool prefs::has_option(const std::string& section, const std::string& option) stolower(o); std::lock_guard<std::mutex> lk(d_mutex); - config_map_itr sec = d_config_map.find(s); - return sec->second.count(o) > 0; + const auto& sec = d_config_map[s]; + return sec.find(o) != sec.end(); } // get_string needs specialization because it can have spaces. @@ -212,9 +203,7 @@ const std::string prefs::get_string(const std::string& section, stolower(o); std::lock_guard<std::mutex> lk(d_mutex); - config_map_itr sec = d_config_map.find(s); - config_map_elem_itr opt = sec->second.find(o); - return opt->second; + return d_config_map[s][o]; } // get_bool() needs specialization because there are multiple text strings for true/false diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc index e5e21ca49b..6236ae3711 100644 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc @@ -14,7 +14,7 @@ /* BINDTOOL_GEN_AUTOMATIC(0) */ /* BINDTOOL_USE_PYGCCXML(0) */ /* BINDTOOL_HEADER_FILE(prefs.h) */ -/* BINDTOOL_HEADER_FILE_HASH(4d5fd75bdefb15004e9f86e1ddec95fc) */ +/* BINDTOOL_HEADER_FILE_HASH(f9d239804a24578ed1abfd735b31ca6b) */ /***********************************************************************************/ #include <pybind11/complex.h> |