GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
prefs.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2013 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 accessable from C++
43  * via the magic of SWIG directors.
44  */
46  {
47  public:
48  static prefs *singleton();
49 
50  prefs();
51  virtual ~prefs();
52 
53  /*!
54  * \brief Returns the configuration options as a string.
55  */
56  std::string to_string();
57 
58  /*!
59  * \brief Saves the configuration settings to
60  * ${HOME}/.gnuradio/config.conf.
61  *
62  * WARNING: this will overwrite your current config.conf file.
63  */
64  void save();
65 
66  /*!
67  * \brief Does \p section exist?
68  */
69  virtual bool has_section(const std::string &section);
70 
71  /*!
72  * \brief Does \p option exist?
73  */
74  virtual bool has_option(const std::string &section,
75  const std::string &option);
76 
77  /*!
78  * \brief If option exists return associated value; else
79  * default_val.
80  */
81  virtual const std::string get_string(const std::string &section,
82  const std::string &option,
83  const std::string &default_val);
84 
85  /*!
86  * \brief Set or add a string \p option to \p section with value
87  * \p val.
88  */
89  virtual void set_string(const std::string &section,
90  const std::string &option,
91  const std::string &val);
92 
93  /*!
94  * \brief If option exists and value can be converted to bool,
95  * return it; else default_val.
96  */
97  virtual bool get_bool(const std::string &section,
98  const std::string &option,
99  bool default_val);
100 
101  /*!
102  * \brief Set or add a bool \p option to \p section with value \p val.
103  */
104  virtual void set_bool(const std::string &section,
105  const std::string &option,
106  bool val);
107 
108  /*!
109  * \brief If option exists and value can be converted to long,
110  * return it; else default_val.
111  */
112  virtual long get_long(const std::string &section,
113  const std::string &option,
114  long default_val);
115 
116  /*!
117  * \brief Set or add a long \p option to \p section with value \p val.
118  */
119  virtual void set_long(const std::string &section,
120  const std::string &option,
121  long val);
122 
123  /*!
124  * \brief If option exists and value can be converted to double,
125  * return it; else default_val.
126  */
127  virtual double get_double(const std::string &section,
128  const std::string &option,
129  double default_val);
130 
131  /*!
132  * \brief Set or add a double \p option to \p section with value \p val.
133  */
134  virtual void set_double(const std::string &section,
135  const std::string &option,
136  double val);
137 
138  protected:
139  virtual std::vector<std::string> _sys_prefs_filenames();
140  virtual void _read_files();
141  virtual void _convert_to_map(const std::string &conf);
142  virtual char * option_to_env(std::string section, std::string option);
143 
144  private:
145  gr::thread::mutex d_mutex;
146  config_map_t d_config_map;
147  };
148 
149 } /* namespace gr */
150 
151 #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
boost::mutex mutex
Definition: thread.h:46
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