OpenZWave Library 1.2
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
37namespace 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(){ 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
243 map<string,Option*> m_options; // Map of option names to values.
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
signed int int32
Definition: Defs.h:68
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:53
#define OPENZWAVE_EXPORT
Definition: Defs.h:51
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:52
Implements COMMAND_CLASS_LOCK (0x76), a Z-Wave device command class.
Definition: Lock.h:40
Manages library options read from XML files or the command line.
Definition: Options.h:67
bool AreLocked() const
Definition: Options.h:214
static Options * Get()
Definition: Options.h:125
OptionType
Definition: Options.h:70
@ OptionType_Int
Definition: Options.h:73
@ OptionType_Bool
Definition: Options.h:72
Definition: Bitfield.h:35