OpenZWave Library  1.6.896
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 
135  bool Lock();
136 
145  bool AddOptionBool(string const& _name, bool const _default);
146 
155  bool AddOptionInt(string const& _name, int32 const _default);
156 
168  bool AddOptionString(string const& _name, string const& _default, bool const _append);
169 
178  bool GetOptionAsBool(string const& _name, bool* o_value);
179 
188  bool GetOptionAsInt(string const& _name, int32* o_value);
189 
198  bool GetOptionAsString(string const& _name, string* o_value);
199 
207  OptionType GetOptionType(string const& _name);
208 
214  bool AreLocked() const
215  {
216  return m_locked;
217  }
218 
219  private:
220  class Option
221  {
222  friend class Options;
223 
224  public:
225  Option(string const& _name) :
226  m_name(_name), m_append(false)
227  {
228  }
229  bool SetValueFromString(string const& _value);
230 
231  Options::OptionType m_type;
232  string m_name;
233  bool m_valueBool;
234  int32 m_valueInt;
235  string m_valueString;
236  bool m_append;
237  };
238 
239  Options(string const& _configPath, string const& _userPath, string const& _commandLine); // Constructor, to be called only via the static Create method.
240  ~Options(); // Destructor, to be called only via the static Destroy method.
241 
242  bool ParseOptionsString(string const& _options); // Parse a string containing program options, such as a command line.
243  bool ParseOptionsXML(string const& _filename); // Parse an XML file containing program options.
244  Option* AddOption(string const& _name); // check lock and create (or open existing) option
245  Option* Find(string const& _name);
246 
248  map<string, Option*> m_options; // Map of option names to values.
250  string m_xml; // Path to XML options file.
251  string m_commandLine; // String containing command line options.
252  string m_SystemPath;
253  string m_LocalPath;
254  bool m_locked; // If true, the options are final and AddOption can no longer be called.
255  static Options* s_instance;
256  };
257 } // namespace OpenZWave
258 
259 #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
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:214
Definition: Options.h:73
OptionType
Definition: Options.h:69