OpenZWave Library  1.6.784
Options.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Options.h
4 //
5 // Program options read from XML files or the command line.
6 //
7 // Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8 //
9 // SOFTWARE NOTICE AND LICENSE
10 //
11 // This file is part of OpenZWave.
12 //
13 // OpenZWave is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published
15 // by the Free Software Foundation, either version 3 of the License,
16 // or (at your option) any later version.
17 //
18 // OpenZWave is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #ifndef _Options_H
29 #define _Options_H
30 
31 #include <string>
32 #include <cstring>
33 #include <map>
34 
35 #include "Defs.h"
36 
37 namespace OpenZWave
38 {
67  {
68  public:
70  {
71  OptionType_Invalid = 0,
74  OptionType_String
75  };
76 
106  static Options* Create(string const& _configPath, string const& _userPath, string const& _commandLine);
107 
118  static bool Destroy();
119 
125  static Options* Get()
126  {
127  return s_instance;
128  }
129 
138  bool Lock();
139 
148  bool AddOptionBool(string const& _name, bool const _default);
149 
158  bool AddOptionInt(string const& _name, int32 const _default);
159 
171  bool AddOptionString(string const& _name, string const& _default, bool const _append);
172 
181  bool GetOptionAsBool(string const& _name, bool* o_value);
182 
191  bool GetOptionAsInt(string const& _name, int32* o_value);
192 
201  bool GetOptionAsString(string const& _name, string* o_value);
202 
210  OptionType GetOptionType(string const& _name);
211 
217  bool AreLocked() const
218  {
219  return m_locked;
220  }
221 
222  private:
223  class Option
224  {
225  friend class Options;
226 
227  public:
228  Option(string const& _name) :
229  m_name(_name), m_append(false)
230  {
231  }
232  bool SetValueFromString(string const& _value);
233 
234  Options::OptionType m_type;
235  string m_name;
236  bool m_valueBool;
237  int32 m_valueInt;
238  string m_valueString;
239  bool m_append;
240  };
241 
242  Options(string const& _configPath, string const& _userPath, string const& _commandLine); // Constructor, to be called only via the static Create method.
243  ~Options(); // Destructor, to be called only via the static Destroy method.
244 
245  bool ParseOptionsString(string const& _options); // Parse a string containing program options, such as a command line.
246  bool ParseOptionsXML(string const& _filename); // Parse an XML file containing program options.
247  Option* AddOption(string const& _name); // check lock and create (or open existing) option
248  Option* Find(string const& _name);
249 
251  map<string, Option*> m_options; // Map of option names to values.
253  string m_xml; // Path to XML options file.
254  string m_commandLine; // String containing command line options.
255  string m_SystemPath;
256  string m_LocalPath;
257  bool m_locked; // If true, the options are final and AddOption can no longer be called.
258  static Options* s_instance;
259  };
260 } // namespace OpenZWave
261 
262 #endif // _Options_H
Definition: Bitfield.cpp:30
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:53
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:52
Definition: Options.h:72
static Options * Get()
Definition: Options.h:125
Manages library options read from XML files or the command line.
Definition: Options.h:66
signed int int32
Definition: Defs.h:91
bool AreLocked() const
Definition: Options.h:217
Definition: Options.h:73
OptionType
Definition: Options.h:69