Options.h
Go to the documentation of this file.
//-----------------------------------------------------------------------------
//
// Options.h
//
// Program options read from XML files or the command line.
//
// Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
//
// SOFTWARE NOTICE AND LICENSE
//
// This file is part of OpenZWave.
//
// OpenZWave is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// OpenZWave is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
#ifndef _Options_H
#define _Options_H
#include <string>
#include <cstring>
#include <map>
#include "Defs.h"
namespace OpenZWave
{
class OPENZWAVE_EXPORT Options
{
public:
enum OptionType
{
OptionType_Invalid = 0,
OptionType_Bool,
OptionType_Int,
OptionType_String
};
static Options* Create( string const& _configPath, string const& _userPath, string const& _commandLine );
static bool Destroy();
static Options* Get(){ return s_instance; }
bool Lock();
bool AddOptionBool( string const& _name, bool const _default );
bool AddOptionInt( string const& _name, int32 const _default );
bool AddOptionString( string const& _name, string const& _default, bool const _append );
bool GetOptionAsBool( string const& _name, bool* o_value );
bool GetOptionAsInt( string const& _name, int32* o_value );
bool GetOptionAsString( string const& _name, string* o_value );
OptionType GetOptionType( string const& _name );
bool AreLocked()const{ return m_locked; }
private:
class Option
{
friend class Options;
public:
Option( string const& _name ): m_name( _name ), m_append( false ){}
bool SetValueFromString( string const& _value );
Options::OptionType m_type;
string m_name;
bool m_valueBool;
int32 m_valueInt;
string m_valueString;
bool m_append;
};
Options( string const& _configPath, string const& _userPath, string const& _commandLine ); // Constructor, to be called only via the static Create method.
~Options(); // Destructor, to be called only via the static Destroy method.
bool ParseOptionsString( string const& _options ); // Parse a string containing program options, such as a command line.
bool ParseOptionsXML( string const& _filename ); // Parse an XML file containing program options.
Option* AddOption( string const& _name ); // check lock and create (or open existing) option
Option* Find( string const& _name );
OPENZWAVE_EXPORT_WARNINGS_OFF
map<string,Option*> m_options; // Map of option names to values.
OPENZWAVE_EXPORT_WARNINGS_ON
string m_xml; // Path to XML options file.
string m_commandLine; // String containing command line options.
string m_SystemPath;
string m_LocalPath;
bool m_locked; // If true, the options are final and AddOption can no longer be called.
static Options* s_instance;
};
} // namespace OpenZWave
#endif // _Options_H
OpenZWave
Definition: Bitfield.h:34
OPENZWAVE_EXPORT
#define OPENZWAVE_EXPORT
Definition: Defs.h:52
OPENZWAVE_EXPORT_WARNINGS_ON
#define OPENZWAVE_EXPORT_WARNINGS_ON
Definition: Defs.h:54
OpenZWave::Lock
Implements COMMAND_CLASS_LOCK (0x76), a Z-Wave device command class.
Definition: Lock.h:39
OPENZWAVE_EXPORT_WARNINGS_OFF
#define OPENZWAVE_EXPORT_WARNINGS_OFF
Definition: Defs.h:53
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:79
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