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