GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
prefs.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2013,2015 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_GR_PREFS_H
24 #define INCLUDED_GR_PREFS_H
25 
26 #include <gnuradio/api.h>
27 #include <gnuradio/thread/thread.h>
28 #include <map>
29 #include <string>
30 
31 namespace gr {
32 
33 typedef std::map<std::string, std::map<std::string, std::string>> config_map_t;
34 typedef std::map<std::string, std::map<std::string, std::string>>::iterator
36 typedef std::map<std::string, std::string> config_map_elem_t;
37 typedef std::map<std::string, std::string>::iterator config_map_elem_itr;
38 
39 /*!
40  * \brief Base class for representing user preferences a la windows INI files.
41  * \ingroup misc
42  *
43  * The real implementation is in Python, and is accessible from C++
44  * via the magic of SWIG directors.
45  */
47 {
48 public:
49  static prefs* singleton();
50 
51  /*!
52  * \brief Creates an object to read preference files.
53  *
54  * \details
55  *
56  * If no file name is given (empty arg list or ""), this opens up
57  * the standard GNU Radio configuration files in
58  * prefix/etc/gnuradio/conf.d as well as ~/.gnuradio/config.conf.
59  *
60  * Only access this through the singleton defined here:
61  * \code
62  * prefs *p = prefs::singleton();
63  * \endcode
64  */
65  prefs();
66 
67  virtual ~prefs();
68 
69  /*!
70  * If specifying a file name, this opens that specific
71  * configuration file of the standard form containing sections and
72  * key-value pairs:
73  *
74  * \code
75  * [SectionName]
76  * key0 = value0
77  * key1 = value1
78  * \endcode
79  */
80  void add_config_file(const std::string& configfile);
81 
82  /*!
83  * \brief Returns the configuration options as a string.
84  */
85  std::string to_string();
86 
87  /*!
88  * \brief Saves the configuration settings to
89  * ${HOME}/.gnuradio/config.conf.
90  *
91  * WARNING: this will overwrite your current config.conf file.
92  */
93  void save();
94 
95  /*!
96  * \brief Does \p section exist?
97  */
98  virtual bool has_section(const std::string& section);
99 
100  /*!
101  * \brief Does \p option exist?
102  */
103  virtual bool has_option(const std::string& section, const std::string& option);
104 
105  /*!
106  * \brief If option exists return associated value; else
107  * default_val.
108  */
109  virtual const std::string get_string(const std::string& section,
110  const std::string& option,
111  const std::string& default_val);
112 
113  /*!
114  * \brief Set or add a string \p option to \p section with value
115  * \p val.
116  */
117  virtual void set_string(const std::string& section,
118  const std::string& option,
119  const std::string& val);
120 
121  /*!
122  * \brief If option exists and value can be converted to bool,
123  * return it; else default_val.
124  */
125  virtual bool
126  get_bool(const std::string& section, const std::string& option, bool default_val);
127 
128  /*!
129  * \brief Set or add a bool \p option to \p section with value \p val.
130  */
131  virtual void
132  set_bool(const std::string& section, const std::string& option, bool val);
133 
134  /*!
135  * \brief If option exists and value can be converted to long,
136  * return it; else default_val.
137  */
138  virtual long
139  get_long(const std::string& section, const std::string& option, long default_val);
140 
141  /*!
142  * \brief Set or add a long \p option to \p section with value \p val.
143  */
144  virtual void
145  set_long(const std::string& section, const std::string& option, long val);
146 
147  /*!
148  * \brief If option exists and value can be converted to double,
149  * return it; else default_val.
150  */
151  virtual double
152  get_double(const std::string& section, const std::string& option, double default_val);
153 
154  /*!
155  * \brief Set or add a double \p option to \p section with value \p val.
156  */
157  virtual void
158  set_double(const std::string& section, const std::string& option, double val);
159 
160 protected:
161  virtual std::vector<std::string> _sys_prefs_filenames();
162  virtual void _read_files(const std::vector<std::string>& filenames);
163  virtual char* option_to_env(std::string section, std::string option);
164 
165 private:
166  gr::thread::mutex d_mutex;
167  config_map_t d_config_map;
168 };
169 
170 } /* namespace gr */
171 
172 #endif /* INCLUDED_GR_PREFS_H */
std::map< std::string, std::string >::iterator config_map_elem_itr
Definition: prefs.h:37
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
Base class for representing user preferences a la windows INI files.The real implementation is in Pyt...
Definition: prefs.h:46
std::map< std::string, std::map< std::string, std::string > > config_map_t
Definition: prefs.h:33
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
std::map< std::string, std::map< std::string, std::string > >::iterator config_map_itr
Definition: prefs.h:35
boost::mutex mutex
Definition: thread.h:48
std::map< std::string, std::string > config_map_elem_t
Definition: prefs.h:36