diff options
author | Tom Rondeau <tom@trondeau.com> | 2015-03-02 13:44:17 -0500 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2015-04-02 15:38:57 -0700 |
commit | 7bdd6effd7b6b36ea8d86cb57329a20874fb3290 (patch) | |
tree | fc493ddf8e28e46f8209f219573e7175dd96cd5c | |
parent | c67d0a417f43c644a0ccabe46b38a1e48c3bd15d (diff) |
runtime: more generic version of prefs class.
Adds another constructor to open a particular file to configure specific preferences.
-rw-r--r-- | gnuradio-runtime/include/gnuradio/prefs.h | 28 | ||||
-rw-r--r-- | gnuradio-runtime/lib/prefs.cc | 28 | ||||
-rw-r--r-- | gnuradio-runtime/swig/prefs.i | 4 |
3 files changed, 49 insertions, 11 deletions
diff --git a/gnuradio-runtime/include/gnuradio/prefs.h b/gnuradio-runtime/include/gnuradio/prefs.h index a9a28586ab..8049be7ea1 100644 --- a/gnuradio-runtime/include/gnuradio/prefs.h +++ b/gnuradio-runtime/include/gnuradio/prefs.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2013 Free Software Foundation, Inc. + * Copyright 2006,2013,2015 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -47,10 +47,34 @@ namespace gr { public: static prefs *singleton(); + /*! + * \brief Creates an object to read preference files. + * + * \detail + * + * If no file name is given (empty arg list or ""), this opens up + * the standard GNU Radio configuration files in + * prefix/etc/gnuradio/conf.d as well as ~/.gnuradio/config.conf. + * + * Only access this through the singleton defined here: + * prefs *p = prefs::singleton(); + */ prefs(); + virtual ~prefs(); /*! + * If specifying a file name, this opens that specific + * configuration file of the standard form containing sections and + * key-value pairs: + * + * [SectionName] + * key0 = value0 + * key1 = value1 + */ + void add_config_file(const std::string &configfile); + + /*! * \brief Returns the configuration options as a string. */ std::string to_string(); @@ -137,7 +161,7 @@ namespace gr { protected: virtual std::vector<std::string> _sys_prefs_filenames(); - virtual void _read_files(); + virtual std::string _read_files(const std::vector<std::string> &filenames); virtual void _convert_to_map(const std::string &conf); virtual char * option_to_env(std::string section, std::string option); diff --git a/gnuradio-runtime/lib/prefs.cc b/gnuradio-runtime/lib/prefs.cc index b7fcaada9d..b303ffdaf9 100644 --- a/gnuradio-runtime/lib/prefs.cc +++ b/gnuradio-runtime/lib/prefs.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2013 Free Software Foundation, Inc. + * Copyright 2006,2013,2015 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -46,7 +46,10 @@ namespace gr { prefs::prefs() { - _read_files(); + std::string config = _read_files(_sys_prefs_filenames()); + + // Convert the string into a map + _convert_to_map(config); } prefs::~prefs() @@ -83,13 +86,12 @@ namespace gr { return fnames; } - void - prefs::_read_files() + std::string + prefs::_read_files(const std::vector<std::string> &filenames) { std::string config; - std::vector<std::string> filenames = _sys_prefs_filenames(); - std::vector<std::string>::iterator sitr; + std::vector<std::string>::const_iterator sitr; char tmp[1024]; for(sitr = filenames.begin(); sitr != filenames.end(); sitr++) { fs::ifstream fin(*sitr); @@ -142,8 +144,7 @@ namespace gr { fin.close(); } - // Convert the string into a map - _convert_to_map(config); + return config; } void @@ -188,6 +189,17 @@ namespace gr { } } + void + prefs::add_config_file(const std::string &configfile) + { + std::vector<std::string> filenames; + filenames.push_back(configfile); + + std::string config = _read_files(filenames); + _convert_to_map(config); + } + + std::string prefs::to_string() { diff --git a/gnuradio-runtime/swig/prefs.i b/gnuradio-runtime/swig/prefs.i index ac5fab7adc..4774146b69 100644 --- a/gnuradio-runtime/swig/prefs.i +++ b/gnuradio-runtime/swig/prefs.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2006,2013 Free Software Foundation, Inc. + * Copyright 2006,2015 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -25,6 +25,8 @@ class gr::prefs public: static gr::prefs *singleton(); + void add_config_file(const std::string &configfile); + virtual ~prefs(); std::string to_string(); |