OpenZWave Library: Options.h Source File

| OpenZWave Library 1.6.0

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 {
66 class OPENZWAVE_EXPORT Options
67 {
68 public:
69 enum OptionType
70 {
71 OptionType_Invalid = 0,
72 OptionType_Bool,
73 OptionType_Int,
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(){ return s_instance; }
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{ return m_locked; }
215
216
217 private:
218 class Option
219 {
220 friend class Options;
221
222 public:
223 Option( string const& _name ): m_name( _name ), m_append( false ){}
224 bool SetValueFromString( string const& _value );
225
226 Options::OptionType m_type;
227 string m_name;
228 bool m_valueBool;
229 int32 m_valueInt;
230 string m_valueString;
231 bool m_append;
232 };
233
234 Options( string const& _configPath, string const& _userPath, string const& _commandLine ); // Constructor, to be called only via the static Create method.
235 ~Options(); // Destructor, to be called only via the static Destroy method.
236
237 bool ParseOptionsString( string const& _options ); // Parse a string containing program options, such as a command line.
238 bool ParseOptionsXML( string const& _filename ); // Parse an XML file containing program options.
239 Option* AddOption( string const& _name ); // check lock and create (or open existing) option
240 Option* Find( string const& _name );
241
242 OPENZWAVE_EXPORT_WARNINGS_OFF
243 map<string,Option*> m_options; // Map of option names to values.
244 OPENZWAVE_EXPORT_WARNINGS_ON
245 string m_xml; // Path to XML options file.
246 string m_commandLine; // String containing command line options.
247 string m_SystemPath;
248 string m_LocalPath;
249 bool m_locked; // If true, the options are final and AddOption can no longer be called.
250 static Options* s_instance;
251 };
252 } // namespace OpenZWave
253
254 #endif // _Options_H
OpenZWave
Definition: Bitfield.h:34
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
OPENZWAVE_EXPORT_WARNINGS_ON
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:53
OpenZWave::Lock
Implements COMMAND_CLASS_LOCK (0x76), a Z-Wave device command class.
Definition: Lock.h:40
OPENZWAVE_EXPORT_WARNINGS_OFF
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:52
Defs.h
OpenZWave::Options::OptionType_Bool
Definition: Options.h:72
OpenZWave::Options::Get
static Options * Get()
Definition: Options.h:125
OpenZWave::Options
Manages library options read from XML files or the command line.
Definition: Options.h:66
int32
signed int int32
Definition: Defs.h:94
OpenZWave::Options::AreLocked
bool AreLocked() const
Definition: Options.h:214
OpenZWave::Options::OptionType_Int
Definition: Options.h:73
OpenZWave::Options::OptionType
OptionType
Definition: Options.h:69