GNU Radio Manual and C++ API Reference  3.7.13.4
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 <string>
28 #include <map>
29 #include <gnuradio/thread/thread.h>
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 config_map_itr;
35  typedef std::map<std::string, std::string> config_map_elem_t;
36  typedef std::map<std::string, std::string>::iterator config_map_elem_itr;
37 
38  /*!
39  * \brief Base class for representing user preferences a la windows INI files.
40  * \ingroup misc
41  *
42  * The real implementation is in Python, and is accessible from C++
43  * via the magic of SWIG directors.
44  */
46  {
47  public:
48  static prefs *singleton();
49 
50  /*!
51  * \brief Creates an object to read preference files.
52  *
53  * \details
54  *
55  * If no file name is given (empty arg list or ""), this opens up
56  * the standard GNU Radio configuration files in
57  * prefix/etc/gnuradio/conf.d as well as ~/.gnuradio/config.conf.
58  *
59  * Only access this through the singleton defined here:
60  * \code
61  * prefs *p = prefs::singleton();
62  * \endcode
63  */
64  prefs();
65 
66  virtual ~prefs();
67 
68  /*!
69  * If specifying a file name, this opens that specific
70  * configuration file of the standard form containing sections and
71  * key-value pairs:
72  *
73  * \code
74  * [SectionName]
75  * key0 = value0
76  * key1 = value1
77  * \endcode
78  */
79  void add_config_file(const std::string &configfile);
80 
81  /*!
82  * \brief Returns the configuration options as a string.
83  */
84  std::string to_string();
85 
86  /*!
87  * \brief Saves the configuration settings to
88  * ${HOME}/.gnuradio/config.conf.
89  *
90  * WARNING: this will overwrite your current config.conf file.
91  */
92  void save();
93 
94  /*!
95  * \brief Does \p section exist?
96  */
97  virtual bool has_section(const std::string &section);
98 
99  /*!
100  * \brief Does \p option exist?
101  */
102  virtual bool has_option(const std::string &section,
103  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 get_bool(const std::string &section,
126  const std::string &option,
127  bool default_val);
128 
129  /*!
130  * \brief Set or add a bool \p option to \p section with value \p val.
131  */
132  virtual void set_bool(const std::string &section,
133  const std::string &option,
134  bool val);
135 
136  /*!
137  * \brief If option exists and value can be converted to long,
138  * return it; else default_val.
139  */
140  virtual long get_long(const std::string &section,
141  const std::string &option,
142  long default_val);
143 
144  /*!
145  * \brief Set or add a long \p option to \p section with value \p val.
146  */
147  virtual void set_long(const std::string &section,
148  const std::string &option,
149  long val);
150 
151  /*!
152  * \brief If option exists and value can be converted to double,
153  * return it; else default_val.
154  */
155  virtual double get_double(const std::string &section,
156  const std::string &option,
157  double default_val);
158 
159  /*!
160  * \brief Set or add a double \p option to \p section with value \p val.
161  */
162  virtual void set_double(const std::string &section,
163  const std::string &option,
164  double val);
165 
166  protected:
167  virtual std::vector<std::string> _sys_prefs_filenames();
168  virtual void _read_files(const std::vector<std::string> &filenames);
169  virtual char * option_to_env(std::string section, std::string option);
170 
171  private:
172  gr::thread::mutex d_mutex;
173  config_map_t d_config_map;
174  };
175 
176 } /* namespace gr */
177 
178 #endif /* INCLUDED_GR_PREFS_H */
std::map< std::string, std::map< std::string, std::string > >::iterator config_map_itr
Definition: prefs.h:34
std::map< std::string, std::string >::iterator config_map_elem_itr
Definition: prefs.h:36
#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:45
Include this header to use the message passing features.
Definition: logger.h:695
boost::mutex mutex
Definition: thread.h:48
std::map< std::string, std::string > config_map_elem_t
Definition: prefs.h:35
std::map< std::string, std::map< std::string, std::string > > config_map_t
Definition: prefs.h:33