mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-01 21:13:10 +01:00
change EOL to 'native'
This commit is contained in:
@@ -1,320 +1,320 @@
|
||||
//
|
||||
// AbstractConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/AbstractConfiguration.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: AbstractConfiguration
|
||||
//
|
||||
// Definition of the AbstractConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_AbstractConfiguration_INCLUDED
|
||||
#define Util_AbstractConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API AbstractConfiguration: public Poco::RefCountedObject
|
||||
/// AbstractConfiguration is an abstract base class for different
|
||||
/// kinds of configuration data, such as INI files, property files,
|
||||
/// XML configuration files or the Windows Registry.
|
||||
///
|
||||
/// Configuration property keys have a hierarchical format, consisting
|
||||
/// of names separated by periods. The exact interpretation of key names
|
||||
/// is up to the actual subclass implementation of AbstractConfiguration.
|
||||
/// Keys are case sensitive.
|
||||
///
|
||||
/// All public methods are synchronized, so the class is safe for multithreaded use.
|
||||
/// AbstractConfiguration implements reference counting based garbage collection.
|
||||
///
|
||||
/// Subclasses must override the getRaw(), setRaw() and enumerate() methods.
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::string> Keys;
|
||||
|
||||
class KeyValue
|
||||
/// A key-value pair, used as event argument.
|
||||
{
|
||||
public:
|
||||
KeyValue(const std::string& key, std::string& value):
|
||||
_key(key),
|
||||
_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& key() const
|
||||
{
|
||||
return _key;
|
||||
}
|
||||
|
||||
const std::string& value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
std::string& value()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string& _key;
|
||||
std::string& _value;
|
||||
};
|
||||
|
||||
Poco::BasicEvent<KeyValue> propertyChanging;
|
||||
/// Fired before a property value is changed or
|
||||
/// a new property is created.
|
||||
///
|
||||
/// Can be used to check or fix a property value,
|
||||
/// or to cancel the change by throwing an exception.
|
||||
///
|
||||
/// The event delegate can use one of the get...() functions
|
||||
/// to obtain the current property value.
|
||||
|
||||
Poco::BasicEvent<const KeyValue> propertyChanged;
|
||||
/// Fired after a property value has been changed
|
||||
/// or a property has been created.
|
||||
|
||||
Poco::BasicEvent<const std::string> propertyRemoving;
|
||||
/// Fired before a property is removed by a
|
||||
/// call to remove().
|
||||
///
|
||||
/// Note: This will even be fired if the key
|
||||
/// does not exist and the remove operation will
|
||||
/// fail with an exception.
|
||||
|
||||
Poco::BasicEvent<const std::string> propertyRemoved;
|
||||
/// Fired after a property has been removed by
|
||||
/// a call to remove().
|
||||
|
||||
AbstractConfiguration();
|
||||
/// Creates the AbstractConfiguration.
|
||||
|
||||
bool hasProperty(const std::string& key) const;
|
||||
/// Returns true iff the property with the given key exists.
|
||||
|
||||
bool hasOption(const std::string& key) const;
|
||||
/// Returns true iff the property with the given key exists.
|
||||
///
|
||||
/// Same as hasProperty().
|
||||
|
||||
bool has(const std::string& key) const;
|
||||
/// Returns true iff the property with the given key exists.
|
||||
///
|
||||
/// Same as hasProperty().
|
||||
|
||||
std::string getString(const std::string& key) const;
|
||||
/// Returns the string value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
std::string getString(const std::string& key, const std::string& defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's string value,
|
||||
/// otherwise returns the given default value.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
std::string getRawString(const std::string& key) const;
|
||||
/// Returns the raw string value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// References to other properties are not expanded.
|
||||
|
||||
std::string getRawString(const std::string& key, const std::string& defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's raw string value,
|
||||
/// otherwise returns the given default value.
|
||||
/// References to other properties are not expanded.
|
||||
|
||||
int getInt(const std::string& key) const;
|
||||
/// Returns the int value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to an int.
|
||||
/// Numbers starting with 0x are treated as hexadecimal.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
int getInt(const std::string& key, int defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's int value,
|
||||
/// otherwise returns the given default value.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to an int.
|
||||
/// Numbers starting with 0x are treated as hexadecimal.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
double getDouble(const std::string& key) const;
|
||||
/// Returns the double value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to a double.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
double getDouble(const std::string& key, double defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's double value,
|
||||
/// otherwise returns the given default value.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to an double.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
bool getBool(const std::string& key) const;
|
||||
/// Returns the boolean value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to a boolean.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
bool getBool(const std::string& key, bool defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's boolean value,
|
||||
/// otherwise returns the given default value.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to a boolean.
|
||||
/// The following string values can be converted into a boolean:
|
||||
/// - numerical values: non zero becomes true, zero becomes false
|
||||
/// - strings: true, yes, on become true, false, no, off become false
|
||||
/// Case does not matter.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
void setString(const std::string& key, const std::string& value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
void setInt(const std::string& key, int value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
void setDouble(const std::string& key, double value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
void setBool(const std::string& key, bool value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
void keys(Keys& range) const;
|
||||
/// Returns in range the names of all keys at root level.
|
||||
|
||||
void keys(const std::string& key, Keys& range) const;
|
||||
/// Returns in range the names of all subkeys under the given key.
|
||||
/// If an empty key is passed, all root level keys are returned.
|
||||
|
||||
const AbstractConfiguration* createView(const std::string& prefix) const;
|
||||
/// Creates a non-mutable view (see ConfigurationView) into the configuration.
|
||||
|
||||
AbstractConfiguration* createView(const std::string& prefix);
|
||||
/// Creates a view (see ConfigurationView) into the configuration.
|
||||
|
||||
std::string expand(const std::string& value) const;
|
||||
/// Replaces all occurences of ${<property>} in value with the
|
||||
/// value of the <property>. If <property> does not exist,
|
||||
/// nothing is changed.
|
||||
///
|
||||
/// If a circular property reference is detected, a
|
||||
/// CircularReferenceException will be thrown.
|
||||
|
||||
void remove(const std::string& key);
|
||||
/// Removes the property with the given key.
|
||||
///
|
||||
/// Does nothing if the key does not exist.
|
||||
|
||||
void enableEvents(bool enable = true);
|
||||
/// Enables (or disables) events.
|
||||
|
||||
bool eventsEnabled() const;
|
||||
/// Returns true iff events are enabled.
|
||||
|
||||
protected:
|
||||
virtual bool getRaw(const std::string& key, std::string& value) const = 0;
|
||||
/// If the property with the given key exists, stores the property's value
|
||||
/// in value and returns true. Otherwise, returns false.
|
||||
///
|
||||
/// Must be overridden by subclasses.
|
||||
|
||||
virtual void setRaw(const std::string& key, const std::string& value) = 0;
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
///
|
||||
/// Must be overridden by subclasses.
|
||||
|
||||
virtual void enumerate(const std::string& key, Keys& range) const = 0;
|
||||
/// Returns in range the names of all subkeys under the given key.
|
||||
/// If an empty key is passed, all root level keys are returned.
|
||||
|
||||
virtual void removeRaw(const std::string& key);
|
||||
/// Removes the property with the given key.
|
||||
///
|
||||
/// Does nothing if the key does not exist.
|
||||
///
|
||||
/// Should be overridden by subclasses; the default
|
||||
/// implementation throws a Poco::NotImplementedException.
|
||||
|
||||
static int parseInt(const std::string& value);
|
||||
static bool parseBool(const std::string& value);
|
||||
void setRawWithEvent(const std::string& key, std::string value);
|
||||
|
||||
virtual ~AbstractConfiguration();
|
||||
|
||||
private:
|
||||
std::string internalExpand(const std::string& value) const;
|
||||
std::string uncheckedExpand(const std::string& value) const;
|
||||
|
||||
AbstractConfiguration(const AbstractConfiguration&);
|
||||
AbstractConfiguration& operator = (const AbstractConfiguration&);
|
||||
|
||||
mutable int _depth;
|
||||
bool _eventsEnabled;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
|
||||
friend class LayeredConfiguration;
|
||||
friend class ConfigurationView;
|
||||
friend class ConfigurationMapper;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_AbstractConfiguration_INCLUDED
|
||||
//
|
||||
// AbstractConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/AbstractConfiguration.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: AbstractConfiguration
|
||||
//
|
||||
// Definition of the AbstractConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_AbstractConfiguration_INCLUDED
|
||||
#define Util_AbstractConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API AbstractConfiguration: public Poco::RefCountedObject
|
||||
/// AbstractConfiguration is an abstract base class for different
|
||||
/// kinds of configuration data, such as INI files, property files,
|
||||
/// XML configuration files or the Windows Registry.
|
||||
///
|
||||
/// Configuration property keys have a hierarchical format, consisting
|
||||
/// of names separated by periods. The exact interpretation of key names
|
||||
/// is up to the actual subclass implementation of AbstractConfiguration.
|
||||
/// Keys are case sensitive.
|
||||
///
|
||||
/// All public methods are synchronized, so the class is safe for multithreaded use.
|
||||
/// AbstractConfiguration implements reference counting based garbage collection.
|
||||
///
|
||||
/// Subclasses must override the getRaw(), setRaw() and enumerate() methods.
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::string> Keys;
|
||||
|
||||
class KeyValue
|
||||
/// A key-value pair, used as event argument.
|
||||
{
|
||||
public:
|
||||
KeyValue(const std::string& key, std::string& value):
|
||||
_key(key),
|
||||
_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string& key() const
|
||||
{
|
||||
return _key;
|
||||
}
|
||||
|
||||
const std::string& value() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
std::string& value()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
private:
|
||||
const std::string& _key;
|
||||
std::string& _value;
|
||||
};
|
||||
|
||||
Poco::BasicEvent<KeyValue> propertyChanging;
|
||||
/// Fired before a property value is changed or
|
||||
/// a new property is created.
|
||||
///
|
||||
/// Can be used to check or fix a property value,
|
||||
/// or to cancel the change by throwing an exception.
|
||||
///
|
||||
/// The event delegate can use one of the get...() functions
|
||||
/// to obtain the current property value.
|
||||
|
||||
Poco::BasicEvent<const KeyValue> propertyChanged;
|
||||
/// Fired after a property value has been changed
|
||||
/// or a property has been created.
|
||||
|
||||
Poco::BasicEvent<const std::string> propertyRemoving;
|
||||
/// Fired before a property is removed by a
|
||||
/// call to remove().
|
||||
///
|
||||
/// Note: This will even be fired if the key
|
||||
/// does not exist and the remove operation will
|
||||
/// fail with an exception.
|
||||
|
||||
Poco::BasicEvent<const std::string> propertyRemoved;
|
||||
/// Fired after a property has been removed by
|
||||
/// a call to remove().
|
||||
|
||||
AbstractConfiguration();
|
||||
/// Creates the AbstractConfiguration.
|
||||
|
||||
bool hasProperty(const std::string& key) const;
|
||||
/// Returns true iff the property with the given key exists.
|
||||
|
||||
bool hasOption(const std::string& key) const;
|
||||
/// Returns true iff the property with the given key exists.
|
||||
///
|
||||
/// Same as hasProperty().
|
||||
|
||||
bool has(const std::string& key) const;
|
||||
/// Returns true iff the property with the given key exists.
|
||||
///
|
||||
/// Same as hasProperty().
|
||||
|
||||
std::string getString(const std::string& key) const;
|
||||
/// Returns the string value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
std::string getString(const std::string& key, const std::string& defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's string value,
|
||||
/// otherwise returns the given default value.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
std::string getRawString(const std::string& key) const;
|
||||
/// Returns the raw string value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// References to other properties are not expanded.
|
||||
|
||||
std::string getRawString(const std::string& key, const std::string& defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's raw string value,
|
||||
/// otherwise returns the given default value.
|
||||
/// References to other properties are not expanded.
|
||||
|
||||
int getInt(const std::string& key) const;
|
||||
/// Returns the int value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to an int.
|
||||
/// Numbers starting with 0x are treated as hexadecimal.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
int getInt(const std::string& key, int defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's int value,
|
||||
/// otherwise returns the given default value.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to an int.
|
||||
/// Numbers starting with 0x are treated as hexadecimal.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
double getDouble(const std::string& key) const;
|
||||
/// Returns the double value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to a double.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
double getDouble(const std::string& key, double defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's double value,
|
||||
/// otherwise returns the given default value.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to an double.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
bool getBool(const std::string& key) const;
|
||||
/// Returns the boolean value of the property with the given name.
|
||||
/// Throws a NotFoundException if the key does not exist.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to a boolean.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
bool getBool(const std::string& key, bool defaultValue) const;
|
||||
/// If a property with the given key exists, returns the property's boolean value,
|
||||
/// otherwise returns the given default value.
|
||||
/// Throws a SyntaxException if the property can not be converted
|
||||
/// to a boolean.
|
||||
/// The following string values can be converted into a boolean:
|
||||
/// - numerical values: non zero becomes true, zero becomes false
|
||||
/// - strings: true, yes, on become true, false, no, off become false
|
||||
/// Case does not matter.
|
||||
/// If the value contains references to other properties (${<property>}), these
|
||||
/// are expanded.
|
||||
|
||||
void setString(const std::string& key, const std::string& value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
void setInt(const std::string& key, int value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
void setDouble(const std::string& key, double value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
void setBool(const std::string& key, bool value);
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
|
||||
void keys(Keys& range) const;
|
||||
/// Returns in range the names of all keys at root level.
|
||||
|
||||
void keys(const std::string& key, Keys& range) const;
|
||||
/// Returns in range the names of all subkeys under the given key.
|
||||
/// If an empty key is passed, all root level keys are returned.
|
||||
|
||||
const AbstractConfiguration* createView(const std::string& prefix) const;
|
||||
/// Creates a non-mutable view (see ConfigurationView) into the configuration.
|
||||
|
||||
AbstractConfiguration* createView(const std::string& prefix);
|
||||
/// Creates a view (see ConfigurationView) into the configuration.
|
||||
|
||||
std::string expand(const std::string& value) const;
|
||||
/// Replaces all occurences of ${<property>} in value with the
|
||||
/// value of the <property>. If <property> does not exist,
|
||||
/// nothing is changed.
|
||||
///
|
||||
/// If a circular property reference is detected, a
|
||||
/// CircularReferenceException will be thrown.
|
||||
|
||||
void remove(const std::string& key);
|
||||
/// Removes the property with the given key.
|
||||
///
|
||||
/// Does nothing if the key does not exist.
|
||||
|
||||
void enableEvents(bool enable = true);
|
||||
/// Enables (or disables) events.
|
||||
|
||||
bool eventsEnabled() const;
|
||||
/// Returns true iff events are enabled.
|
||||
|
||||
protected:
|
||||
virtual bool getRaw(const std::string& key, std::string& value) const = 0;
|
||||
/// If the property with the given key exists, stores the property's value
|
||||
/// in value and returns true. Otherwise, returns false.
|
||||
///
|
||||
/// Must be overridden by subclasses.
|
||||
|
||||
virtual void setRaw(const std::string& key, const std::string& value) = 0;
|
||||
/// Sets the property with the given key to the given value.
|
||||
/// An already existing value for the key is overwritten.
|
||||
///
|
||||
/// Must be overridden by subclasses.
|
||||
|
||||
virtual void enumerate(const std::string& key, Keys& range) const = 0;
|
||||
/// Returns in range the names of all subkeys under the given key.
|
||||
/// If an empty key is passed, all root level keys are returned.
|
||||
|
||||
virtual void removeRaw(const std::string& key);
|
||||
/// Removes the property with the given key.
|
||||
///
|
||||
/// Does nothing if the key does not exist.
|
||||
///
|
||||
/// Should be overridden by subclasses; the default
|
||||
/// implementation throws a Poco::NotImplementedException.
|
||||
|
||||
static int parseInt(const std::string& value);
|
||||
static bool parseBool(const std::string& value);
|
||||
void setRawWithEvent(const std::string& key, std::string value);
|
||||
|
||||
virtual ~AbstractConfiguration();
|
||||
|
||||
private:
|
||||
std::string internalExpand(const std::string& value) const;
|
||||
std::string uncheckedExpand(const std::string& value) const;
|
||||
|
||||
AbstractConfiguration(const AbstractConfiguration&);
|
||||
AbstractConfiguration& operator = (const AbstractConfiguration&);
|
||||
|
||||
mutable int _depth;
|
||||
bool _eventsEnabled;
|
||||
mutable Poco::FastMutex _mutex;
|
||||
|
||||
friend class LayeredConfiguration;
|
||||
friend class ConfigurationView;
|
||||
friend class ConfigurationMapper;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_AbstractConfiguration_INCLUDED
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,116 +1,116 @@
|
||||
//
|
||||
// ConfigurationMapper.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/ConfigurationMapper.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: ConfigurationMapper
|
||||
//
|
||||
// Definition of the ConfigurationMapper class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_ConfigurationMapper_INCLUDED
|
||||
#define Util_ConfigurationMapper_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API ConfigurationMapper: public AbstractConfiguration
|
||||
/// This configuration maps a property hierarchy into another
|
||||
/// hierarchy.
|
||||
///
|
||||
/// For example, given a configuration with the following properties:
|
||||
/// config.value1
|
||||
/// config.value2
|
||||
/// config.sub.value1
|
||||
/// config.sub.value2
|
||||
/// and a ConfigurationView with fromPrefix == "config" and toPrefix == "root.conf", then
|
||||
/// the above properties will be available via the mapper as
|
||||
/// root.conf.value1
|
||||
/// root.conf.value2
|
||||
/// root.conf.sub.value1
|
||||
/// root.conf.sub.value2
|
||||
///
|
||||
/// FromPrefix can be empty, in which case, and given toPrefix == "root",
|
||||
/// the properties will be available as
|
||||
/// root.config.value1
|
||||
/// root.config.value2
|
||||
/// root.config.sub.value1
|
||||
/// root.config.sub.value2
|
||||
///
|
||||
/// This is equivalent to the functionality of the ConfigurationView class.
|
||||
///
|
||||
/// Similarly, toPrefix can also be empty. Given fromPrefix == "config" and
|
||||
/// toPrefix == "", the properties will be available as
|
||||
/// value1
|
||||
/// value2
|
||||
/// sub.value1
|
||||
/// sub.value2
|
||||
///
|
||||
/// If both fromPrefix and toPrefix are empty, no mapping is performed.
|
||||
///
|
||||
/// A ConfigurationMapper is most useful in combination with a
|
||||
/// LayeredConfiguration.
|
||||
{
|
||||
public:
|
||||
ConfigurationMapper(const std::string& fromPrefix, const std::string& toPrefix, AbstractConfiguration* pConfig);
|
||||
/// Creates the ConfigurationMapper. The ConfigurationMapper does not take
|
||||
/// ownership of the passed configuration.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
std::string translateKey(const std::string& key) const;
|
||||
|
||||
~ConfigurationMapper();
|
||||
|
||||
private:
|
||||
ConfigurationMapper(const ConfigurationMapper&);
|
||||
ConfigurationMapper& operator = (const ConfigurationMapper&);
|
||||
|
||||
std::string _fromPrefix;
|
||||
std::string _toPrefix;
|
||||
AbstractConfiguration* _pConfig;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_ConfigurationMapper_INCLUDED
|
||||
//
|
||||
// ConfigurationMapper.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/ConfigurationMapper.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: ConfigurationMapper
|
||||
//
|
||||
// Definition of the ConfigurationMapper class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_ConfigurationMapper_INCLUDED
|
||||
#define Util_ConfigurationMapper_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API ConfigurationMapper: public AbstractConfiguration
|
||||
/// This configuration maps a property hierarchy into another
|
||||
/// hierarchy.
|
||||
///
|
||||
/// For example, given a configuration with the following properties:
|
||||
/// config.value1
|
||||
/// config.value2
|
||||
/// config.sub.value1
|
||||
/// config.sub.value2
|
||||
/// and a ConfigurationView with fromPrefix == "config" and toPrefix == "root.conf", then
|
||||
/// the above properties will be available via the mapper as
|
||||
/// root.conf.value1
|
||||
/// root.conf.value2
|
||||
/// root.conf.sub.value1
|
||||
/// root.conf.sub.value2
|
||||
///
|
||||
/// FromPrefix can be empty, in which case, and given toPrefix == "root",
|
||||
/// the properties will be available as
|
||||
/// root.config.value1
|
||||
/// root.config.value2
|
||||
/// root.config.sub.value1
|
||||
/// root.config.sub.value2
|
||||
///
|
||||
/// This is equivalent to the functionality of the ConfigurationView class.
|
||||
///
|
||||
/// Similarly, toPrefix can also be empty. Given fromPrefix == "config" and
|
||||
/// toPrefix == "", the properties will be available as
|
||||
/// value1
|
||||
/// value2
|
||||
/// sub.value1
|
||||
/// sub.value2
|
||||
///
|
||||
/// If both fromPrefix and toPrefix are empty, no mapping is performed.
|
||||
///
|
||||
/// A ConfigurationMapper is most useful in combination with a
|
||||
/// LayeredConfiguration.
|
||||
{
|
||||
public:
|
||||
ConfigurationMapper(const std::string& fromPrefix, const std::string& toPrefix, AbstractConfiguration* pConfig);
|
||||
/// Creates the ConfigurationMapper. The ConfigurationMapper does not take
|
||||
/// ownership of the passed configuration.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
std::string translateKey(const std::string& key) const;
|
||||
|
||||
~ConfigurationMapper();
|
||||
|
||||
private:
|
||||
ConfigurationMapper(const ConfigurationMapper&);
|
||||
ConfigurationMapper& operator = (const ConfigurationMapper&);
|
||||
|
||||
std::string _fromPrefix;
|
||||
std::string _toPrefix;
|
||||
AbstractConfiguration* _pConfig;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_ConfigurationMapper_INCLUDED
|
||||
|
||||
@@ -1,104 +1,104 @@
|
||||
//
|
||||
// ConfigurationView.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/ConfigurationView.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: ConfigurationView
|
||||
//
|
||||
// Definition of the ConfigurationView class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_ConfigurationView_INCLUDED
|
||||
#define Util_ConfigurationView_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API ConfigurationView: public AbstractConfiguration
|
||||
/// This configuration implements a "view" into a sub-hierarchy
|
||||
/// of another configuration.
|
||||
///
|
||||
/// For example, given a configuration with the following properties:
|
||||
/// config.value1
|
||||
/// config.value2
|
||||
/// config.sub.value1
|
||||
/// config.sub.value2
|
||||
/// and a ConfigurationView with the prefix "config", then
|
||||
/// the above properties will be available via the view as
|
||||
/// value1
|
||||
/// value2
|
||||
/// sub.value1
|
||||
/// sub.value2
|
||||
///
|
||||
/// A ConfigurationView is most useful in combination with a
|
||||
/// LayeredConfiguration.
|
||||
///
|
||||
/// If a property is not found in the view, it is searched in
|
||||
/// the original configuration. Given the above example configuration,
|
||||
/// the property named "config.value1" will still be found in the view.
|
||||
///
|
||||
/// The main reason for this is that placeholder expansion (${property})
|
||||
/// still works as expected given a ConfigurationView.
|
||||
{
|
||||
public:
|
||||
ConfigurationView(const std::string& prefix, AbstractConfiguration* pConfig);
|
||||
/// Creates the ConfigurationView. The ConfigurationView does not take
|
||||
/// ownership of the passed configuration.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
std::string translateKey(const std::string& key) const;
|
||||
|
||||
~ConfigurationView();
|
||||
|
||||
private:
|
||||
ConfigurationView(const ConfigurationView&);
|
||||
ConfigurationView& operator = (const ConfigurationView&);
|
||||
|
||||
std::string _prefix;
|
||||
AbstractConfiguration* _pConfig;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_ConfigurationView_INCLUDED
|
||||
//
|
||||
// ConfigurationView.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/ConfigurationView.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: ConfigurationView
|
||||
//
|
||||
// Definition of the ConfigurationView class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_ConfigurationView_INCLUDED
|
||||
#define Util_ConfigurationView_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API ConfigurationView: public AbstractConfiguration
|
||||
/// This configuration implements a "view" into a sub-hierarchy
|
||||
/// of another configuration.
|
||||
///
|
||||
/// For example, given a configuration with the following properties:
|
||||
/// config.value1
|
||||
/// config.value2
|
||||
/// config.sub.value1
|
||||
/// config.sub.value2
|
||||
/// and a ConfigurationView with the prefix "config", then
|
||||
/// the above properties will be available via the view as
|
||||
/// value1
|
||||
/// value2
|
||||
/// sub.value1
|
||||
/// sub.value2
|
||||
///
|
||||
/// A ConfigurationView is most useful in combination with a
|
||||
/// LayeredConfiguration.
|
||||
///
|
||||
/// If a property is not found in the view, it is searched in
|
||||
/// the original configuration. Given the above example configuration,
|
||||
/// the property named "config.value1" will still be found in the view.
|
||||
///
|
||||
/// The main reason for this is that placeholder expansion (${property})
|
||||
/// still works as expected given a ConfigurationView.
|
||||
{
|
||||
public:
|
||||
ConfigurationView(const std::string& prefix, AbstractConfiguration* pConfig);
|
||||
/// Creates the ConfigurationView. The ConfigurationView does not take
|
||||
/// ownership of the passed configuration.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
std::string translateKey(const std::string& key) const;
|
||||
|
||||
~ConfigurationView();
|
||||
|
||||
private:
|
||||
ConfigurationView(const ConfigurationView&);
|
||||
ConfigurationView& operator = (const ConfigurationView&);
|
||||
|
||||
std::string _prefix;
|
||||
AbstractConfiguration* _pConfig;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_ConfigurationView_INCLUDED
|
||||
|
||||
@@ -1,115 +1,115 @@
|
||||
//
|
||||
// FilesystemConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/FilesystemConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: FilesystemConfiguration
|
||||
//
|
||||
// Definition of the FilesystemConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_FilesystemConfiguration_INCLUDED
|
||||
#define Util_FilesystemConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/Path.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API FilesystemConfiguration: public AbstractConfiguration
|
||||
/// An implementation of AbstractConfiguration that stores configuration data
|
||||
/// in a directory hierarchy in the filesystem.
|
||||
///
|
||||
/// Every period-separated part of a property name is represented
|
||||
/// as a directory in the filesystem, relative to the base directory.
|
||||
/// Values are stored in files named "data".
|
||||
///
|
||||
/// All changes to properties are immediately persisted in the filesystem.
|
||||
///
|
||||
/// For example, a configuration consisting of the properties
|
||||
///
|
||||
/// logging.loggers.root.channel.class = ConsoleChannel
|
||||
/// logging.loggers.app.name = Application
|
||||
/// logging.loggers.app.channel = c1
|
||||
/// logging.formatters.f1.class = PatternFormatter
|
||||
/// logging.formatters.f1.pattern = [%p] %t
|
||||
///
|
||||
/// is stored in the filesystem as follows:
|
||||
///
|
||||
/// logging/
|
||||
/// loggers/
|
||||
/// root/
|
||||
/// channel/
|
||||
/// class/
|
||||
/// data ("ConsoleChannel")
|
||||
/// app/
|
||||
/// name/
|
||||
/// data ("Application")
|
||||
/// channel/
|
||||
/// data ("c1")
|
||||
/// formatters/
|
||||
/// f1/
|
||||
/// class/
|
||||
/// data ("PatternFormatter")
|
||||
/// pattern/
|
||||
/// data ("[%p] %t")
|
||||
{
|
||||
public:
|
||||
FilesystemConfiguration(const std::string& path);
|
||||
/// Creates a FilesystemConfiguration using the given path.
|
||||
/// All directories are created as necessary.
|
||||
|
||||
void clear();
|
||||
/// Clears the configuration by erasing the configuration
|
||||
/// directory and all its subdirectories and files.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
Poco::Path keyToPath(const std::string& key) const;
|
||||
~FilesystemConfiguration();
|
||||
|
||||
private:
|
||||
Poco::Path _path;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_FilesystemConfiguration_INCLUDED
|
||||
//
|
||||
// FilesystemConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/FilesystemConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: FilesystemConfiguration
|
||||
//
|
||||
// Definition of the FilesystemConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_FilesystemConfiguration_INCLUDED
|
||||
#define Util_FilesystemConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/Path.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API FilesystemConfiguration: public AbstractConfiguration
|
||||
/// An implementation of AbstractConfiguration that stores configuration data
|
||||
/// in a directory hierarchy in the filesystem.
|
||||
///
|
||||
/// Every period-separated part of a property name is represented
|
||||
/// as a directory in the filesystem, relative to the base directory.
|
||||
/// Values are stored in files named "data".
|
||||
///
|
||||
/// All changes to properties are immediately persisted in the filesystem.
|
||||
///
|
||||
/// For example, a configuration consisting of the properties
|
||||
///
|
||||
/// logging.loggers.root.channel.class = ConsoleChannel
|
||||
/// logging.loggers.app.name = Application
|
||||
/// logging.loggers.app.channel = c1
|
||||
/// logging.formatters.f1.class = PatternFormatter
|
||||
/// logging.formatters.f1.pattern = [%p] %t
|
||||
///
|
||||
/// is stored in the filesystem as follows:
|
||||
///
|
||||
/// logging/
|
||||
/// loggers/
|
||||
/// root/
|
||||
/// channel/
|
||||
/// class/
|
||||
/// data ("ConsoleChannel")
|
||||
/// app/
|
||||
/// name/
|
||||
/// data ("Application")
|
||||
/// channel/
|
||||
/// data ("c1")
|
||||
/// formatters/
|
||||
/// f1/
|
||||
/// class/
|
||||
/// data ("PatternFormatter")
|
||||
/// pattern/
|
||||
/// data ("[%p] %t")
|
||||
{
|
||||
public:
|
||||
FilesystemConfiguration(const std::string& path);
|
||||
/// Creates a FilesystemConfiguration using the given path.
|
||||
/// All directories are created as necessary.
|
||||
|
||||
void clear();
|
||||
/// Clears the configuration by erasing the configuration
|
||||
/// directory and all its subdirectories and files.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
Poco::Path keyToPath(const std::string& key) const;
|
||||
~FilesystemConfiguration();
|
||||
|
||||
private:
|
||||
Poco::Path _path;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_FilesystemConfiguration_INCLUDED
|
||||
|
||||
@@ -1,224 +1,224 @@
|
||||
//
|
||||
// HelpFormatter.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/HelpFormatter.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: HelpFormatter
|
||||
//
|
||||
// Definition of the HelpFormatter class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_HelpFormatter_INCLUDED
|
||||
#define Util_HelpFormatter_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class OptionSet;
|
||||
class Option;
|
||||
|
||||
|
||||
class Util_API HelpFormatter
|
||||
/// This class formats a help message from an OptionSet.
|
||||
{
|
||||
public:
|
||||
HelpFormatter(const OptionSet& options);
|
||||
/// Creates the HelpFormatter, using the given
|
||||
/// options.
|
||||
///
|
||||
/// The HelpFormatter just stores a reference
|
||||
/// to the given OptionSet, so the OptionSet must not
|
||||
/// be destroyed during the lifetime of the HelpFormatter.
|
||||
|
||||
~HelpFormatter();
|
||||
/// Destroys the HelpFormatter.
|
||||
|
||||
void setCommand(const std::string& command);
|
||||
/// Sets the command name.
|
||||
|
||||
const std::string& getCommand() const;
|
||||
/// Returns the command name.
|
||||
|
||||
void setUsage(const std::string& usage);
|
||||
/// Sets the usage string.
|
||||
|
||||
const std::string& getUsage() const;
|
||||
/// Returns the usage string.
|
||||
|
||||
void setHeader(const std::string& header);
|
||||
/// Sets the header string.
|
||||
|
||||
const std::string& getHeader() const;
|
||||
/// Returns the header string.
|
||||
|
||||
void setFooter(const std::string& footer);
|
||||
/// Sets the footer string.
|
||||
|
||||
const std::string& getFooter() const;
|
||||
/// Returns the footer string.
|
||||
|
||||
void format(std::ostream& ostr) const;
|
||||
/// Writes the formatted help text to the given stream.
|
||||
|
||||
void setWidth(int width);
|
||||
/// Sets the line width for the formatted help text.
|
||||
|
||||
int getWidth() const;
|
||||
/// Returns the line width for the formatted help text.
|
||||
///
|
||||
/// The default width is 72.
|
||||
|
||||
void setIndent(int indent);
|
||||
/// Sets the indentation for description continuation lines.
|
||||
|
||||
int getIndent() const;
|
||||
/// Returns the indentation for description continuation lines.
|
||||
|
||||
void setAutoIndent();
|
||||
/// Sets the indentation for description continuation lines so that
|
||||
/// the description text is left-aligned.
|
||||
|
||||
void setUnixStyle(bool flag);
|
||||
/// Enables Unix-style options. Both short and long option names
|
||||
/// are printed if Unix-style is set. Otherwise, only long option
|
||||
/// names are printed.
|
||||
///
|
||||
/// After calling setUnixStyle(), setAutoIndent() should be called
|
||||
/// as well to ensure proper help text formatting.
|
||||
|
||||
bool isUnixStyle() const;
|
||||
/// Returns if Unix-style options are set.
|
||||
|
||||
std::string shortPrefix() const;
|
||||
/// Returns the platform-specific prefix for short options.
|
||||
/// "-" on Unix, "/" on Windows and OpenVMS.
|
||||
|
||||
std::string longPrefix() const;
|
||||
/// Returns the platform-specific prefix for long options.
|
||||
/// "--" on Unix, "/" on Windows and OpenVMS.
|
||||
|
||||
protected:
|
||||
int calcIndent() const;
|
||||
/// Calculates the indentation for the option descriptions
|
||||
/// from the given options.
|
||||
|
||||
void formatOptions(std::ostream& ostr) const;
|
||||
/// Formats all options.
|
||||
|
||||
void formatOption(std::ostream& ostr, const Option& option, int width) const;
|
||||
/// Formats an option, using the platform-specific
|
||||
/// prefixes.
|
||||
|
||||
void formatText(std::ostream& ostr, const std::string& text, int indent) const;
|
||||
/// Formats the given text.
|
||||
|
||||
void formatText(std::ostream& ostr, const std::string& text, int indent, int firstIndent) const;
|
||||
/// Formats the given text.
|
||||
|
||||
void formatWord(std::ostream& ostr, int& pos, const std::string& word, int indent) const;
|
||||
/// Formats the given word.
|
||||
|
||||
void clearWord(std::ostream& ostr, int& pos, std::string& word, int indent) const;
|
||||
/// Formats and then clears the given word.
|
||||
|
||||
private:
|
||||
HelpFormatter(const HelpFormatter&);
|
||||
HelpFormatter& operator = (const HelpFormatter&);
|
||||
|
||||
const OptionSet& _options;
|
||||
int _width;
|
||||
int _indent;
|
||||
std::string _command;
|
||||
std::string _usage;
|
||||
std::string _header;
|
||||
std::string _footer;
|
||||
bool _unixStyle;
|
||||
|
||||
static const int TAB_WIDTH;
|
||||
static const int LINE_WIDTH;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline int HelpFormatter::getWidth() const
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
|
||||
inline int HelpFormatter::getIndent() const
|
||||
{
|
||||
return _indent;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HelpFormatter::getCommand() const
|
||||
{
|
||||
return _command;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HelpFormatter::getUsage() const
|
||||
{
|
||||
return _usage;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HelpFormatter::getHeader() const
|
||||
{
|
||||
return _header;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HelpFormatter::getFooter() const
|
||||
{
|
||||
return _footer;
|
||||
}
|
||||
|
||||
|
||||
inline bool HelpFormatter::isUnixStyle() const
|
||||
{
|
||||
return _unixStyle;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_HelpFormatter_INCLUDED
|
||||
//
|
||||
// HelpFormatter.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/HelpFormatter.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: HelpFormatter
|
||||
//
|
||||
// Definition of the HelpFormatter class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_HelpFormatter_INCLUDED
|
||||
#define Util_HelpFormatter_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class OptionSet;
|
||||
class Option;
|
||||
|
||||
|
||||
class Util_API HelpFormatter
|
||||
/// This class formats a help message from an OptionSet.
|
||||
{
|
||||
public:
|
||||
HelpFormatter(const OptionSet& options);
|
||||
/// Creates the HelpFormatter, using the given
|
||||
/// options.
|
||||
///
|
||||
/// The HelpFormatter just stores a reference
|
||||
/// to the given OptionSet, so the OptionSet must not
|
||||
/// be destroyed during the lifetime of the HelpFormatter.
|
||||
|
||||
~HelpFormatter();
|
||||
/// Destroys the HelpFormatter.
|
||||
|
||||
void setCommand(const std::string& command);
|
||||
/// Sets the command name.
|
||||
|
||||
const std::string& getCommand() const;
|
||||
/// Returns the command name.
|
||||
|
||||
void setUsage(const std::string& usage);
|
||||
/// Sets the usage string.
|
||||
|
||||
const std::string& getUsage() const;
|
||||
/// Returns the usage string.
|
||||
|
||||
void setHeader(const std::string& header);
|
||||
/// Sets the header string.
|
||||
|
||||
const std::string& getHeader() const;
|
||||
/// Returns the header string.
|
||||
|
||||
void setFooter(const std::string& footer);
|
||||
/// Sets the footer string.
|
||||
|
||||
const std::string& getFooter() const;
|
||||
/// Returns the footer string.
|
||||
|
||||
void format(std::ostream& ostr) const;
|
||||
/// Writes the formatted help text to the given stream.
|
||||
|
||||
void setWidth(int width);
|
||||
/// Sets the line width for the formatted help text.
|
||||
|
||||
int getWidth() const;
|
||||
/// Returns the line width for the formatted help text.
|
||||
///
|
||||
/// The default width is 72.
|
||||
|
||||
void setIndent(int indent);
|
||||
/// Sets the indentation for description continuation lines.
|
||||
|
||||
int getIndent() const;
|
||||
/// Returns the indentation for description continuation lines.
|
||||
|
||||
void setAutoIndent();
|
||||
/// Sets the indentation for description continuation lines so that
|
||||
/// the description text is left-aligned.
|
||||
|
||||
void setUnixStyle(bool flag);
|
||||
/// Enables Unix-style options. Both short and long option names
|
||||
/// are printed if Unix-style is set. Otherwise, only long option
|
||||
/// names are printed.
|
||||
///
|
||||
/// After calling setUnixStyle(), setAutoIndent() should be called
|
||||
/// as well to ensure proper help text formatting.
|
||||
|
||||
bool isUnixStyle() const;
|
||||
/// Returns if Unix-style options are set.
|
||||
|
||||
std::string shortPrefix() const;
|
||||
/// Returns the platform-specific prefix for short options.
|
||||
/// "-" on Unix, "/" on Windows and OpenVMS.
|
||||
|
||||
std::string longPrefix() const;
|
||||
/// Returns the platform-specific prefix for long options.
|
||||
/// "--" on Unix, "/" on Windows and OpenVMS.
|
||||
|
||||
protected:
|
||||
int calcIndent() const;
|
||||
/// Calculates the indentation for the option descriptions
|
||||
/// from the given options.
|
||||
|
||||
void formatOptions(std::ostream& ostr) const;
|
||||
/// Formats all options.
|
||||
|
||||
void formatOption(std::ostream& ostr, const Option& option, int width) const;
|
||||
/// Formats an option, using the platform-specific
|
||||
/// prefixes.
|
||||
|
||||
void formatText(std::ostream& ostr, const std::string& text, int indent) const;
|
||||
/// Formats the given text.
|
||||
|
||||
void formatText(std::ostream& ostr, const std::string& text, int indent, int firstIndent) const;
|
||||
/// Formats the given text.
|
||||
|
||||
void formatWord(std::ostream& ostr, int& pos, const std::string& word, int indent) const;
|
||||
/// Formats the given word.
|
||||
|
||||
void clearWord(std::ostream& ostr, int& pos, std::string& word, int indent) const;
|
||||
/// Formats and then clears the given word.
|
||||
|
||||
private:
|
||||
HelpFormatter(const HelpFormatter&);
|
||||
HelpFormatter& operator = (const HelpFormatter&);
|
||||
|
||||
const OptionSet& _options;
|
||||
int _width;
|
||||
int _indent;
|
||||
std::string _command;
|
||||
std::string _usage;
|
||||
std::string _header;
|
||||
std::string _footer;
|
||||
bool _unixStyle;
|
||||
|
||||
static const int TAB_WIDTH;
|
||||
static const int LINE_WIDTH;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline int HelpFormatter::getWidth() const
|
||||
{
|
||||
return _width;
|
||||
}
|
||||
|
||||
|
||||
inline int HelpFormatter::getIndent() const
|
||||
{
|
||||
return _indent;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HelpFormatter::getCommand() const
|
||||
{
|
||||
return _command;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HelpFormatter::getUsage() const
|
||||
{
|
||||
return _usage;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HelpFormatter::getHeader() const
|
||||
{
|
||||
return _header;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HelpFormatter::getFooter() const
|
||||
{
|
||||
return _footer;
|
||||
}
|
||||
|
||||
|
||||
inline bool HelpFormatter::isUnixStyle() const
|
||||
{
|
||||
return _unixStyle;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_HelpFormatter_INCLUDED
|
||||
|
||||
@@ -1,113 +1,113 @@
|
||||
//
|
||||
// IniFileConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/IniFileConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: IniFileConfiguration
|
||||
//
|
||||
// Definition of the IniFileConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_IniFileConfiguration_INCLUDED
|
||||
#define Util_IniFileConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include <map>
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API IniFileConfiguration: public AbstractConfiguration
|
||||
/// This implementation of a Configuration reads properties
|
||||
/// from a legacy Windows initialization (.ini) file.
|
||||
///
|
||||
/// The file syntax is implemented as follows.
|
||||
/// - a line starting with a semicolon is treated as a comment and ignored
|
||||
/// - a line starting with a square bracket denotes a section key [<key>]
|
||||
/// - every other line denotes a property assignment in the form
|
||||
/// <value key> = <value>
|
||||
///
|
||||
/// The name of a property is composed of the section key and the value key,
|
||||
/// separated by a period (<section key>.<value key>).
|
||||
///
|
||||
/// Property names are not case sensitive. Leading and trailing whitespace is
|
||||
/// removed from both keys and values.
|
||||
{
|
||||
public:
|
||||
IniFileConfiguration();
|
||||
/// Creates an empty IniFileConfiguration.
|
||||
|
||||
IniFileConfiguration(std::istream& istr);
|
||||
/// Creates an IniFileConfiguration and loads the configuration data
|
||||
/// from the given stream, which must be in initialization file format.
|
||||
|
||||
IniFileConfiguration(const std::string& path);
|
||||
/// Creates an IniFileConfiguration and loads the configuration data
|
||||
/// from the given file, which must be in initialization file format.
|
||||
|
||||
void load(std::istream& istr);
|
||||
/// Loads the configuration data from the given stream, which
|
||||
/// must be in initialization file format.
|
||||
|
||||
void load(const std::string& path);
|
||||
/// Loads the configuration data from the given file, which
|
||||
/// must be in initialization file format.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
~IniFileConfiguration();
|
||||
|
||||
private:
|
||||
void parseLine(std::istream& istr);
|
||||
|
||||
struct ICompare
|
||||
{
|
||||
bool operator () (const std::string& s1, const std::string& s2) const;
|
||||
};
|
||||
typedef std::map<std::string, std::string, ICompare> IStringMap;
|
||||
|
||||
IStringMap _map;
|
||||
std::string _sectionKey;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_IniFileConfiguration_INCLUDED
|
||||
//
|
||||
// IniFileConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/IniFileConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: IniFileConfiguration
|
||||
//
|
||||
// Definition of the IniFileConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_IniFileConfiguration_INCLUDED
|
||||
#define Util_IniFileConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include <map>
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API IniFileConfiguration: public AbstractConfiguration
|
||||
/// This implementation of a Configuration reads properties
|
||||
/// from a legacy Windows initialization (.ini) file.
|
||||
///
|
||||
/// The file syntax is implemented as follows.
|
||||
/// - a line starting with a semicolon is treated as a comment and ignored
|
||||
/// - a line starting with a square bracket denotes a section key [<key>]
|
||||
/// - every other line denotes a property assignment in the form
|
||||
/// <value key> = <value>
|
||||
///
|
||||
/// The name of a property is composed of the section key and the value key,
|
||||
/// separated by a period (<section key>.<value key>).
|
||||
///
|
||||
/// Property names are not case sensitive. Leading and trailing whitespace is
|
||||
/// removed from both keys and values.
|
||||
{
|
||||
public:
|
||||
IniFileConfiguration();
|
||||
/// Creates an empty IniFileConfiguration.
|
||||
|
||||
IniFileConfiguration(std::istream& istr);
|
||||
/// Creates an IniFileConfiguration and loads the configuration data
|
||||
/// from the given stream, which must be in initialization file format.
|
||||
|
||||
IniFileConfiguration(const std::string& path);
|
||||
/// Creates an IniFileConfiguration and loads the configuration data
|
||||
/// from the given file, which must be in initialization file format.
|
||||
|
||||
void load(std::istream& istr);
|
||||
/// Loads the configuration data from the given stream, which
|
||||
/// must be in initialization file format.
|
||||
|
||||
void load(const std::string& path);
|
||||
/// Loads the configuration data from the given file, which
|
||||
/// must be in initialization file format.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
~IniFileConfiguration();
|
||||
|
||||
private:
|
||||
void parseLine(std::istream& istr);
|
||||
|
||||
struct ICompare
|
||||
{
|
||||
bool operator () (const std::string& s1, const std::string& s2) const;
|
||||
};
|
||||
typedef std::map<std::string, std::string, ICompare> IStringMap;
|
||||
|
||||
IStringMap _map;
|
||||
std::string _sectionKey;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_IniFileConfiguration_INCLUDED
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
//
|
||||
// IntValidator.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/IntValidator.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: IntValidator
|
||||
//
|
||||
// Definition of the IntValidator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_IntValidator_INCLUDED
|
||||
#define Util_IntValidator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Validator.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API IntValidator: public Validator
|
||||
/// The IntValidator tests whether the option argument,
|
||||
/// which must be an integer, lies within a given range.
|
||||
{
|
||||
public:
|
||||
IntValidator(int min, int max);
|
||||
/// Creates the IntValidator.
|
||||
|
||||
~IntValidator();
|
||||
/// Destroys the IntValidator.
|
||||
|
||||
void validate(const Option& option, const std::string& value);
|
||||
/// Validates the value for the given option by
|
||||
/// testing whether it's an integer that lies within
|
||||
/// a given range.
|
||||
|
||||
private:
|
||||
IntValidator();
|
||||
|
||||
int _min;
|
||||
int _max;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_IntValidator_INCLUDED
|
||||
//
|
||||
// IntValidator.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/IntValidator.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: IntValidator
|
||||
//
|
||||
// Definition of the IntValidator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_IntValidator_INCLUDED
|
||||
#define Util_IntValidator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Validator.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API IntValidator: public Validator
|
||||
/// The IntValidator tests whether the option argument,
|
||||
/// which must be an integer, lies within a given range.
|
||||
{
|
||||
public:
|
||||
IntValidator(int min, int max);
|
||||
/// Creates the IntValidator.
|
||||
|
||||
~IntValidator();
|
||||
/// Destroys the IntValidator.
|
||||
|
||||
void validate(const Option& option, const std::string& value);
|
||||
/// Validates the value for the given option by
|
||||
/// testing whether it's an integer that lies within
|
||||
/// a given range.
|
||||
|
||||
private:
|
||||
IntValidator();
|
||||
|
||||
int _min;
|
||||
int _max;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_IntValidator_INCLUDED
|
||||
|
||||
@@ -1,170 +1,170 @@
|
||||
//
|
||||
// LayeredConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/LayeredConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: LayeredConfiguration
|
||||
//
|
||||
// Definition of the LayeredConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_LayeredConfiguration_INCLUDED
|
||||
#define Util_LayeredConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API LayeredConfiguration: public AbstractConfiguration
|
||||
/// A LayeredConfiguration consists of a number of AbstractConfigurations.
|
||||
///
|
||||
/// When reading a configuration property in a LayeredConfiguration,
|
||||
/// all added configurations are searched, in order of their priority.
|
||||
/// Configurations with lower priority values have precedence.
|
||||
///
|
||||
/// When setting a property, the property is always written to the first writeable
|
||||
/// configuration (see addWriteable()).
|
||||
/// If no writeable configuration has been added to the LayeredConfiguration, and an
|
||||
/// attempt is made to set a property, a RuntimeException is thrown.
|
||||
///
|
||||
/// Every configuration added to the LayeredConfiguration has a priority value.
|
||||
/// The priority determines the position where the configuration is inserted,
|
||||
/// with lower priority values coming before higher priority values.
|
||||
///
|
||||
/// If no priority is specified, a priority of 0 is assumed.
|
||||
{
|
||||
public:
|
||||
LayeredConfiguration();
|
||||
/// Creates the LayeredConfiguration.
|
||||
|
||||
void add(AbstractConfiguration* pConfig);
|
||||
/// Adds a read-only configuration to the back of the LayeredConfiguration.
|
||||
/// The LayeredConfiguration does not take ownership of the given
|
||||
/// configuration. In other words, the configuration's reference
|
||||
/// count is incremented.
|
||||
|
||||
void add(AbstractConfiguration* pConfig, bool shared);
|
||||
/// Adds a read-only configuration to the back of the LayeredConfiguration.
|
||||
/// If shared is false, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration (and the configuration's reference
|
||||
/// count remains unchanged).
|
||||
|
||||
void add(AbstractConfiguration* pConfig, int priority);
|
||||
/// Adds a read-only configuration to the LayeredConfiguration.
|
||||
/// The LayeredConfiguration does not take ownership of the given
|
||||
/// configuration. In other words, the configuration's reference
|
||||
/// count is incremented.
|
||||
|
||||
void add(AbstractConfiguration* pConfig, int priority, bool shared);
|
||||
/// Adds a read-only configuration the LayeredConfiguration.
|
||||
/// If shared is false, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration (and the configuration's reference
|
||||
/// count remains unchanged).
|
||||
|
||||
void add(AbstractConfiguration* pConfig, int priority, bool writeable, bool shared);
|
||||
/// Adds a configuration to the LayeredConfiguration.
|
||||
/// If shared is false, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration (and the configuration's reference
|
||||
/// count remains unchanged).
|
||||
|
||||
void addWriteable(AbstractConfiguration* pConfig, int priority);
|
||||
/// Adds a writeable configuration to the LayeredConfiguration.
|
||||
/// The LayeredConfiguration does not take ownership of the given
|
||||
/// configuration. In other words, the configuration's reference
|
||||
/// count is incremented.
|
||||
|
||||
void addWriteable(AbstractConfiguration* pConfig, int priority, bool shared);
|
||||
/// Adds a writeable configuration to the LayeredConfiguration.
|
||||
/// If shared is false, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration (and the configuration's reference
|
||||
/// count remains unchanged).
|
||||
|
||||
//@ deprecated
|
||||
void addFront(AbstractConfiguration* pConfig);
|
||||
/// Adds a read-only configuration to the front of the LayeredConfiguration.
|
||||
/// The LayeredConfiguration does not take ownership of the given
|
||||
/// configuration. In other words, the configuration's reference
|
||||
/// count is incremented.
|
||||
|
||||
//@ deprecated
|
||||
void addFront(AbstractConfiguration* pConfig, bool shared);
|
||||
/// Adds a read-only configuration to the front of the LayeredConfiguration.
|
||||
/// If shared is true, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration.
|
||||
|
||||
void removeConfiguration(AbstractConfiguration* pConfig);
|
||||
/// Removes the given configuration from the LayeredConfiguration.
|
||||
///
|
||||
/// Does nothing if the given configuration is not part of the
|
||||
/// LayeredConfiguration.
|
||||
|
||||
protected:
|
||||
typedef Poco::AutoPtr<AbstractConfiguration> ConfigPtr;
|
||||
|
||||
struct ConfigItem
|
||||
{
|
||||
ConfigPtr pConfig;
|
||||
int priority;
|
||||
bool writeable;
|
||||
};
|
||||
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
int lowest() const;
|
||||
int highest() const;
|
||||
void insert(const ConfigItem& item);
|
||||
|
||||
~LayeredConfiguration();
|
||||
|
||||
private:
|
||||
LayeredConfiguration(const LayeredConfiguration&);
|
||||
LayeredConfiguration& operator = (const LayeredConfiguration&);
|
||||
|
||||
typedef std::list<ConfigItem> ConfigList;
|
||||
|
||||
ConfigList _configs;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_LayeredConfiguration_INCLUDED
|
||||
//
|
||||
// LayeredConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/LayeredConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: LayeredConfiguration
|
||||
//
|
||||
// Definition of the LayeredConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_LayeredConfiguration_INCLUDED
|
||||
#define Util_LayeredConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API LayeredConfiguration: public AbstractConfiguration
|
||||
/// A LayeredConfiguration consists of a number of AbstractConfigurations.
|
||||
///
|
||||
/// When reading a configuration property in a LayeredConfiguration,
|
||||
/// all added configurations are searched, in order of their priority.
|
||||
/// Configurations with lower priority values have precedence.
|
||||
///
|
||||
/// When setting a property, the property is always written to the first writeable
|
||||
/// configuration (see addWriteable()).
|
||||
/// If no writeable configuration has been added to the LayeredConfiguration, and an
|
||||
/// attempt is made to set a property, a RuntimeException is thrown.
|
||||
///
|
||||
/// Every configuration added to the LayeredConfiguration has a priority value.
|
||||
/// The priority determines the position where the configuration is inserted,
|
||||
/// with lower priority values coming before higher priority values.
|
||||
///
|
||||
/// If no priority is specified, a priority of 0 is assumed.
|
||||
{
|
||||
public:
|
||||
LayeredConfiguration();
|
||||
/// Creates the LayeredConfiguration.
|
||||
|
||||
void add(AbstractConfiguration* pConfig);
|
||||
/// Adds a read-only configuration to the back of the LayeredConfiguration.
|
||||
/// The LayeredConfiguration does not take ownership of the given
|
||||
/// configuration. In other words, the configuration's reference
|
||||
/// count is incremented.
|
||||
|
||||
void add(AbstractConfiguration* pConfig, bool shared);
|
||||
/// Adds a read-only configuration to the back of the LayeredConfiguration.
|
||||
/// If shared is false, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration (and the configuration's reference
|
||||
/// count remains unchanged).
|
||||
|
||||
void add(AbstractConfiguration* pConfig, int priority);
|
||||
/// Adds a read-only configuration to the LayeredConfiguration.
|
||||
/// The LayeredConfiguration does not take ownership of the given
|
||||
/// configuration. In other words, the configuration's reference
|
||||
/// count is incremented.
|
||||
|
||||
void add(AbstractConfiguration* pConfig, int priority, bool shared);
|
||||
/// Adds a read-only configuration the LayeredConfiguration.
|
||||
/// If shared is false, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration (and the configuration's reference
|
||||
/// count remains unchanged).
|
||||
|
||||
void add(AbstractConfiguration* pConfig, int priority, bool writeable, bool shared);
|
||||
/// Adds a configuration to the LayeredConfiguration.
|
||||
/// If shared is false, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration (and the configuration's reference
|
||||
/// count remains unchanged).
|
||||
|
||||
void addWriteable(AbstractConfiguration* pConfig, int priority);
|
||||
/// Adds a writeable configuration to the LayeredConfiguration.
|
||||
/// The LayeredConfiguration does not take ownership of the given
|
||||
/// configuration. In other words, the configuration's reference
|
||||
/// count is incremented.
|
||||
|
||||
void addWriteable(AbstractConfiguration* pConfig, int priority, bool shared);
|
||||
/// Adds a writeable configuration to the LayeredConfiguration.
|
||||
/// If shared is false, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration (and the configuration's reference
|
||||
/// count remains unchanged).
|
||||
|
||||
//@ deprecated
|
||||
void addFront(AbstractConfiguration* pConfig);
|
||||
/// Adds a read-only configuration to the front of the LayeredConfiguration.
|
||||
/// The LayeredConfiguration does not take ownership of the given
|
||||
/// configuration. In other words, the configuration's reference
|
||||
/// count is incremented.
|
||||
|
||||
//@ deprecated
|
||||
void addFront(AbstractConfiguration* pConfig, bool shared);
|
||||
/// Adds a read-only configuration to the front of the LayeredConfiguration.
|
||||
/// If shared is true, the LayeredConfiguration takes ownership
|
||||
/// of the given configuration.
|
||||
|
||||
void removeConfiguration(AbstractConfiguration* pConfig);
|
||||
/// Removes the given configuration from the LayeredConfiguration.
|
||||
///
|
||||
/// Does nothing if the given configuration is not part of the
|
||||
/// LayeredConfiguration.
|
||||
|
||||
protected:
|
||||
typedef Poco::AutoPtr<AbstractConfiguration> ConfigPtr;
|
||||
|
||||
struct ConfigItem
|
||||
{
|
||||
ConfigPtr pConfig;
|
||||
int priority;
|
||||
bool writeable;
|
||||
};
|
||||
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
int lowest() const;
|
||||
int highest() const;
|
||||
void insert(const ConfigItem& item);
|
||||
|
||||
~LayeredConfiguration();
|
||||
|
||||
private:
|
||||
LayeredConfiguration(const LayeredConfiguration&);
|
||||
LayeredConfiguration& operator = (const LayeredConfiguration&);
|
||||
|
||||
typedef std::list<ConfigItem> ConfigList;
|
||||
|
||||
ConfigList _configs;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_LayeredConfiguration_INCLUDED
|
||||
|
||||
@@ -1,161 +1,161 @@
|
||||
//
|
||||
// LoggingConfigurator.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/LoggingConfigurator.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: LoggingConfigurator
|
||||
//
|
||||
// Definition of the LoggingConfigurator class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_LoggingConfigurator_INCLUDED
|
||||
#define Util_LoggingConfigurator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Formatter.h"
|
||||
#include "Poco/Channel.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class AbstractConfiguration;
|
||||
|
||||
|
||||
class Util_API LoggingConfigurator
|
||||
/// This utility class uses a configuration object to configure the
|
||||
/// logging subsystem of an application.
|
||||
///
|
||||
/// The LoggingConfigurator sets up and connects formatters, channels
|
||||
/// and loggers. To accomplish its work, the LoggingConfigurator relies on the
|
||||
/// functionality provided by the LoggingFactory und LoggingRegistry classes.
|
||||
///
|
||||
/// The LoggingConfigurator expects all configuration data to be under a root
|
||||
/// property named "logging".
|
||||
///
|
||||
/// Configuring Formatters
|
||||
///
|
||||
/// A formatter is configured using the "logging.formatters" property. Every
|
||||
/// formatter has an internal name, which is only used for referring to it
|
||||
/// during configuration time. This name becomes part of the property name.
|
||||
/// Every formatter has a mandatory "class" property, which specifies the actual
|
||||
/// class implementing the formatter. Any other properties are passed on to
|
||||
/// the formatter by calling its setProperty() method.
|
||||
///
|
||||
/// A typical formatter definition looks as follows:
|
||||
/// logging.formatters.f1.class = PatternFormatter
|
||||
/// logging.formatters.f1.pattern = %s: [%p] %t
|
||||
/// logging.formatters.f1.times = UTC
|
||||
///
|
||||
/// Configuring Channels
|
||||
///
|
||||
/// A channel is configured using the "logging.channels" property. Like with
|
||||
/// Formatters, every channel has an internal name, which is used during
|
||||
/// configuration only. The name becomes part of the property name.
|
||||
/// Every channel has a mandatory "class" property, which specifies the actual
|
||||
/// class implementing the channel. Any other properties are passed on to
|
||||
/// the formatter by calling its setProperty() method.
|
||||
///
|
||||
/// For convenience, the "formatter" property of a channel is treated
|
||||
/// specifically. The "formatter" property can either be used to refer to
|
||||
/// an already defined formatter, or it can be used to specify an "inline"
|
||||
/// formatter definition. In either case, when a "formatter" property is
|
||||
/// present, the channel is automatically "wrapped" in a FormattingChannel
|
||||
/// object.
|
||||
///
|
||||
/// Similarly, a channel supports also a "pattern" property, which results
|
||||
/// in the automatic instantiation of a FormattingChannel object with a
|
||||
/// connected PatternFormatter.
|
||||
///
|
||||
/// Examples:
|
||||
/// logging.channels.c1.class = ConsoleChannel
|
||||
/// logging.channels.c1.formatter = f1
|
||||
/// logging.channels.c2.class = FileChannel
|
||||
/// logging.channels.c2.path = ${system.tempDir}/sample.log
|
||||
/// logging.channels.c2.formatter.class = PatternFormatter
|
||||
/// logging.channels.c2.formatter.pattern = %s: [%p] %t
|
||||
/// logging.channels.c3.class = ConsoleChannel
|
||||
/// logging.channels.c3.pattern = %s: [%p] %t
|
||||
///
|
||||
/// Configuring Loggers
|
||||
///
|
||||
/// A logger is configured using the "logging.loggers" property. Like with
|
||||
/// channels and formatters, every logger has an internal name, which, however,
|
||||
/// is only used to ensure the uniqueness of the property names. Note that this
|
||||
/// name is different from the logger's full name, which is used to access
|
||||
/// the logger at runtime.
|
||||
/// Every logger except the root logger has a mandatory "name" property which
|
||||
/// is used to specify the logger's full name.
|
||||
/// Furthermore, a "channel" property is supported, which can either refer
|
||||
/// to a named channel, or which can contain an inline channel definition.
|
||||
///
|
||||
/// Examples:
|
||||
/// logging.loggers.root.channel = c1
|
||||
/// logging.loggers.root.level = warning
|
||||
/// logging.loggers.l1.name = logger1
|
||||
/// logging.loggers.l1.channel.class = ConsoleChannel
|
||||
/// logging.loggers.l1.channel.pattern = %s: [%p] %t
|
||||
/// logging.loggers.l1.level = information
|
||||
{
|
||||
public:
|
||||
LoggingConfigurator();
|
||||
/// Creates the LoggingConfigurator.
|
||||
|
||||
~LoggingConfigurator();
|
||||
/// Destroys the LoggingConfigurator.
|
||||
|
||||
void configure(AbstractConfiguration* pConfig);
|
||||
/// Configures the logging subsystem based on
|
||||
/// the given configuration.
|
||||
///
|
||||
/// A ConfigurationView can be used to pass only
|
||||
/// a part of a larger configuration.
|
||||
|
||||
private:
|
||||
void configureFormatters(AbstractConfiguration* pConfig);
|
||||
void configureChannels(AbstractConfiguration* pConfig);
|
||||
void configureLoggers(AbstractConfiguration* pConfig);
|
||||
Poco::Formatter* createFormatter(AbstractConfiguration* pConfig);
|
||||
Poco::Channel* createChannel(AbstractConfiguration* pConfig);
|
||||
void configureChannel(Channel* pChannel, AbstractConfiguration* pConfig);
|
||||
void configureLogger(AbstractConfiguration* pConfig);
|
||||
|
||||
LoggingConfigurator(const LoggingConfigurator&);
|
||||
LoggingConfigurator& operator = (const LoggingConfigurator&);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_LoggingConfigurator_INCLUDED
|
||||
//
|
||||
// LoggingConfigurator.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/LoggingConfigurator.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: LoggingConfigurator
|
||||
//
|
||||
// Definition of the LoggingConfigurator class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_LoggingConfigurator_INCLUDED
|
||||
#define Util_LoggingConfigurator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Formatter.h"
|
||||
#include "Poco/Channel.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class AbstractConfiguration;
|
||||
|
||||
|
||||
class Util_API LoggingConfigurator
|
||||
/// This utility class uses a configuration object to configure the
|
||||
/// logging subsystem of an application.
|
||||
///
|
||||
/// The LoggingConfigurator sets up and connects formatters, channels
|
||||
/// and loggers. To accomplish its work, the LoggingConfigurator relies on the
|
||||
/// functionality provided by the LoggingFactory und LoggingRegistry classes.
|
||||
///
|
||||
/// The LoggingConfigurator expects all configuration data to be under a root
|
||||
/// property named "logging".
|
||||
///
|
||||
/// Configuring Formatters
|
||||
///
|
||||
/// A formatter is configured using the "logging.formatters" property. Every
|
||||
/// formatter has an internal name, which is only used for referring to it
|
||||
/// during configuration time. This name becomes part of the property name.
|
||||
/// Every formatter has a mandatory "class" property, which specifies the actual
|
||||
/// class implementing the formatter. Any other properties are passed on to
|
||||
/// the formatter by calling its setProperty() method.
|
||||
///
|
||||
/// A typical formatter definition looks as follows:
|
||||
/// logging.formatters.f1.class = PatternFormatter
|
||||
/// logging.formatters.f1.pattern = %s: [%p] %t
|
||||
/// logging.formatters.f1.times = UTC
|
||||
///
|
||||
/// Configuring Channels
|
||||
///
|
||||
/// A channel is configured using the "logging.channels" property. Like with
|
||||
/// Formatters, every channel has an internal name, which is used during
|
||||
/// configuration only. The name becomes part of the property name.
|
||||
/// Every channel has a mandatory "class" property, which specifies the actual
|
||||
/// class implementing the channel. Any other properties are passed on to
|
||||
/// the formatter by calling its setProperty() method.
|
||||
///
|
||||
/// For convenience, the "formatter" property of a channel is treated
|
||||
/// specifically. The "formatter" property can either be used to refer to
|
||||
/// an already defined formatter, or it can be used to specify an "inline"
|
||||
/// formatter definition. In either case, when a "formatter" property is
|
||||
/// present, the channel is automatically "wrapped" in a FormattingChannel
|
||||
/// object.
|
||||
///
|
||||
/// Similarly, a channel supports also a "pattern" property, which results
|
||||
/// in the automatic instantiation of a FormattingChannel object with a
|
||||
/// connected PatternFormatter.
|
||||
///
|
||||
/// Examples:
|
||||
/// logging.channels.c1.class = ConsoleChannel
|
||||
/// logging.channels.c1.formatter = f1
|
||||
/// logging.channels.c2.class = FileChannel
|
||||
/// logging.channels.c2.path = ${system.tempDir}/sample.log
|
||||
/// logging.channels.c2.formatter.class = PatternFormatter
|
||||
/// logging.channels.c2.formatter.pattern = %s: [%p] %t
|
||||
/// logging.channels.c3.class = ConsoleChannel
|
||||
/// logging.channels.c3.pattern = %s: [%p] %t
|
||||
///
|
||||
/// Configuring Loggers
|
||||
///
|
||||
/// A logger is configured using the "logging.loggers" property. Like with
|
||||
/// channels and formatters, every logger has an internal name, which, however,
|
||||
/// is only used to ensure the uniqueness of the property names. Note that this
|
||||
/// name is different from the logger's full name, which is used to access
|
||||
/// the logger at runtime.
|
||||
/// Every logger except the root logger has a mandatory "name" property which
|
||||
/// is used to specify the logger's full name.
|
||||
/// Furthermore, a "channel" property is supported, which can either refer
|
||||
/// to a named channel, or which can contain an inline channel definition.
|
||||
///
|
||||
/// Examples:
|
||||
/// logging.loggers.root.channel = c1
|
||||
/// logging.loggers.root.level = warning
|
||||
/// logging.loggers.l1.name = logger1
|
||||
/// logging.loggers.l1.channel.class = ConsoleChannel
|
||||
/// logging.loggers.l1.channel.pattern = %s: [%p] %t
|
||||
/// logging.loggers.l1.level = information
|
||||
{
|
||||
public:
|
||||
LoggingConfigurator();
|
||||
/// Creates the LoggingConfigurator.
|
||||
|
||||
~LoggingConfigurator();
|
||||
/// Destroys the LoggingConfigurator.
|
||||
|
||||
void configure(AbstractConfiguration* pConfig);
|
||||
/// Configures the logging subsystem based on
|
||||
/// the given configuration.
|
||||
///
|
||||
/// A ConfigurationView can be used to pass only
|
||||
/// a part of a larger configuration.
|
||||
|
||||
private:
|
||||
void configureFormatters(AbstractConfiguration* pConfig);
|
||||
void configureChannels(AbstractConfiguration* pConfig);
|
||||
void configureLoggers(AbstractConfiguration* pConfig);
|
||||
Poco::Formatter* createFormatter(AbstractConfiguration* pConfig);
|
||||
Poco::Channel* createChannel(AbstractConfiguration* pConfig);
|
||||
void configureChannel(Channel* pChannel, AbstractConfiguration* pConfig);
|
||||
void configureLogger(AbstractConfiguration* pConfig);
|
||||
|
||||
LoggingConfigurator(const LoggingConfigurator&);
|
||||
LoggingConfigurator& operator = (const LoggingConfigurator&);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_LoggingConfigurator_INCLUDED
|
||||
|
||||
@@ -1,74 +1,74 @@
|
||||
//
|
||||
// LoggingSubsystem.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/LoggingSubsystem.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Application
|
||||
// Module: LoggingSubsystem
|
||||
//
|
||||
// Definition of the LoggingSubsystem class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_LoggingSubsystem_INCLUDED
|
||||
#define Util_LoggingSubsystem_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Subsystem.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API LoggingSubsystem: public Subsystem
|
||||
/// The LoggingSubsystem class initializes the logging
|
||||
/// framework using the LoggingConfigurator.
|
||||
///
|
||||
/// It also sets the Application's logger to
|
||||
/// the logger specified by the "application.logger"
|
||||
/// property, or to "Application" if the property
|
||||
/// is not specified.
|
||||
{
|
||||
public:
|
||||
LoggingSubsystem();
|
||||
const char* name() const;
|
||||
|
||||
protected:
|
||||
void initialize(Application& self);
|
||||
void uninitialize();
|
||||
~LoggingSubsystem();
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_LoggingSubsystem_INCLUDED
|
||||
//
|
||||
// LoggingSubsystem.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/LoggingSubsystem.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Application
|
||||
// Module: LoggingSubsystem
|
||||
//
|
||||
// Definition of the LoggingSubsystem class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_LoggingSubsystem_INCLUDED
|
||||
#define Util_LoggingSubsystem_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Subsystem.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API LoggingSubsystem: public Subsystem
|
||||
/// The LoggingSubsystem class initializes the logging
|
||||
/// framework using the LoggingConfigurator.
|
||||
///
|
||||
/// It also sets the Application's logger to
|
||||
/// the logger specified by the "application.logger"
|
||||
/// property, or to "Application" if the property
|
||||
/// is not specified.
|
||||
{
|
||||
public:
|
||||
LoggingSubsystem();
|
||||
const char* name() const;
|
||||
|
||||
protected:
|
||||
void initialize(Application& self);
|
||||
void uninitialize();
|
||||
~LoggingSubsystem();
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_LoggingSubsystem_INCLUDED
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
//
|
||||
// MapConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/MapConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: MapConfiguration
|
||||
//
|
||||
// Definition of the MapConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_MapConfiguration_INCLUDED
|
||||
#define Util_MapConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API MapConfiguration: public AbstractConfiguration
|
||||
/// An implementation of AbstractConfiguration that stores configuration data in a map.
|
||||
{
|
||||
public:
|
||||
MapConfiguration();
|
||||
/// Creates an empty MapConfiguration.
|
||||
|
||||
void clear();
|
||||
/// Clears the configuration.
|
||||
|
||||
protected:
|
||||
typedef std::map<std::string, std::string> StringMap;
|
||||
typedef StringMap::const_iterator iterator;
|
||||
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
~MapConfiguration();
|
||||
|
||||
iterator begin() const;
|
||||
iterator end() const;
|
||||
|
||||
private:
|
||||
StringMap _map;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_MapConfiguration_INCLUDED
|
||||
//
|
||||
// MapConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/MapConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: MapConfiguration
|
||||
//
|
||||
// Definition of the MapConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_MapConfiguration_INCLUDED
|
||||
#define Util_MapConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API MapConfiguration: public AbstractConfiguration
|
||||
/// An implementation of AbstractConfiguration that stores configuration data in a map.
|
||||
{
|
||||
public:
|
||||
MapConfiguration();
|
||||
/// Creates an empty MapConfiguration.
|
||||
|
||||
void clear();
|
||||
/// Clears the configuration.
|
||||
|
||||
protected:
|
||||
typedef std::map<std::string, std::string> StringMap;
|
||||
typedef StringMap::const_iterator iterator;
|
||||
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
~MapConfiguration();
|
||||
|
||||
iterator begin() const;
|
||||
iterator end() const;
|
||||
|
||||
private:
|
||||
StringMap _map;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_MapConfiguration_INCLUDED
|
||||
|
||||
@@ -1,354 +1,354 @@
|
||||
//
|
||||
// Option.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/Option.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: Option
|
||||
//
|
||||
// Definition of the Option class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_Option_INCLUDED
|
||||
#define Util_Option_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/OptionCallback.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Application;
|
||||
class Validator;
|
||||
class AbstractConfiguration;
|
||||
|
||||
|
||||
class Util_API Option
|
||||
/// This class represents and stores the properties
|
||||
/// of a command line option.
|
||||
///
|
||||
/// An option has a full name, an optional short name,
|
||||
/// a description (used for printing a usage statement),
|
||||
/// and an optional argument name.
|
||||
/// An option can be optional or required.
|
||||
/// An option can be repeatable, which means that it can
|
||||
/// be given more than once on the command line.
|
||||
///
|
||||
/// An option can be part of an option group. At most one
|
||||
/// option of each group may be specified on the command
|
||||
/// line.
|
||||
///
|
||||
/// An option can be bound to a configuration property.
|
||||
/// In this case, a configuration property will automatically
|
||||
/// receive the option's argument value.
|
||||
///
|
||||
/// A callback method can be specified for options. This method
|
||||
/// is called whenever an option is specified on the command line.
|
||||
///
|
||||
/// Option argument values can be automatically validated using a
|
||||
/// Validator.
|
||||
///
|
||||
/// Option instances are value objects.
|
||||
///
|
||||
/// Typcally, after construction, an Option object is immediately
|
||||
/// passed to an Options object.
|
||||
///
|
||||
/// An Option object can be created by chaining the constructor
|
||||
/// with any of the setter methods, as in the following example:
|
||||
///
|
||||
/// Option versionOpt("include", "I", "specify an include directory")
|
||||
/// .required(false)
|
||||
/// .repeatable(true)
|
||||
/// .argument("directory");
|
||||
{
|
||||
public:
|
||||
Option();
|
||||
/// Creates an empty Option.
|
||||
|
||||
Option(const Option& option);
|
||||
/// Creates an option from another one.
|
||||
|
||||
Option(const std::string& fullName, const std::string& shortName);
|
||||
/// Creates an option with the given properties.
|
||||
|
||||
Option(const std::string& fullName, const std::string& shortName, const std::string& description, bool required = false);
|
||||
/// Creates an option with the given properties.
|
||||
|
||||
Option(const std::string& fullName, const std::string& shortName, const std::string& description, bool required, const std::string& argName, bool argRequired = false);
|
||||
/// Creates an option with the given properties.
|
||||
|
||||
~Option();
|
||||
/// Destroys the Option.
|
||||
|
||||
Option& operator = (const Option& option);
|
||||
/// Assignment operator.
|
||||
|
||||
void swap(Option& option);
|
||||
/// Swaps the option with another one.
|
||||
|
||||
Option& shortName(const std::string& name);
|
||||
/// Sets the short name of the option.
|
||||
|
||||
Option& fullName(const std::string& name);
|
||||
/// Sets the full name of the option.
|
||||
|
||||
Option& description(const std::string& text);
|
||||
/// Sets the description of the option.
|
||||
|
||||
Option& required(bool flag);
|
||||
/// Sets whether the option is required (flag == true)
|
||||
/// or optional (flag == false).
|
||||
|
||||
Option& repeatable(bool flag);
|
||||
/// Sets whether the option can be specified more than once
|
||||
/// (flag == true) or at most once (flag == false).
|
||||
|
||||
Option& argument(const std::string& name, bool required = true);
|
||||
/// Specifies that the option takes an (optional or required)
|
||||
/// argument.
|
||||
|
||||
Option& noArgument();
|
||||
/// Specifies that the option does not take an argument (default).
|
||||
|
||||
Option& group(const std::string& group);
|
||||
/// Specifies the option group the option is part of.
|
||||
|
||||
Option& binding(const std::string& propertyName);
|
||||
/// Binds the option to the configuration property with the given name.
|
||||
///
|
||||
/// The configuration will automatically receive the option's argument.
|
||||
|
||||
Option& binding(const std::string& propertyName, AbstractConfiguration* pConfig);
|
||||
/// Binds the option to the configuration property with the given name,
|
||||
/// using the given AbstractConfiguration.
|
||||
///
|
||||
/// The configuration will automatically receive the option's argument.
|
||||
|
||||
Option& callback(const AbstractOptionCallback& cb);
|
||||
/// Binds the option to the given method.
|
||||
///
|
||||
/// The callback method will be called when the option
|
||||
/// has been specified on the command line.
|
||||
///
|
||||
/// Usage:
|
||||
/// callback(OptionCallback<MyApplication>(this, &MyApplication::myCallback));
|
||||
|
||||
Option& validator(Validator* pValidator);
|
||||
/// Sets the validator for the given option.
|
||||
///
|
||||
/// The Option takes ownership of the Validator and
|
||||
/// deletes it when it's no longer needed.
|
||||
|
||||
const std::string& shortName() const;
|
||||
/// Returns the short name of the option.
|
||||
|
||||
const std::string& fullName() const;
|
||||
/// Returns the full name of the option.
|
||||
|
||||
const std::string& description() const;
|
||||
/// Returns the description of the option.
|
||||
|
||||
bool required() const;
|
||||
/// Returns true if the option is required, false if not.
|
||||
|
||||
bool repeatable() const;
|
||||
/// Returns true if the option can be specified more than
|
||||
/// once, or false if at most once.
|
||||
|
||||
bool takesArgument() const;
|
||||
/// Returns true if the options takes an (optional) argument.
|
||||
|
||||
bool argumentRequired() const;
|
||||
/// Returns true if the argument is required.
|
||||
|
||||
const std::string& argumentName() const;
|
||||
/// Returns the argument name, if specified.
|
||||
|
||||
const std::string& group() const;
|
||||
/// Returns the option group the option is part of,
|
||||
/// or an empty string, if the option is not part of
|
||||
/// a group.
|
||||
|
||||
const std::string& binding() const;
|
||||
/// Returns the property name the option is bound to,
|
||||
/// or an empty string in case it is not bound.
|
||||
|
||||
AbstractOptionCallback* callback() const;
|
||||
/// Returns a pointer to the callback method for the option,
|
||||
/// or NULL if no callback has been specified.
|
||||
|
||||
Validator* validator() const;
|
||||
/// Returns the option's Validator, if one has been specified,
|
||||
/// or NULL otherwise.
|
||||
|
||||
AbstractConfiguration* config() const;
|
||||
/// Returns the configuration, if specified, or NULL otherwise.
|
||||
|
||||
bool matchesShort(const std::string& option) const;
|
||||
/// Returns true if the given option string matches the
|
||||
/// short name.
|
||||
///
|
||||
/// The first characters of the option string must match
|
||||
/// the short name of the option (case sensitive),
|
||||
/// or the option string must partially match the full
|
||||
/// name (case insensitive).
|
||||
|
||||
bool matchesFull(const std::string& option) const;
|
||||
/// Returns true if the given option string matches the
|
||||
/// full name.
|
||||
///
|
||||
/// The option string must match the full
|
||||
/// name (case insensitive).
|
||||
|
||||
bool matchesPartial(const std::string& option) const;
|
||||
/// Returns true if the given option string partially matches the
|
||||
/// full name.
|
||||
///
|
||||
/// The option string must partially match the full
|
||||
/// name (case insensitive).
|
||||
|
||||
void process(const std::string& option, std::string& arg) const;
|
||||
/// Verifies that the given option string matches the
|
||||
/// requirements of the option, and extracts the option argument,
|
||||
/// if present.
|
||||
///
|
||||
/// If the option string is okay and carries an argument,
|
||||
/// the argument is returned in arg.
|
||||
///
|
||||
/// Throws a MissingArgumentException if a required argument
|
||||
/// is missing. Throws an UnexpectedArgumentException if an
|
||||
/// argument has been found, but none is expected.
|
||||
|
||||
private:
|
||||
std::string _shortName;
|
||||
std::string _fullName;
|
||||
std::string _description;
|
||||
bool _required;
|
||||
bool _repeatable;
|
||||
std::string _argName;
|
||||
bool _argRequired;
|
||||
std::string _group;
|
||||
std::string _binding;
|
||||
Validator* _pValidator;
|
||||
AbstractOptionCallback* _pCallback;
|
||||
AbstractConfiguration* _pConfig;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline const std::string& Option::shortName() const
|
||||
{
|
||||
return _shortName;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::fullName() const
|
||||
{
|
||||
return _fullName;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::description() const
|
||||
{
|
||||
return _description;
|
||||
}
|
||||
|
||||
|
||||
inline bool Option::required() const
|
||||
{
|
||||
return _required;
|
||||
}
|
||||
|
||||
|
||||
inline bool Option::repeatable() const
|
||||
{
|
||||
return _repeatable;
|
||||
}
|
||||
|
||||
|
||||
inline bool Option::takesArgument() const
|
||||
{
|
||||
return !_argName.empty();
|
||||
}
|
||||
|
||||
|
||||
inline bool Option::argumentRequired() const
|
||||
{
|
||||
return _argRequired;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::argumentName() const
|
||||
{
|
||||
return _argName;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::group() const
|
||||
{
|
||||
return _group;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::binding() const
|
||||
{
|
||||
return _binding;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractOptionCallback* Option::callback() const
|
||||
{
|
||||
return _pCallback;
|
||||
}
|
||||
|
||||
|
||||
inline Validator* Option::validator() const
|
||||
{
|
||||
return _pValidator;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractConfiguration* Option::config() const
|
||||
{
|
||||
return _pConfig;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_Option_INCLUDED
|
||||
//
|
||||
// Option.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/Option.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: Option
|
||||
//
|
||||
// Definition of the Option class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_Option_INCLUDED
|
||||
#define Util_Option_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/OptionCallback.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Application;
|
||||
class Validator;
|
||||
class AbstractConfiguration;
|
||||
|
||||
|
||||
class Util_API Option
|
||||
/// This class represents and stores the properties
|
||||
/// of a command line option.
|
||||
///
|
||||
/// An option has a full name, an optional short name,
|
||||
/// a description (used for printing a usage statement),
|
||||
/// and an optional argument name.
|
||||
/// An option can be optional or required.
|
||||
/// An option can be repeatable, which means that it can
|
||||
/// be given more than once on the command line.
|
||||
///
|
||||
/// An option can be part of an option group. At most one
|
||||
/// option of each group may be specified on the command
|
||||
/// line.
|
||||
///
|
||||
/// An option can be bound to a configuration property.
|
||||
/// In this case, a configuration property will automatically
|
||||
/// receive the option's argument value.
|
||||
///
|
||||
/// A callback method can be specified for options. This method
|
||||
/// is called whenever an option is specified on the command line.
|
||||
///
|
||||
/// Option argument values can be automatically validated using a
|
||||
/// Validator.
|
||||
///
|
||||
/// Option instances are value objects.
|
||||
///
|
||||
/// Typcally, after construction, an Option object is immediately
|
||||
/// passed to an Options object.
|
||||
///
|
||||
/// An Option object can be created by chaining the constructor
|
||||
/// with any of the setter methods, as in the following example:
|
||||
///
|
||||
/// Option versionOpt("include", "I", "specify an include directory")
|
||||
/// .required(false)
|
||||
/// .repeatable(true)
|
||||
/// .argument("directory");
|
||||
{
|
||||
public:
|
||||
Option();
|
||||
/// Creates an empty Option.
|
||||
|
||||
Option(const Option& option);
|
||||
/// Creates an option from another one.
|
||||
|
||||
Option(const std::string& fullName, const std::string& shortName);
|
||||
/// Creates an option with the given properties.
|
||||
|
||||
Option(const std::string& fullName, const std::string& shortName, const std::string& description, bool required = false);
|
||||
/// Creates an option with the given properties.
|
||||
|
||||
Option(const std::string& fullName, const std::string& shortName, const std::string& description, bool required, const std::string& argName, bool argRequired = false);
|
||||
/// Creates an option with the given properties.
|
||||
|
||||
~Option();
|
||||
/// Destroys the Option.
|
||||
|
||||
Option& operator = (const Option& option);
|
||||
/// Assignment operator.
|
||||
|
||||
void swap(Option& option);
|
||||
/// Swaps the option with another one.
|
||||
|
||||
Option& shortName(const std::string& name);
|
||||
/// Sets the short name of the option.
|
||||
|
||||
Option& fullName(const std::string& name);
|
||||
/// Sets the full name of the option.
|
||||
|
||||
Option& description(const std::string& text);
|
||||
/// Sets the description of the option.
|
||||
|
||||
Option& required(bool flag);
|
||||
/// Sets whether the option is required (flag == true)
|
||||
/// or optional (flag == false).
|
||||
|
||||
Option& repeatable(bool flag);
|
||||
/// Sets whether the option can be specified more than once
|
||||
/// (flag == true) or at most once (flag == false).
|
||||
|
||||
Option& argument(const std::string& name, bool required = true);
|
||||
/// Specifies that the option takes an (optional or required)
|
||||
/// argument.
|
||||
|
||||
Option& noArgument();
|
||||
/// Specifies that the option does not take an argument (default).
|
||||
|
||||
Option& group(const std::string& group);
|
||||
/// Specifies the option group the option is part of.
|
||||
|
||||
Option& binding(const std::string& propertyName);
|
||||
/// Binds the option to the configuration property with the given name.
|
||||
///
|
||||
/// The configuration will automatically receive the option's argument.
|
||||
|
||||
Option& binding(const std::string& propertyName, AbstractConfiguration* pConfig);
|
||||
/// Binds the option to the configuration property with the given name,
|
||||
/// using the given AbstractConfiguration.
|
||||
///
|
||||
/// The configuration will automatically receive the option's argument.
|
||||
|
||||
Option& callback(const AbstractOptionCallback& cb);
|
||||
/// Binds the option to the given method.
|
||||
///
|
||||
/// The callback method will be called when the option
|
||||
/// has been specified on the command line.
|
||||
///
|
||||
/// Usage:
|
||||
/// callback(OptionCallback<MyApplication>(this, &MyApplication::myCallback));
|
||||
|
||||
Option& validator(Validator* pValidator);
|
||||
/// Sets the validator for the given option.
|
||||
///
|
||||
/// The Option takes ownership of the Validator and
|
||||
/// deletes it when it's no longer needed.
|
||||
|
||||
const std::string& shortName() const;
|
||||
/// Returns the short name of the option.
|
||||
|
||||
const std::string& fullName() const;
|
||||
/// Returns the full name of the option.
|
||||
|
||||
const std::string& description() const;
|
||||
/// Returns the description of the option.
|
||||
|
||||
bool required() const;
|
||||
/// Returns true if the option is required, false if not.
|
||||
|
||||
bool repeatable() const;
|
||||
/// Returns true if the option can be specified more than
|
||||
/// once, or false if at most once.
|
||||
|
||||
bool takesArgument() const;
|
||||
/// Returns true if the options takes an (optional) argument.
|
||||
|
||||
bool argumentRequired() const;
|
||||
/// Returns true if the argument is required.
|
||||
|
||||
const std::string& argumentName() const;
|
||||
/// Returns the argument name, if specified.
|
||||
|
||||
const std::string& group() const;
|
||||
/// Returns the option group the option is part of,
|
||||
/// or an empty string, if the option is not part of
|
||||
/// a group.
|
||||
|
||||
const std::string& binding() const;
|
||||
/// Returns the property name the option is bound to,
|
||||
/// or an empty string in case it is not bound.
|
||||
|
||||
AbstractOptionCallback* callback() const;
|
||||
/// Returns a pointer to the callback method for the option,
|
||||
/// or NULL if no callback has been specified.
|
||||
|
||||
Validator* validator() const;
|
||||
/// Returns the option's Validator, if one has been specified,
|
||||
/// or NULL otherwise.
|
||||
|
||||
AbstractConfiguration* config() const;
|
||||
/// Returns the configuration, if specified, or NULL otherwise.
|
||||
|
||||
bool matchesShort(const std::string& option) const;
|
||||
/// Returns true if the given option string matches the
|
||||
/// short name.
|
||||
///
|
||||
/// The first characters of the option string must match
|
||||
/// the short name of the option (case sensitive),
|
||||
/// or the option string must partially match the full
|
||||
/// name (case insensitive).
|
||||
|
||||
bool matchesFull(const std::string& option) const;
|
||||
/// Returns true if the given option string matches the
|
||||
/// full name.
|
||||
///
|
||||
/// The option string must match the full
|
||||
/// name (case insensitive).
|
||||
|
||||
bool matchesPartial(const std::string& option) const;
|
||||
/// Returns true if the given option string partially matches the
|
||||
/// full name.
|
||||
///
|
||||
/// The option string must partially match the full
|
||||
/// name (case insensitive).
|
||||
|
||||
void process(const std::string& option, std::string& arg) const;
|
||||
/// Verifies that the given option string matches the
|
||||
/// requirements of the option, and extracts the option argument,
|
||||
/// if present.
|
||||
///
|
||||
/// If the option string is okay and carries an argument,
|
||||
/// the argument is returned in arg.
|
||||
///
|
||||
/// Throws a MissingArgumentException if a required argument
|
||||
/// is missing. Throws an UnexpectedArgumentException if an
|
||||
/// argument has been found, but none is expected.
|
||||
|
||||
private:
|
||||
std::string _shortName;
|
||||
std::string _fullName;
|
||||
std::string _description;
|
||||
bool _required;
|
||||
bool _repeatable;
|
||||
std::string _argName;
|
||||
bool _argRequired;
|
||||
std::string _group;
|
||||
std::string _binding;
|
||||
Validator* _pValidator;
|
||||
AbstractOptionCallback* _pCallback;
|
||||
AbstractConfiguration* _pConfig;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
|
||||
inline const std::string& Option::shortName() const
|
||||
{
|
||||
return _shortName;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::fullName() const
|
||||
{
|
||||
return _fullName;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::description() const
|
||||
{
|
||||
return _description;
|
||||
}
|
||||
|
||||
|
||||
inline bool Option::required() const
|
||||
{
|
||||
return _required;
|
||||
}
|
||||
|
||||
|
||||
inline bool Option::repeatable() const
|
||||
{
|
||||
return _repeatable;
|
||||
}
|
||||
|
||||
|
||||
inline bool Option::takesArgument() const
|
||||
{
|
||||
return !_argName.empty();
|
||||
}
|
||||
|
||||
|
||||
inline bool Option::argumentRequired() const
|
||||
{
|
||||
return _argRequired;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::argumentName() const
|
||||
{
|
||||
return _argName;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::group() const
|
||||
{
|
||||
return _group;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& Option::binding() const
|
||||
{
|
||||
return _binding;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractOptionCallback* Option::callback() const
|
||||
{
|
||||
return _pCallback;
|
||||
}
|
||||
|
||||
|
||||
inline Validator* Option::validator() const
|
||||
{
|
||||
return _pValidator;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractConfiguration* Option::config() const
|
||||
{
|
||||
return _pConfig;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_Option_INCLUDED
|
||||
|
||||
@@ -1,131 +1,131 @@
|
||||
//
|
||||
// OptionCallback.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/OptionCallback.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: OptionCallback
|
||||
//
|
||||
// Definition of the OptionCallback class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_OptionCallback_INCLUDED
|
||||
#define Util_OptionCallback_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API AbstractOptionCallback
|
||||
/// Base class for OptionCallback.
|
||||
{
|
||||
public:
|
||||
virtual void invoke(const std::string& name, const std::string& value) const = 0;
|
||||
/// Invokes the callback member function.
|
||||
|
||||
virtual AbstractOptionCallback* clone() const = 0;
|
||||
/// Creates and returns a copy of the object.
|
||||
|
||||
virtual ~AbstractOptionCallback();
|
||||
/// Destroys the AbstractOptionCallback.
|
||||
|
||||
protected:
|
||||
AbstractOptionCallback();
|
||||
AbstractOptionCallback(const AbstractOptionCallback&);
|
||||
};
|
||||
|
||||
|
||||
template <class C>
|
||||
class OptionCallback: public AbstractOptionCallback
|
||||
/// This class is used as an argument to Option::callback().
|
||||
///
|
||||
/// It stores a pointer to an object and a pointer to a member
|
||||
/// function of the object's class.
|
||||
{
|
||||
public:
|
||||
typedef void (C::*Callback)(const std::string& name, const std::string& value);
|
||||
|
||||
OptionCallback(C* pObject, Callback method):
|
||||
_pObject(pObject),
|
||||
_method(method)
|
||||
/// Creates the OptionCallback for the given object and member function.
|
||||
{
|
||||
poco_check_ptr (pObject);
|
||||
}
|
||||
|
||||
OptionCallback(const OptionCallback& cb):
|
||||
AbstractOptionCallback(cb),
|
||||
_pObject(cb._pObject),
|
||||
_method(cb._method)
|
||||
/// Creates an OptionCallback from another one.
|
||||
{
|
||||
}
|
||||
|
||||
~OptionCallback()
|
||||
/// Destroys the OptionCallback.
|
||||
{
|
||||
}
|
||||
|
||||
OptionCallback& operator = (const OptionCallback& cb)
|
||||
{
|
||||
if (&cb != this)
|
||||
{
|
||||
this->_pObject = cb._pObject;
|
||||
this->_method = cb._method;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void invoke(const std::string& name, const std::string& value) const
|
||||
{
|
||||
(_pObject->*_method)(name, value);
|
||||
}
|
||||
|
||||
AbstractOptionCallback* clone() const
|
||||
{
|
||||
return new OptionCallback(_pObject, _method);
|
||||
}
|
||||
|
||||
private:
|
||||
OptionCallback();
|
||||
|
||||
C* _pObject;
|
||||
Callback _method;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_OptionCallback_INCLUDED
|
||||
//
|
||||
// OptionCallback.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/OptionCallback.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: OptionCallback
|
||||
//
|
||||
// Definition of the OptionCallback class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_OptionCallback_INCLUDED
|
||||
#define Util_OptionCallback_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API AbstractOptionCallback
|
||||
/// Base class for OptionCallback.
|
||||
{
|
||||
public:
|
||||
virtual void invoke(const std::string& name, const std::string& value) const = 0;
|
||||
/// Invokes the callback member function.
|
||||
|
||||
virtual AbstractOptionCallback* clone() const = 0;
|
||||
/// Creates and returns a copy of the object.
|
||||
|
||||
virtual ~AbstractOptionCallback();
|
||||
/// Destroys the AbstractOptionCallback.
|
||||
|
||||
protected:
|
||||
AbstractOptionCallback();
|
||||
AbstractOptionCallback(const AbstractOptionCallback&);
|
||||
};
|
||||
|
||||
|
||||
template <class C>
|
||||
class OptionCallback: public AbstractOptionCallback
|
||||
/// This class is used as an argument to Option::callback().
|
||||
///
|
||||
/// It stores a pointer to an object and a pointer to a member
|
||||
/// function of the object's class.
|
||||
{
|
||||
public:
|
||||
typedef void (C::*Callback)(const std::string& name, const std::string& value);
|
||||
|
||||
OptionCallback(C* pObject, Callback method):
|
||||
_pObject(pObject),
|
||||
_method(method)
|
||||
/// Creates the OptionCallback for the given object and member function.
|
||||
{
|
||||
poco_check_ptr (pObject);
|
||||
}
|
||||
|
||||
OptionCallback(const OptionCallback& cb):
|
||||
AbstractOptionCallback(cb),
|
||||
_pObject(cb._pObject),
|
||||
_method(cb._method)
|
||||
/// Creates an OptionCallback from another one.
|
||||
{
|
||||
}
|
||||
|
||||
~OptionCallback()
|
||||
/// Destroys the OptionCallback.
|
||||
{
|
||||
}
|
||||
|
||||
OptionCallback& operator = (const OptionCallback& cb)
|
||||
{
|
||||
if (&cb != this)
|
||||
{
|
||||
this->_pObject = cb._pObject;
|
||||
this->_method = cb._method;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void invoke(const std::string& name, const std::string& value) const
|
||||
{
|
||||
(_pObject->*_method)(name, value);
|
||||
}
|
||||
|
||||
AbstractOptionCallback* clone() const
|
||||
{
|
||||
return new OptionCallback(_pObject, _method);
|
||||
}
|
||||
|
||||
private:
|
||||
OptionCallback();
|
||||
|
||||
C* _pObject;
|
||||
Callback _method;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_OptionCallback_INCLUDED
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
//
|
||||
// OptionException.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/OptionException.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: OptionException
|
||||
//
|
||||
// Definition of the OptionException class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_OptionException_INCLUDED
|
||||
#define Util_OptionException_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(Util_API, OptionException, Poco::DataException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, UnknownOptionException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, AmbiguousOptionException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, MissingOptionException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, MissingArgumentException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, InvalidArgumentException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, UnexpectedArgumentException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, IncompatibleOptionsException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, DuplicateOptionException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, EmptyOptionException, OptionException)
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_OptionException_INCLUDED
|
||||
//
|
||||
// OptionException.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/OptionException.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: OptionException
|
||||
//
|
||||
// Definition of the OptionException class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_OptionException_INCLUDED
|
||||
#define Util_OptionException_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(Util_API, OptionException, Poco::DataException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, UnknownOptionException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, AmbiguousOptionException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, MissingOptionException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, MissingArgumentException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, InvalidArgumentException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, UnexpectedArgumentException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, IncompatibleOptionsException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, DuplicateOptionException, OptionException)
|
||||
POCO_DECLARE_EXCEPTION(Util_API, EmptyOptionException, OptionException)
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_OptionException_INCLUDED
|
||||
|
||||
@@ -1,159 +1,159 @@
|
||||
//
|
||||
// OptionProcessor.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/OptionProcessor.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: OptionProcessor
|
||||
//
|
||||
// Definition of the OptionProcessor class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_OptionProcessor_INCLUDED
|
||||
#define Util_OptionProcessor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class OptionSet;
|
||||
|
||||
|
||||
class Util_API OptionProcessor
|
||||
/// An OptionProcessor is used to process the command line
|
||||
/// arguments of an application.
|
||||
///
|
||||
/// The process() method takes an argument from the command line.
|
||||
/// If that argument starts with an option prefix, the argument
|
||||
/// is further processed. Otherwise, the argument is ignored and
|
||||
/// false is returned. The argument must match one of the options
|
||||
/// given in the OptionSet that is passed to the OptionProcessor
|
||||
/// with the constructor. If an option is part of a group, at most
|
||||
/// one option of the group can be passed to the OptionProcessor.
|
||||
/// Otherwise an IncompatibleOptionsException is thrown.
|
||||
/// If the same option is given multiple times, but the option
|
||||
/// is not repeatable, a DuplicateOptionException is thrown.
|
||||
/// If the option is not recognized, a UnexpectedArgumentException
|
||||
/// is thrown.
|
||||
/// If the option requires an argument, but none is given, an
|
||||
/// MissingArgumentException is thrown.
|
||||
/// If no argument is expected, but one is present, a
|
||||
/// UnexpectedArgumentException is thrown.
|
||||
/// If a partial option name is ambiguous, an AmbiguousOptionException
|
||||
/// is thrown.
|
||||
///
|
||||
/// The OptionProcessor supports two modes: Unix mode and default mode.
|
||||
/// In Unix mode, the option prefix is a dash '-'. A dash must be followed
|
||||
/// by a short option name, or another dash, followed by a (partial)
|
||||
/// long option name.
|
||||
/// In default mode, the option prefix is a slash '/', followed by
|
||||
/// a (partial) long option name.
|
||||
/// If the special option '--' is encountered in Unix mode, all following
|
||||
/// options are ignored.
|
||||
///
|
||||
/// Option arguments can be specified in three ways. If a Unix short option
|
||||
/// ("-o") is given, the argument directly follows the option name, without
|
||||
/// any delimiting character or space ("-ovalue"). In default option mode, or if a
|
||||
/// Unix long option ("--option") is given, the option argument is
|
||||
/// delimited from the option name with either an equal sign ('=') or
|
||||
/// a colon (':'), as in "--option=value" or "/option:value". Finally,
|
||||
/// a required option argument can be specified on the command line after the
|
||||
/// option, delimited with a space, as in "--option value" or "-o value".
|
||||
/// The latter only works for required option arguments, not optional ones.
|
||||
{
|
||||
public:
|
||||
OptionProcessor(const OptionSet& options);
|
||||
/// Creates the OptionProcessor, using the given OptionSet.
|
||||
|
||||
~OptionProcessor();
|
||||
/// Destroys the OptionProcessor.
|
||||
|
||||
void setUnixStyle(bool flag);
|
||||
/// Enables (flag == true) or disables (flag == false) Unix-style
|
||||
/// option processing.
|
||||
///
|
||||
/// If Unix-style processing is enabled, options are expected to
|
||||
/// begin with a single or a double dash ('-' or '--', respectively).
|
||||
/// A single dash must be followed by a short option name. A double
|
||||
/// dash must be followed by a (partial) full option name.
|
||||
///
|
||||
/// If Unix-style processing is disabled, options are expected to
|
||||
/// begin with a slash ('/'), followed by a (partial) full option name.
|
||||
|
||||
bool isUnixStyle() const;
|
||||
/// Returns true iff Unix-style option processing is enabled.
|
||||
|
||||
bool process(const std::string& argument, std::string& optionName, std::string& optionArg);
|
||||
/// Examines and processes the given command line argument.
|
||||
///
|
||||
/// If the argument begins with an option prefix, the option is processed
|
||||
/// and true is returned. The full option name is stored in optionName and the
|
||||
/// option argument, if present, is stored in optionArg.
|
||||
///
|
||||
/// If the option does not begin with an option prefix, false is returned.
|
||||
|
||||
void checkRequired() const;
|
||||
/// Checks if all required options have been processed.
|
||||
///
|
||||
/// Does nothing if all required options have been processed.
|
||||
/// Throws a MissingOptionException otherwise.
|
||||
|
||||
private:
|
||||
bool processUnix(const std::string& argument, std::string& optionName, std::string& optionArg);
|
||||
bool processDefault(const std::string& argument, std::string& optionName, std::string& optionArg);
|
||||
bool processCommon(const std::string& option, bool isShort, std::string& optionName, std::string& optionArg);
|
||||
|
||||
const OptionSet& _options;
|
||||
bool _unixStyle;
|
||||
bool _ignore;
|
||||
std::set<std::string> _groups;
|
||||
std::set<std::string> _specifiedOptions;
|
||||
std::string _deferredOption;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline bool OptionProcessor::isUnixStyle() const
|
||||
{
|
||||
return _unixStyle;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_OptionProcessor_INCLUDED
|
||||
//
|
||||
// OptionProcessor.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/OptionProcessor.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: OptionProcessor
|
||||
//
|
||||
// Definition of the OptionProcessor class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_OptionProcessor_INCLUDED
|
||||
#define Util_OptionProcessor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class OptionSet;
|
||||
|
||||
|
||||
class Util_API OptionProcessor
|
||||
/// An OptionProcessor is used to process the command line
|
||||
/// arguments of an application.
|
||||
///
|
||||
/// The process() method takes an argument from the command line.
|
||||
/// If that argument starts with an option prefix, the argument
|
||||
/// is further processed. Otherwise, the argument is ignored and
|
||||
/// false is returned. The argument must match one of the options
|
||||
/// given in the OptionSet that is passed to the OptionProcessor
|
||||
/// with the constructor. If an option is part of a group, at most
|
||||
/// one option of the group can be passed to the OptionProcessor.
|
||||
/// Otherwise an IncompatibleOptionsException is thrown.
|
||||
/// If the same option is given multiple times, but the option
|
||||
/// is not repeatable, a DuplicateOptionException is thrown.
|
||||
/// If the option is not recognized, a UnexpectedArgumentException
|
||||
/// is thrown.
|
||||
/// If the option requires an argument, but none is given, an
|
||||
/// MissingArgumentException is thrown.
|
||||
/// If no argument is expected, but one is present, a
|
||||
/// UnexpectedArgumentException is thrown.
|
||||
/// If a partial option name is ambiguous, an AmbiguousOptionException
|
||||
/// is thrown.
|
||||
///
|
||||
/// The OptionProcessor supports two modes: Unix mode and default mode.
|
||||
/// In Unix mode, the option prefix is a dash '-'. A dash must be followed
|
||||
/// by a short option name, or another dash, followed by a (partial)
|
||||
/// long option name.
|
||||
/// In default mode, the option prefix is a slash '/', followed by
|
||||
/// a (partial) long option name.
|
||||
/// If the special option '--' is encountered in Unix mode, all following
|
||||
/// options are ignored.
|
||||
///
|
||||
/// Option arguments can be specified in three ways. If a Unix short option
|
||||
/// ("-o") is given, the argument directly follows the option name, without
|
||||
/// any delimiting character or space ("-ovalue"). In default option mode, or if a
|
||||
/// Unix long option ("--option") is given, the option argument is
|
||||
/// delimited from the option name with either an equal sign ('=') or
|
||||
/// a colon (':'), as in "--option=value" or "/option:value". Finally,
|
||||
/// a required option argument can be specified on the command line after the
|
||||
/// option, delimited with a space, as in "--option value" or "-o value".
|
||||
/// The latter only works for required option arguments, not optional ones.
|
||||
{
|
||||
public:
|
||||
OptionProcessor(const OptionSet& options);
|
||||
/// Creates the OptionProcessor, using the given OptionSet.
|
||||
|
||||
~OptionProcessor();
|
||||
/// Destroys the OptionProcessor.
|
||||
|
||||
void setUnixStyle(bool flag);
|
||||
/// Enables (flag == true) or disables (flag == false) Unix-style
|
||||
/// option processing.
|
||||
///
|
||||
/// If Unix-style processing is enabled, options are expected to
|
||||
/// begin with a single or a double dash ('-' or '--', respectively).
|
||||
/// A single dash must be followed by a short option name. A double
|
||||
/// dash must be followed by a (partial) full option name.
|
||||
///
|
||||
/// If Unix-style processing is disabled, options are expected to
|
||||
/// begin with a slash ('/'), followed by a (partial) full option name.
|
||||
|
||||
bool isUnixStyle() const;
|
||||
/// Returns true iff Unix-style option processing is enabled.
|
||||
|
||||
bool process(const std::string& argument, std::string& optionName, std::string& optionArg);
|
||||
/// Examines and processes the given command line argument.
|
||||
///
|
||||
/// If the argument begins with an option prefix, the option is processed
|
||||
/// and true is returned. The full option name is stored in optionName and the
|
||||
/// option argument, if present, is stored in optionArg.
|
||||
///
|
||||
/// If the option does not begin with an option prefix, false is returned.
|
||||
|
||||
void checkRequired() const;
|
||||
/// Checks if all required options have been processed.
|
||||
///
|
||||
/// Does nothing if all required options have been processed.
|
||||
/// Throws a MissingOptionException otherwise.
|
||||
|
||||
private:
|
||||
bool processUnix(const std::string& argument, std::string& optionName, std::string& optionArg);
|
||||
bool processDefault(const std::string& argument, std::string& optionName, std::string& optionArg);
|
||||
bool processCommon(const std::string& option, bool isShort, std::string& optionName, std::string& optionArg);
|
||||
|
||||
const OptionSet& _options;
|
||||
bool _unixStyle;
|
||||
bool _ignore;
|
||||
std::set<std::string> _groups;
|
||||
std::set<std::string> _specifiedOptions;
|
||||
std::string _deferredOption;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline bool OptionProcessor::isUnixStyle() const
|
||||
{
|
||||
return _unixStyle;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_OptionProcessor_INCLUDED
|
||||
|
||||
@@ -1,110 +1,110 @@
|
||||
//
|
||||
// OptionSet.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/OptionSet.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: OptionSet
|
||||
//
|
||||
// Definition of the OptionSet class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_OptionSet_INCLUDED
|
||||
#define Util_OptionSet_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Option.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API OptionSet
|
||||
/// A collection of Option objects.
|
||||
{
|
||||
public:
|
||||
typedef std::vector<Option> OptionVec;
|
||||
typedef OptionVec::const_iterator Iterator;
|
||||
|
||||
OptionSet();
|
||||
/// Creates the OptionSet.
|
||||
|
||||
OptionSet(const OptionSet& options);
|
||||
/// Creates an option set from another one.
|
||||
|
||||
~OptionSet();
|
||||
/// Destroys the OptionSet.
|
||||
|
||||
OptionSet& operator = (const OptionSet& options);
|
||||
/// Assignment operator.
|
||||
|
||||
void addOption(const Option& option);
|
||||
/// Adds an option to the collection.
|
||||
|
||||
bool hasOption(const std::string& name, bool matchShort = false) const;
|
||||
/// Returns a true iff an option with the given name exists.
|
||||
///
|
||||
/// The given name can either be a fully specified short name,
|
||||
/// or a partially specified full name. If a partial name
|
||||
/// matches more than one full name, false is returned.
|
||||
/// The name must either match the short or full name of an
|
||||
/// option. Comparison case sensitive for the short name and
|
||||
/// not case sensitive for the full name.
|
||||
|
||||
const Option& getOption(const std::string& name, bool matchShort = false) const;
|
||||
/// Returns a reference to the option with the given name.
|
||||
///
|
||||
/// The given name can either be a fully specified short name,
|
||||
/// or a partially specified full name.
|
||||
/// The name must either match the short or full name of an
|
||||
/// option. Comparison case sensitive for the short name and
|
||||
/// not case sensitive for the full name.
|
||||
/// Throws a NotFoundException if no matching option has been found.
|
||||
/// Throws an UnknownOptionException if a partial full name matches
|
||||
/// more than one option.
|
||||
|
||||
Iterator begin() const;
|
||||
/// Supports iterating over all options.
|
||||
|
||||
Iterator end() const;
|
||||
/// Supports iterating over all options.
|
||||
|
||||
private:
|
||||
OptionVec _options;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_OptionSet_INCLUDED
|
||||
//
|
||||
// OptionSet.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/OptionSet.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: OptionSet
|
||||
//
|
||||
// Definition of the OptionSet class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_OptionSet_INCLUDED
|
||||
#define Util_OptionSet_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Option.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API OptionSet
|
||||
/// A collection of Option objects.
|
||||
{
|
||||
public:
|
||||
typedef std::vector<Option> OptionVec;
|
||||
typedef OptionVec::const_iterator Iterator;
|
||||
|
||||
OptionSet();
|
||||
/// Creates the OptionSet.
|
||||
|
||||
OptionSet(const OptionSet& options);
|
||||
/// Creates an option set from another one.
|
||||
|
||||
~OptionSet();
|
||||
/// Destroys the OptionSet.
|
||||
|
||||
OptionSet& operator = (const OptionSet& options);
|
||||
/// Assignment operator.
|
||||
|
||||
void addOption(const Option& option);
|
||||
/// Adds an option to the collection.
|
||||
|
||||
bool hasOption(const std::string& name, bool matchShort = false) const;
|
||||
/// Returns a true iff an option with the given name exists.
|
||||
///
|
||||
/// The given name can either be a fully specified short name,
|
||||
/// or a partially specified full name. If a partial name
|
||||
/// matches more than one full name, false is returned.
|
||||
/// The name must either match the short or full name of an
|
||||
/// option. Comparison case sensitive for the short name and
|
||||
/// not case sensitive for the full name.
|
||||
|
||||
const Option& getOption(const std::string& name, bool matchShort = false) const;
|
||||
/// Returns a reference to the option with the given name.
|
||||
///
|
||||
/// The given name can either be a fully specified short name,
|
||||
/// or a partially specified full name.
|
||||
/// The name must either match the short or full name of an
|
||||
/// option. Comparison case sensitive for the short name and
|
||||
/// not case sensitive for the full name.
|
||||
/// Throws a NotFoundException if no matching option has been found.
|
||||
/// Throws an UnknownOptionException if a partial full name matches
|
||||
/// more than one option.
|
||||
|
||||
Iterator begin() const;
|
||||
/// Supports iterating over all options.
|
||||
|
||||
Iterator end() const;
|
||||
/// Supports iterating over all options.
|
||||
|
||||
private:
|
||||
OptionVec _options;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_OptionSet_INCLUDED
|
||||
|
||||
@@ -1,121 +1,121 @@
|
||||
//
|
||||
// PropertyFileConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/PropertyFileConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: PropertyFileConfiguration
|
||||
//
|
||||
// Definition of the PropertyFileConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_PropertyFileConfiguration_INCLUDED
|
||||
#define Util_PropertyFileConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/MapConfiguration.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API PropertyFileConfiguration: public MapConfiguration
|
||||
/// This implementation of a Configuration reads properties
|
||||
/// from a Java-style properties file.
|
||||
///
|
||||
/// The file syntax is implemented as follows.
|
||||
/// - a line starting with a hash '#' or exclamation mark '!' is treated as a comment and ignored
|
||||
/// - every other line denotes a property assignment in the form
|
||||
/// <key> = <value> or
|
||||
/// <key> : <value>
|
||||
///
|
||||
/// Keys and values may contain special characters represented by the following escape sequences:
|
||||
/// - \t: tab (0x09)
|
||||
/// - \n: line feed (0x0a)
|
||||
/// - \r: carriage return (0x0d)
|
||||
/// - \f: form feed (0x0c)
|
||||
///
|
||||
/// For every other sequence that starts with a backslash, the backslash is removed.
|
||||
/// Therefore, the sequence \a would just yield an 'a'.
|
||||
///
|
||||
/// A value can spread across multiple lines if the last character in a line (the character
|
||||
/// immediately before the carriage return or line feed character) is a single backslash.
|
||||
///
|
||||
/// Property names are case sensitive. Leading and trailing whitespace is
|
||||
/// removed from both keys and values. A property name can neither contain
|
||||
/// a colon ':' nor an equal sign '=' character.
|
||||
{
|
||||
public:
|
||||
PropertyFileConfiguration();
|
||||
/// Creates an empty PropertyFileConfiguration.
|
||||
|
||||
PropertyFileConfiguration(std::istream& istr);
|
||||
/// Creates an PropertyFileConfiguration and loads the configuration data
|
||||
/// from the given stream, which must be in properties file format.
|
||||
|
||||
PropertyFileConfiguration(const std::string& path);
|
||||
/// Creates an PropertyFileConfiguration and loads the configuration data
|
||||
/// from the given file, which must be in properties file format.
|
||||
|
||||
void load(std::istream& istr);
|
||||
/// Loads the configuration data from the given stream, which
|
||||
/// must be in properties file format.
|
||||
|
||||
void load(const std::string& path);
|
||||
/// Loads the configuration data from the given file, which
|
||||
/// must be in properties file format.
|
||||
|
||||
void save(std::ostream& ostr) const;
|
||||
/// Writes the configuration data to the given stream.
|
||||
///
|
||||
/// The data is written as a sequence of statements in the form
|
||||
/// <key>: <value>
|
||||
/// separated by a newline character.
|
||||
|
||||
void save(const std::string& path) const;
|
||||
/// Writes the configuration data to the given file.
|
||||
|
||||
protected:
|
||||
~PropertyFileConfiguration();
|
||||
|
||||
private:
|
||||
void parseLine(std::istream& istr);
|
||||
static int readChar(std::istream& istr);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_PropertyFileConfiguration_INCLUDED
|
||||
//
|
||||
// PropertyFileConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/PropertyFileConfiguration.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: PropertyFileConfiguration
|
||||
//
|
||||
// Definition of the PropertyFileConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_PropertyFileConfiguration_INCLUDED
|
||||
#define Util_PropertyFileConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/MapConfiguration.h"
|
||||
#include <istream>
|
||||
#include <ostream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API PropertyFileConfiguration: public MapConfiguration
|
||||
/// This implementation of a Configuration reads properties
|
||||
/// from a Java-style properties file.
|
||||
///
|
||||
/// The file syntax is implemented as follows.
|
||||
/// - a line starting with a hash '#' or exclamation mark '!' is treated as a comment and ignored
|
||||
/// - every other line denotes a property assignment in the form
|
||||
/// <key> = <value> or
|
||||
/// <key> : <value>
|
||||
///
|
||||
/// Keys and values may contain special characters represented by the following escape sequences:
|
||||
/// - \t: tab (0x09)
|
||||
/// - \n: line feed (0x0a)
|
||||
/// - \r: carriage return (0x0d)
|
||||
/// - \f: form feed (0x0c)
|
||||
///
|
||||
/// For every other sequence that starts with a backslash, the backslash is removed.
|
||||
/// Therefore, the sequence \a would just yield an 'a'.
|
||||
///
|
||||
/// A value can spread across multiple lines if the last character in a line (the character
|
||||
/// immediately before the carriage return or line feed character) is a single backslash.
|
||||
///
|
||||
/// Property names are case sensitive. Leading and trailing whitespace is
|
||||
/// removed from both keys and values. A property name can neither contain
|
||||
/// a colon ':' nor an equal sign '=' character.
|
||||
{
|
||||
public:
|
||||
PropertyFileConfiguration();
|
||||
/// Creates an empty PropertyFileConfiguration.
|
||||
|
||||
PropertyFileConfiguration(std::istream& istr);
|
||||
/// Creates an PropertyFileConfiguration and loads the configuration data
|
||||
/// from the given stream, which must be in properties file format.
|
||||
|
||||
PropertyFileConfiguration(const std::string& path);
|
||||
/// Creates an PropertyFileConfiguration and loads the configuration data
|
||||
/// from the given file, which must be in properties file format.
|
||||
|
||||
void load(std::istream& istr);
|
||||
/// Loads the configuration data from the given stream, which
|
||||
/// must be in properties file format.
|
||||
|
||||
void load(const std::string& path);
|
||||
/// Loads the configuration data from the given file, which
|
||||
/// must be in properties file format.
|
||||
|
||||
void save(std::ostream& ostr) const;
|
||||
/// Writes the configuration data to the given stream.
|
||||
///
|
||||
/// The data is written as a sequence of statements in the form
|
||||
/// <key>: <value>
|
||||
/// separated by a newline character.
|
||||
|
||||
void save(const std::string& path) const;
|
||||
/// Writes the configuration data to the given file.
|
||||
|
||||
protected:
|
||||
~PropertyFileConfiguration();
|
||||
|
||||
private:
|
||||
void parseLine(std::istream& istr);
|
||||
static int readChar(std::istream& istr);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_PropertyFileConfiguration_INCLUDED
|
||||
|
||||
@@ -1,76 +1,76 @@
|
||||
//
|
||||
// RegExpValidator.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/RegExpValidator.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: RegExpValidator
|
||||
//
|
||||
// Definition of the RegExpValidator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_RegExpValidator_INCLUDED
|
||||
#define Util_RegExpValidator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Validator.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API RegExpValidator: public Validator
|
||||
/// This validator matches the option value against
|
||||
/// a regular expression.
|
||||
{
|
||||
public:
|
||||
RegExpValidator(const std::string& regexp);
|
||||
/// Creates the RegExpValidator, using the given regular expression.
|
||||
|
||||
~RegExpValidator();
|
||||
/// Destroys the RegExpValidator.
|
||||
|
||||
void validate(const Option& option, const std::string& value);
|
||||
/// Validates the value for the given option by
|
||||
/// matching it with the regular expression.
|
||||
|
||||
private:
|
||||
RegExpValidator();
|
||||
|
||||
std::string _regexp;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_RegExpValidator_INCLUDED
|
||||
//
|
||||
// RegExpValidator.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/RegExpValidator.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: RegExpValidator
|
||||
//
|
||||
// Definition of the RegExpValidator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_RegExpValidator_INCLUDED
|
||||
#define Util_RegExpValidator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Validator.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API RegExpValidator: public Validator
|
||||
/// This validator matches the option value against
|
||||
/// a regular expression.
|
||||
{
|
||||
public:
|
||||
RegExpValidator(const std::string& regexp);
|
||||
/// Creates the RegExpValidator, using the given regular expression.
|
||||
|
||||
~RegExpValidator();
|
||||
/// Destroys the RegExpValidator.
|
||||
|
||||
void validate(const Option& option, const std::string& value);
|
||||
/// Validates the value for the given option by
|
||||
/// matching it with the regular expression.
|
||||
|
||||
private:
|
||||
RegExpValidator();
|
||||
|
||||
std::string _regexp;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_RegExpValidator_INCLUDED
|
||||
|
||||
@@ -1,281 +1,281 @@
|
||||
//
|
||||
// ServerApplication.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/ServerApplication.h#3 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Application
|
||||
// Module: ServerApplication
|
||||
//
|
||||
// Definition of the ServerApplication class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_ServerApplication_INCLUDED
|
||||
#define Util_ServerApplication_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Application.h"
|
||||
#include "Poco/Event.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "Poco/NamedEvent.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API ServerApplication: public Application
|
||||
/// A subclass of the Application class that is used
|
||||
/// for implementing server applications.
|
||||
///
|
||||
/// A ServerApplication allows for the application
|
||||
/// to run as a Windows service or as a Unix daemon
|
||||
/// without the need to add extra code.
|
||||
///
|
||||
/// For a ServerApplication to work both from the command line
|
||||
/// and as a daemon or service, a few rules must be met:
|
||||
/// - Subsystems must be registered in the constructor.
|
||||
/// - All non-trivial initializations must be made in the
|
||||
/// initialize() method.
|
||||
/// - At the end of the main() method, waitForTerminationRequest()
|
||||
/// should be called.
|
||||
/// - New threads must only be created in initialize() or main() or
|
||||
/// methods called from there, but not in the application class'
|
||||
/// constructor or in the constructor of instance variables.
|
||||
/// The reason for this is that fork() will be called in order to
|
||||
/// create the daemon process, and threads created prior to calling
|
||||
/// fork() won't be taken over to the daemon process.
|
||||
/// - The main(argc, argv) function must look as follows:
|
||||
///
|
||||
/// int main(int argc, char** argv)
|
||||
/// {
|
||||
/// MyServerApplication app;
|
||||
/// return app.run(argc, argv);
|
||||
/// }
|
||||
///
|
||||
/// The POCO_SERVER_MAIN macro can be used to implement main(argc, argv).
|
||||
/// If POCO has been built with POCO_WIN32_UTF8, POCO_SERVER_MAIN supports
|
||||
/// Unicode command line arguments.
|
||||
///
|
||||
/// On Windows platforms, an application built on top of the
|
||||
/// ServerApplication class can be run both from the command line
|
||||
/// or as a service.
|
||||
///
|
||||
/// To run an application as a Windows service, it must be registered
|
||||
/// with the Windows Service Control Manager (SCM). To do this, the application
|
||||
/// can be started from the command line, with the /registerService option
|
||||
/// specified. This causes the application to register itself with the
|
||||
/// SCM, and then exit. Similarly, an application registered as a service can
|
||||
/// be unregistered, by specifying the /unregisterService option.
|
||||
/// The file name of the application executable (excluding the .exe suffix)
|
||||
/// is used as the service name. Additionally, a more user-friendly name can be
|
||||
/// specified, using the /displayName option (e.g., /displayName="Demo Service")
|
||||
/// and a service description can be added with the /description option.
|
||||
/// The startup mode (automatic or manual) for the service can be specified
|
||||
/// with the /startup option.
|
||||
///
|
||||
/// An application can determine whether it is running as a service by checking
|
||||
/// for the "application.runAsService" configuration property.
|
||||
///
|
||||
/// if (config().getBool("application.runAsService", false))
|
||||
/// {
|
||||
/// // do service specific things
|
||||
/// }
|
||||
///
|
||||
/// Note that the working directory for an application running as a service
|
||||
/// is the Windows system directory (e.g., C:\Windows\system32). Take this
|
||||
/// into account when working with relative filesystem paths. Also, services
|
||||
/// run under a different user account, so an application that works when
|
||||
/// started from the command line may fail to run as a service if it depends
|
||||
/// on a certain environment (e.g., the PATH environment variable).
|
||||
///
|
||||
/// An application registered as a Windows service can be started
|
||||
/// with the NET START <name> command and stopped with the NET STOP <name>
|
||||
/// command. Alternatively, the Services MMC applet can be used.
|
||||
///
|
||||
/// On Unix platforms, an application built on top of the ServerApplication
|
||||
/// class can be optionally run as a daemon by giving the --daemon
|
||||
/// command line option. A daemon, when launched, immediately
|
||||
/// forks off a background process that does the actual work. After launching
|
||||
/// the background process, the foreground process exits.
|
||||
///
|
||||
/// After the initialization is complete, but before entering the main() method,
|
||||
/// the current working directory for the daemon process is changed to the root
|
||||
/// directory ("/"), as it is common practice for daemon processes. Therefore, be
|
||||
/// careful when working with files, as relative paths may not point to where
|
||||
/// you expect them point to.
|
||||
///
|
||||
/// An application can determine whether it is running as a daemon by checking
|
||||
/// for the "application.runAsDaemon" configuration property.
|
||||
///
|
||||
/// if (config().getBool("application.runAsDaemon", false))
|
||||
/// {
|
||||
/// // do daemon specific things
|
||||
/// }
|
||||
///
|
||||
/// When running as a daemon, specifying the --pidfile option (e.g.,
|
||||
/// --pidfile=/var/run/sample.pid) may be useful to record the process ID of
|
||||
/// the daemon in a file. The PID file will be removed when the daemon process
|
||||
/// terminates (but not, if it crashes).
|
||||
{
|
||||
public:
|
||||
ServerApplication();
|
||||
/// Creates the ServerApplication.
|
||||
|
||||
~ServerApplication();
|
||||
/// Destroys the ServerApplication.
|
||||
|
||||
bool isInteractive() const;
|
||||
/// Returns true if the application runs from the command line.
|
||||
/// Returns false if the application runs as a Unix daemon
|
||||
/// or Windows service.
|
||||
|
||||
int run(int argc, char** argv);
|
||||
/// Runs the application by performing additional initializations
|
||||
/// and calling the main() method.
|
||||
|
||||
int run(const std::vector<std::string>& args);
|
||||
/// Runs the application by performing additional initializations
|
||||
/// and calling the main() method.
|
||||
|
||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||
int run(int argc, wchar_t** argv);
|
||||
/// Runs the application by performing additional initializations
|
||||
/// and calling the main() method.
|
||||
///
|
||||
/// This Windows-specific version of init is used for passing
|
||||
/// Unicode command line arguments from wmain().
|
||||
#endif
|
||||
|
||||
static void terminate();
|
||||
/// Sends a friendly termination request to the application.
|
||||
/// If the application's main thread is waiting in
|
||||
/// waitForTerminationRequest(), this method will return
|
||||
/// and the application can shut down.
|
||||
|
||||
protected:
|
||||
int run();
|
||||
void waitForTerminationRequest();
|
||||
#if !defined(_WIN32_WCE)
|
||||
void defineOptions(OptionSet& options);
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if defined(POCO_VXWORKS)
|
||||
static Poco::Event _terminate;
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
void handleDaemon(const std::string& name, const std::string& value);
|
||||
void handlePidFile(const std::string& name, const std::string& value);
|
||||
bool isDaemon(int argc, char** argv);
|
||||
void beDaemon();
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#if !defined(_WIN32_WCE)
|
||||
enum Action
|
||||
{
|
||||
SRV_RUN,
|
||||
SRV_REGISTER,
|
||||
SRV_UNREGISTER
|
||||
};
|
||||
static BOOL __stdcall ConsoleCtrlHandler(DWORD ctrlType);
|
||||
static void __stdcall ServiceControlHandler(DWORD control);
|
||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||
static void __stdcall ServiceMain(DWORD argc, LPWSTR* argv);
|
||||
#else
|
||||
static void __stdcall ServiceMain(DWORD argc, LPTSTR* argv);
|
||||
#endif
|
||||
|
||||
bool hasConsole();
|
||||
bool isService();
|
||||
void beService();
|
||||
void registerService();
|
||||
void unregisterService();
|
||||
void handleRegisterService(const std::string& name, const std::string& value);
|
||||
void handleUnregisterService(const std::string& name, const std::string& value);
|
||||
void handleDisplayName(const std::string& name, const std::string& value);
|
||||
void handleDescription(const std::string& name, const std::string& value);
|
||||
void handleStartup(const std::string& name, const std::string& value);
|
||||
|
||||
Action _action;
|
||||
std::string _displayName;
|
||||
std::string _description;
|
||||
std::string _startup;
|
||||
|
||||
static Poco::Event _terminated;
|
||||
static SERVICE_STATUS _serviceStatus;
|
||||
static SERVICE_STATUS_HANDLE _serviceStatusHandle;
|
||||
#endif // _WIN32_WCE
|
||||
static Poco::NamedEvent _terminate;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
//
|
||||
// Macro to implement main()
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_WIN32_UTF8)
|
||||
#define POCO_SERVER_MAIN(App) \
|
||||
int wmain(int argc, wchar_t** argv) \
|
||||
{ \
|
||||
App app; \
|
||||
return app.run(argc, argv); \
|
||||
}
|
||||
#elif defined(POCO_VXWORKS)
|
||||
#define POCO_SERVER_MAIN(App) \
|
||||
int pocoSrvMain(const char* appName, ...) \
|
||||
{ \
|
||||
std::vector<std::string> args; \
|
||||
args.push_back(std::string(appName)); \
|
||||
va_list vargs; \
|
||||
va_start(vargs, appName); \
|
||||
const char* arg = va_arg(vargs, const char*); \
|
||||
while (arg) \
|
||||
{ \
|
||||
args.push_back(std::string(arg)); \
|
||||
arg = va_arg(vargs, const char*); \
|
||||
} \
|
||||
va_end(vargs); \
|
||||
App app; \
|
||||
return app.run(args); \
|
||||
}
|
||||
#else
|
||||
#define POCO_SERVER_MAIN(App) \
|
||||
int main(int argc, char** argv) \
|
||||
{ \
|
||||
App app; \
|
||||
return app.run(argc, argv); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // Util_ServerApplication_INCLUDED
|
||||
//
|
||||
// ServerApplication.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/ServerApplication.h#3 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Application
|
||||
// Module: ServerApplication
|
||||
//
|
||||
// Definition of the ServerApplication class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_ServerApplication_INCLUDED
|
||||
#define Util_ServerApplication_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/Application.h"
|
||||
#include "Poco/Event.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "Poco/NamedEvent.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API ServerApplication: public Application
|
||||
/// A subclass of the Application class that is used
|
||||
/// for implementing server applications.
|
||||
///
|
||||
/// A ServerApplication allows for the application
|
||||
/// to run as a Windows service or as a Unix daemon
|
||||
/// without the need to add extra code.
|
||||
///
|
||||
/// For a ServerApplication to work both from the command line
|
||||
/// and as a daemon or service, a few rules must be met:
|
||||
/// - Subsystems must be registered in the constructor.
|
||||
/// - All non-trivial initializations must be made in the
|
||||
/// initialize() method.
|
||||
/// - At the end of the main() method, waitForTerminationRequest()
|
||||
/// should be called.
|
||||
/// - New threads must only be created in initialize() or main() or
|
||||
/// methods called from there, but not in the application class'
|
||||
/// constructor or in the constructor of instance variables.
|
||||
/// The reason for this is that fork() will be called in order to
|
||||
/// create the daemon process, and threads created prior to calling
|
||||
/// fork() won't be taken over to the daemon process.
|
||||
/// - The main(argc, argv) function must look as follows:
|
||||
///
|
||||
/// int main(int argc, char** argv)
|
||||
/// {
|
||||
/// MyServerApplication app;
|
||||
/// return app.run(argc, argv);
|
||||
/// }
|
||||
///
|
||||
/// The POCO_SERVER_MAIN macro can be used to implement main(argc, argv).
|
||||
/// If POCO has been built with POCO_WIN32_UTF8, POCO_SERVER_MAIN supports
|
||||
/// Unicode command line arguments.
|
||||
///
|
||||
/// On Windows platforms, an application built on top of the
|
||||
/// ServerApplication class can be run both from the command line
|
||||
/// or as a service.
|
||||
///
|
||||
/// To run an application as a Windows service, it must be registered
|
||||
/// with the Windows Service Control Manager (SCM). To do this, the application
|
||||
/// can be started from the command line, with the /registerService option
|
||||
/// specified. This causes the application to register itself with the
|
||||
/// SCM, and then exit. Similarly, an application registered as a service can
|
||||
/// be unregistered, by specifying the /unregisterService option.
|
||||
/// The file name of the application executable (excluding the .exe suffix)
|
||||
/// is used as the service name. Additionally, a more user-friendly name can be
|
||||
/// specified, using the /displayName option (e.g., /displayName="Demo Service")
|
||||
/// and a service description can be added with the /description option.
|
||||
/// The startup mode (automatic or manual) for the service can be specified
|
||||
/// with the /startup option.
|
||||
///
|
||||
/// An application can determine whether it is running as a service by checking
|
||||
/// for the "application.runAsService" configuration property.
|
||||
///
|
||||
/// if (config().getBool("application.runAsService", false))
|
||||
/// {
|
||||
/// // do service specific things
|
||||
/// }
|
||||
///
|
||||
/// Note that the working directory for an application running as a service
|
||||
/// is the Windows system directory (e.g., C:\Windows\system32). Take this
|
||||
/// into account when working with relative filesystem paths. Also, services
|
||||
/// run under a different user account, so an application that works when
|
||||
/// started from the command line may fail to run as a service if it depends
|
||||
/// on a certain environment (e.g., the PATH environment variable).
|
||||
///
|
||||
/// An application registered as a Windows service can be started
|
||||
/// with the NET START <name> command and stopped with the NET STOP <name>
|
||||
/// command. Alternatively, the Services MMC applet can be used.
|
||||
///
|
||||
/// On Unix platforms, an application built on top of the ServerApplication
|
||||
/// class can be optionally run as a daemon by giving the --daemon
|
||||
/// command line option. A daemon, when launched, immediately
|
||||
/// forks off a background process that does the actual work. After launching
|
||||
/// the background process, the foreground process exits.
|
||||
///
|
||||
/// After the initialization is complete, but before entering the main() method,
|
||||
/// the current working directory for the daemon process is changed to the root
|
||||
/// directory ("/"), as it is common practice for daemon processes. Therefore, be
|
||||
/// careful when working with files, as relative paths may not point to where
|
||||
/// you expect them point to.
|
||||
///
|
||||
/// An application can determine whether it is running as a daemon by checking
|
||||
/// for the "application.runAsDaemon" configuration property.
|
||||
///
|
||||
/// if (config().getBool("application.runAsDaemon", false))
|
||||
/// {
|
||||
/// // do daemon specific things
|
||||
/// }
|
||||
///
|
||||
/// When running as a daemon, specifying the --pidfile option (e.g.,
|
||||
/// --pidfile=/var/run/sample.pid) may be useful to record the process ID of
|
||||
/// the daemon in a file. The PID file will be removed when the daemon process
|
||||
/// terminates (but not, if it crashes).
|
||||
{
|
||||
public:
|
||||
ServerApplication();
|
||||
/// Creates the ServerApplication.
|
||||
|
||||
~ServerApplication();
|
||||
/// Destroys the ServerApplication.
|
||||
|
||||
bool isInteractive() const;
|
||||
/// Returns true if the application runs from the command line.
|
||||
/// Returns false if the application runs as a Unix daemon
|
||||
/// or Windows service.
|
||||
|
||||
int run(int argc, char** argv);
|
||||
/// Runs the application by performing additional initializations
|
||||
/// and calling the main() method.
|
||||
|
||||
int run(const std::vector<std::string>& args);
|
||||
/// Runs the application by performing additional initializations
|
||||
/// and calling the main() method.
|
||||
|
||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||
int run(int argc, wchar_t** argv);
|
||||
/// Runs the application by performing additional initializations
|
||||
/// and calling the main() method.
|
||||
///
|
||||
/// This Windows-specific version of init is used for passing
|
||||
/// Unicode command line arguments from wmain().
|
||||
#endif
|
||||
|
||||
static void terminate();
|
||||
/// Sends a friendly termination request to the application.
|
||||
/// If the application's main thread is waiting in
|
||||
/// waitForTerminationRequest(), this method will return
|
||||
/// and the application can shut down.
|
||||
|
||||
protected:
|
||||
int run();
|
||||
void waitForTerminationRequest();
|
||||
#if !defined(_WIN32_WCE)
|
||||
void defineOptions(OptionSet& options);
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if defined(POCO_VXWORKS)
|
||||
static Poco::Event _terminate;
|
||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||
void handleDaemon(const std::string& name, const std::string& value);
|
||||
void handlePidFile(const std::string& name, const std::string& value);
|
||||
bool isDaemon(int argc, char** argv);
|
||||
void beDaemon();
|
||||
#elif defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#if !defined(_WIN32_WCE)
|
||||
enum Action
|
||||
{
|
||||
SRV_RUN,
|
||||
SRV_REGISTER,
|
||||
SRV_UNREGISTER
|
||||
};
|
||||
static BOOL __stdcall ConsoleCtrlHandler(DWORD ctrlType);
|
||||
static void __stdcall ServiceControlHandler(DWORD control);
|
||||
#if defined(POCO_WIN32_UTF8) && !defined(POCO_NO_WSTRING)
|
||||
static void __stdcall ServiceMain(DWORD argc, LPWSTR* argv);
|
||||
#else
|
||||
static void __stdcall ServiceMain(DWORD argc, LPTSTR* argv);
|
||||
#endif
|
||||
|
||||
bool hasConsole();
|
||||
bool isService();
|
||||
void beService();
|
||||
void registerService();
|
||||
void unregisterService();
|
||||
void handleRegisterService(const std::string& name, const std::string& value);
|
||||
void handleUnregisterService(const std::string& name, const std::string& value);
|
||||
void handleDisplayName(const std::string& name, const std::string& value);
|
||||
void handleDescription(const std::string& name, const std::string& value);
|
||||
void handleStartup(const std::string& name, const std::string& value);
|
||||
|
||||
Action _action;
|
||||
std::string _displayName;
|
||||
std::string _description;
|
||||
std::string _startup;
|
||||
|
||||
static Poco::Event _terminated;
|
||||
static SERVICE_STATUS _serviceStatus;
|
||||
static SERVICE_STATUS_HANDLE _serviceStatusHandle;
|
||||
#endif // _WIN32_WCE
|
||||
static Poco::NamedEvent _terminate;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
//
|
||||
// Macro to implement main()
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_WIN32_UTF8)
|
||||
#define POCO_SERVER_MAIN(App) \
|
||||
int wmain(int argc, wchar_t** argv) \
|
||||
{ \
|
||||
App app; \
|
||||
return app.run(argc, argv); \
|
||||
}
|
||||
#elif defined(POCO_VXWORKS)
|
||||
#define POCO_SERVER_MAIN(App) \
|
||||
int pocoSrvMain(const char* appName, ...) \
|
||||
{ \
|
||||
std::vector<std::string> args; \
|
||||
args.push_back(std::string(appName)); \
|
||||
va_list vargs; \
|
||||
va_start(vargs, appName); \
|
||||
const char* arg = va_arg(vargs, const char*); \
|
||||
while (arg) \
|
||||
{ \
|
||||
args.push_back(std::string(arg)); \
|
||||
arg = va_arg(vargs, const char*); \
|
||||
} \
|
||||
va_end(vargs); \
|
||||
App app; \
|
||||
return app.run(args); \
|
||||
}
|
||||
#else
|
||||
#define POCO_SERVER_MAIN(App) \
|
||||
int main(int argc, char** argv) \
|
||||
{ \
|
||||
App app; \
|
||||
return app.run(argc, argv); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // Util_ServerApplication_INCLUDED
|
||||
|
||||
@@ -1,120 +1,120 @@
|
||||
//
|
||||
// Subsystem.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/Subsystem.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Application
|
||||
// Module: Subsystem
|
||||
//
|
||||
// Definition of the Subsystem class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_Subsystem_INCLUDED
|
||||
#define Util_Subsystem_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Application;
|
||||
class OptionSet;
|
||||
|
||||
|
||||
class Util_API Subsystem: public Poco::RefCountedObject
|
||||
/// Subsystems extend an application in a modular way.
|
||||
///
|
||||
/// The Subsystem class provides a common interface
|
||||
/// for subsystems so that subsystems can be automatically
|
||||
/// initialized at startup and uninitialized at shutdown.
|
||||
///
|
||||
/// Subsystems should also support dynamic reconfiguration,
|
||||
/// so that they can be reconfigured anytime during the
|
||||
/// life of a running application.
|
||||
///
|
||||
/// The degree to which dynamic reconfiguration is supported
|
||||
/// is up to the actual subsystem implementation. It can
|
||||
/// range from ignoring the reconfiguration request (not
|
||||
/// recommended), to changing certain settings that affect
|
||||
/// the performance, to a complete reinitialization.
|
||||
{
|
||||
public:
|
||||
Subsystem();
|
||||
/// Creates the Subsystem.
|
||||
|
||||
protected:
|
||||
virtual const char* name() const = 0;
|
||||
/// Returns the name of the subsystem.
|
||||
/// Must be implemented by subclasses.
|
||||
|
||||
virtual void initialize(Application& app) = 0;
|
||||
/// Initializes the subsystem.
|
||||
|
||||
virtual void uninitialize() = 0;
|
||||
/// Uninitializes the subsystem.
|
||||
|
||||
virtual void reinitialize(Application& app);
|
||||
/// Re-initializes the subsystem.
|
||||
///
|
||||
/// The default implementation just calls
|
||||
/// uninitialize() followed by initialize().
|
||||
/// Actual implementations might want to use a
|
||||
/// less radical and possibly more performant
|
||||
/// approach.
|
||||
|
||||
virtual void defineOptions(OptionSet& options);
|
||||
/// Called before the Application's command line processing begins.
|
||||
/// If a subsystem wants to support command line arguments,
|
||||
/// it must override this method.
|
||||
/// The default implementation does not define any options.
|
||||
///
|
||||
/// To effectively handle options, a subsystem should either bind
|
||||
/// the option to a configuration property or specify a callback
|
||||
/// to handle the option.
|
||||
|
||||
virtual ~Subsystem();
|
||||
/// Destroys the Subsystem.
|
||||
|
||||
friend class Application;
|
||||
|
||||
private:
|
||||
Subsystem(const Subsystem&);
|
||||
Subsystem& operator = (const Subsystem&);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_Subsystem_INCLUDED
|
||||
//
|
||||
// Subsystem.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/Subsystem.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Application
|
||||
// Module: Subsystem
|
||||
//
|
||||
// Definition of the Subsystem class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_Subsystem_INCLUDED
|
||||
#define Util_Subsystem_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Application;
|
||||
class OptionSet;
|
||||
|
||||
|
||||
class Util_API Subsystem: public Poco::RefCountedObject
|
||||
/// Subsystems extend an application in a modular way.
|
||||
///
|
||||
/// The Subsystem class provides a common interface
|
||||
/// for subsystems so that subsystems can be automatically
|
||||
/// initialized at startup and uninitialized at shutdown.
|
||||
///
|
||||
/// Subsystems should also support dynamic reconfiguration,
|
||||
/// so that they can be reconfigured anytime during the
|
||||
/// life of a running application.
|
||||
///
|
||||
/// The degree to which dynamic reconfiguration is supported
|
||||
/// is up to the actual subsystem implementation. It can
|
||||
/// range from ignoring the reconfiguration request (not
|
||||
/// recommended), to changing certain settings that affect
|
||||
/// the performance, to a complete reinitialization.
|
||||
{
|
||||
public:
|
||||
Subsystem();
|
||||
/// Creates the Subsystem.
|
||||
|
||||
protected:
|
||||
virtual const char* name() const = 0;
|
||||
/// Returns the name of the subsystem.
|
||||
/// Must be implemented by subclasses.
|
||||
|
||||
virtual void initialize(Application& app) = 0;
|
||||
/// Initializes the subsystem.
|
||||
|
||||
virtual void uninitialize() = 0;
|
||||
/// Uninitializes the subsystem.
|
||||
|
||||
virtual void reinitialize(Application& app);
|
||||
/// Re-initializes the subsystem.
|
||||
///
|
||||
/// The default implementation just calls
|
||||
/// uninitialize() followed by initialize().
|
||||
/// Actual implementations might want to use a
|
||||
/// less radical and possibly more performant
|
||||
/// approach.
|
||||
|
||||
virtual void defineOptions(OptionSet& options);
|
||||
/// Called before the Application's command line processing begins.
|
||||
/// If a subsystem wants to support command line arguments,
|
||||
/// it must override this method.
|
||||
/// The default implementation does not define any options.
|
||||
///
|
||||
/// To effectively handle options, a subsystem should either bind
|
||||
/// the option to a configuration property or specify a callback
|
||||
/// to handle the option.
|
||||
|
||||
virtual ~Subsystem();
|
||||
/// Destroys the Subsystem.
|
||||
|
||||
friend class Application;
|
||||
|
||||
private:
|
||||
Subsystem(const Subsystem&);
|
||||
Subsystem& operator = (const Subsystem&);
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_Subsystem_INCLUDED
|
||||
|
||||
@@ -1,111 +1,111 @@
|
||||
//
|
||||
// SystemConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/SystemConfiguration.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: SystemConfiguration
|
||||
//
|
||||
// Definition of the SystemConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_SystemConfiguration_INCLUDED
|
||||
#define Util_SystemConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API SystemConfiguration: public AbstractConfiguration
|
||||
/// This class implements a Configuration interface to
|
||||
/// various system properties and environment variables.
|
||||
///
|
||||
/// The following properties are supported:
|
||||
/// - system.osName: the operating system name
|
||||
/// - system.osVersion: the operating system version
|
||||
/// - system.osArchitecture: the operating system architecture
|
||||
/// - system.nodeName: the node (or host) name
|
||||
/// - system.nodeId: system ID, based on the Ethernet address (format "xxxxxxxxxxxx")
|
||||
/// of the first Ethernet adapter found on the system.
|
||||
/// - system.currentDir: the current working directory
|
||||
/// - system.homeDir: the user's home directory
|
||||
/// - system.tempDir: the system's temporary directory
|
||||
/// - system.dateTime: the current UTC date and time, formatted in ISO 8601 format.
|
||||
/// - system.pid: the current process ID.
|
||||
/// - system.env.<NAME>: the environment variable with the given <NAME>.
|
||||
///
|
||||
/// An attempt to set a system variable will result in an
|
||||
/// InvalidAccessException being thrown.
|
||||
///
|
||||
/// Enumerating environment variables is not supported.
|
||||
/// An attempt to call keys("system.env") will return an empty range.
|
||||
///
|
||||
/// Removing key is not supported. An attempt to remove a key results
|
||||
/// in a NotImplementedException being thrown.
|
||||
{
|
||||
public:
|
||||
SystemConfiguration();
|
||||
/// Creates the SystemConfiguration.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
~SystemConfiguration();
|
||||
|
||||
private:
|
||||
static bool getEnv(const std::string& name, std::string& value);
|
||||
|
||||
static const std::string OSNAME;
|
||||
static const std::string OSVERSION;
|
||||
static const std::string OSARCHITECTURE;
|
||||
static const std::string NODENAME;
|
||||
static const std::string NODEID;
|
||||
static const std::string CURRENTDIR;
|
||||
static const std::string HOMEDIR;
|
||||
static const std::string TEMPDIR;
|
||||
static const std::string DATETIME;
|
||||
#if !defined(POCO_VXWORKS)
|
||||
static const std::string PID;
|
||||
#endif
|
||||
static const std::string ENV;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_SystemConfiguration_INCLUDED
|
||||
//
|
||||
// SystemConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/SystemConfiguration.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: SystemConfiguration
|
||||
//
|
||||
// Definition of the SystemConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_SystemConfiguration_INCLUDED
|
||||
#define Util_SystemConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API SystemConfiguration: public AbstractConfiguration
|
||||
/// This class implements a Configuration interface to
|
||||
/// various system properties and environment variables.
|
||||
///
|
||||
/// The following properties are supported:
|
||||
/// - system.osName: the operating system name
|
||||
/// - system.osVersion: the operating system version
|
||||
/// - system.osArchitecture: the operating system architecture
|
||||
/// - system.nodeName: the node (or host) name
|
||||
/// - system.nodeId: system ID, based on the Ethernet address (format "xxxxxxxxxxxx")
|
||||
/// of the first Ethernet adapter found on the system.
|
||||
/// - system.currentDir: the current working directory
|
||||
/// - system.homeDir: the user's home directory
|
||||
/// - system.tempDir: the system's temporary directory
|
||||
/// - system.dateTime: the current UTC date and time, formatted in ISO 8601 format.
|
||||
/// - system.pid: the current process ID.
|
||||
/// - system.env.<NAME>: the environment variable with the given <NAME>.
|
||||
///
|
||||
/// An attempt to set a system variable will result in an
|
||||
/// InvalidAccessException being thrown.
|
||||
///
|
||||
/// Enumerating environment variables is not supported.
|
||||
/// An attempt to call keys("system.env") will return an empty range.
|
||||
///
|
||||
/// Removing key is not supported. An attempt to remove a key results
|
||||
/// in a NotImplementedException being thrown.
|
||||
{
|
||||
public:
|
||||
SystemConfiguration();
|
||||
/// Creates the SystemConfiguration.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
~SystemConfiguration();
|
||||
|
||||
private:
|
||||
static bool getEnv(const std::string& name, std::string& value);
|
||||
|
||||
static const std::string OSNAME;
|
||||
static const std::string OSVERSION;
|
||||
static const std::string OSARCHITECTURE;
|
||||
static const std::string NODENAME;
|
||||
static const std::string NODEID;
|
||||
static const std::string CURRENTDIR;
|
||||
static const std::string HOMEDIR;
|
||||
static const std::string TEMPDIR;
|
||||
static const std::string DATETIME;
|
||||
#if !defined(POCO_VXWORKS)
|
||||
static const std::string PID;
|
||||
#endif
|
||||
static const std::string ENV;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_SystemConfiguration_INCLUDED
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
//
|
||||
// Util.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/Util.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Util
|
||||
// Module: Util
|
||||
//
|
||||
// Basic definitions for the Poco Util library.
|
||||
// This file must be the first file included by every other Util
|
||||
// header file.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_Util_INCLUDED
|
||||
#define Util_Util_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the Util_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// Util_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(Util_EXPORTS)
|
||||
#define Util_API __declspec(dllexport)
|
||||
#else
|
||||
#define Util_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(Util_API)
|
||||
#define Util_API
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Util library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Util_EXPORTS)
|
||||
#pragma comment(lib, "PocoUtil" POCO_LIB_SUFFIX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // Util_Util_INCLUDED
|
||||
//
|
||||
// Util.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/Util.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Util
|
||||
// Module: Util
|
||||
//
|
||||
// Basic definitions for the Poco Util library.
|
||||
// This file must be the first file included by every other Util
|
||||
// header file.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_Util_INCLUDED
|
||||
#define Util_Util_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the Util_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// Util_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(Util_EXPORTS)
|
||||
#define Util_API __declspec(dllexport)
|
||||
#else
|
||||
#define Util_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(Util_API)
|
||||
#define Util_API
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Util library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Util_EXPORTS)
|
||||
#pragma comment(lib, "PocoUtil" POCO_LIB_SUFFIX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // Util_Util_INCLUDED
|
||||
|
||||
@@ -1,79 +1,79 @@
|
||||
//
|
||||
// Validator.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/Validator.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: Validator
|
||||
//
|
||||
// Definition of the Validator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_Validator_INCLUDED
|
||||
#define Util_Validator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Option;
|
||||
|
||||
|
||||
class Util_API Validator: public Poco::RefCountedObject
|
||||
/// Validator specifies the interface for option validators.
|
||||
///
|
||||
/// Option validators provide a simple way for the automatic
|
||||
/// validation of command line argument values.
|
||||
{
|
||||
public:
|
||||
virtual void validate(const Option& option, const std::string& value) = 0;
|
||||
/// Validates the value for the given option.
|
||||
/// Does nothing if the value is valid.
|
||||
///
|
||||
/// Throws an InvalidOptionException otherwise.
|
||||
|
||||
protected:
|
||||
Validator();
|
||||
/// Creates the Validator.
|
||||
|
||||
virtual ~Validator();
|
||||
/// Destroys the Validator.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_Validator_INCLUDED
|
||||
//
|
||||
// Validator.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/Validator.h#1 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Options
|
||||
// Module: Validator
|
||||
//
|
||||
// Definition of the Validator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_Validator_INCLUDED
|
||||
#define Util_Validator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Option;
|
||||
|
||||
|
||||
class Util_API Validator: public Poco::RefCountedObject
|
||||
/// Validator specifies the interface for option validators.
|
||||
///
|
||||
/// Option validators provide a simple way for the automatic
|
||||
/// validation of command line argument values.
|
||||
{
|
||||
public:
|
||||
virtual void validate(const Option& option, const std::string& value) = 0;
|
||||
/// Validates the value for the given option.
|
||||
/// Does nothing if the value is valid.
|
||||
///
|
||||
/// Throws an InvalidOptionException otherwise.
|
||||
|
||||
protected:
|
||||
Validator();
|
||||
/// Creates the Validator.
|
||||
|
||||
virtual ~Validator();
|
||||
/// Destroys the Validator.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_Validator_INCLUDED
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
//
|
||||
// WinRegistryConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/WinRegistryConfiguration.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Windows
|
||||
// Module: WinRegistryConfiguration
|
||||
//
|
||||
// Definition of the WinRegistryConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_WinRegistryConfiguration_INCLUDED
|
||||
#define Util_WinRegistryConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API WinRegistryConfiguration: public AbstractConfiguration
|
||||
/// An implementation of AbstractConfiguration that stores configuration data
|
||||
/// in the Windows registry.
|
||||
///
|
||||
/// Removing key is not supported. An attempt to remove a key results
|
||||
/// in a NotImplementedException being thrown.
|
||||
{
|
||||
public:
|
||||
WinRegistryConfiguration(const std::string& rootPath, REGSAM extraSam = 0);
|
||||
/// Creates the WinRegistryConfiguration.
|
||||
/// The rootPath must start with one of the root key names
|
||||
/// like HKEY_CLASSES_ROOT, e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
|
||||
/// All further keys are relativ to the root path and can be
|
||||
/// dot seperated, e.g. the path MyService.ServiceName will be converted to
|
||||
/// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\ServiceName.
|
||||
/// The extraSam parameter will be passed along to WinRegistryKey, to control
|
||||
/// registry virtualization for example.
|
||||
|
||||
protected:
|
||||
~WinRegistryConfiguration();
|
||||
/// Destroys the WinRegistryConfiguration.
|
||||
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
std::string ConvertToRegFormat(const std::string& key, std::string& keyName) const;
|
||||
/// takes a key in the format of A.B.C and converts it to
|
||||
/// registry format A\B\C, the last entry is the keyName, the rest is returned as path
|
||||
|
||||
private:
|
||||
std::string _rootPath;
|
||||
REGSAM _extraSam;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_WinRegistryConfiguration_INCLUDED
|
||||
//
|
||||
// WinRegistryConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/WinRegistryConfiguration.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Windows
|
||||
// Module: WinRegistryConfiguration
|
||||
//
|
||||
// Definition of the WinRegistryConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_WinRegistryConfiguration_INCLUDED
|
||||
#define Util_WinRegistryConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/AbstractConfiguration.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API WinRegistryConfiguration: public AbstractConfiguration
|
||||
/// An implementation of AbstractConfiguration that stores configuration data
|
||||
/// in the Windows registry.
|
||||
///
|
||||
/// Removing key is not supported. An attempt to remove a key results
|
||||
/// in a NotImplementedException being thrown.
|
||||
{
|
||||
public:
|
||||
WinRegistryConfiguration(const std::string& rootPath, REGSAM extraSam = 0);
|
||||
/// Creates the WinRegistryConfiguration.
|
||||
/// The rootPath must start with one of the root key names
|
||||
/// like HKEY_CLASSES_ROOT, e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
|
||||
/// All further keys are relativ to the root path and can be
|
||||
/// dot seperated, e.g. the path MyService.ServiceName will be converted to
|
||||
/// HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MyService\ServiceName.
|
||||
/// The extraSam parameter will be passed along to WinRegistryKey, to control
|
||||
/// registry virtualization for example.
|
||||
|
||||
protected:
|
||||
~WinRegistryConfiguration();
|
||||
/// Destroys the WinRegistryConfiguration.
|
||||
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
|
||||
std::string ConvertToRegFormat(const std::string& key, std::string& keyName) const;
|
||||
/// takes a key in the format of A.B.C and converts it to
|
||||
/// registry format A\B\C, the last entry is the keyName, the rest is returned as path
|
||||
|
||||
private:
|
||||
std::string _rootPath;
|
||||
REGSAM _extraSam;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_WinRegistryConfiguration_INCLUDED
|
||||
|
||||
@@ -1,187 +1,187 @@
|
||||
//
|
||||
// WinRegistryKey.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/WinRegistryKey.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Windows
|
||||
// Module: WinRegistryKey
|
||||
//
|
||||
// Definition of the WinRegistryKey class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_WinRegistryKey_INCLUDED
|
||||
#define Util_WinRegistryKey_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API WinRegistryKey
|
||||
/// This class implements a convenient interface to the
|
||||
/// Windows Registry.
|
||||
///
|
||||
/// This class is only available on Windows platforms.
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::string> Keys;
|
||||
typedef std::vector<std::string> Values;
|
||||
|
||||
enum Type
|
||||
{
|
||||
REGT_NONE = 0,
|
||||
REGT_STRING = 1,
|
||||
REGT_STRING_EXPAND = 2,
|
||||
REGT_DWORD = 4
|
||||
};
|
||||
|
||||
WinRegistryKey(const std::string& key, bool readOnly = false, REGSAM extraSam = 0);
|
||||
/// Creates the WinRegistryKey.
|
||||
///
|
||||
/// The key must start with one of the root key names
|
||||
/// like HKEY_CLASSES_ROOT, e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
|
||||
///
|
||||
/// If readOnly is true, then only read access to the registry
|
||||
/// is available and any attempt to write to the registry will
|
||||
/// result in an exception.
|
||||
///
|
||||
/// extraSam is used to pass extra flags (in addition to KEY_READ and KEY_WRITE)
|
||||
/// to the samDesired argument of RegOpenKeyEx() or RegCreateKeyEx().
|
||||
|
||||
WinRegistryKey(HKEY hRootKey, const std::string& subKey, bool readOnly = false, REGSAM extraSam = 0);
|
||||
/// Creates the WinRegistryKey.
|
||||
///
|
||||
/// If readOnly is true, then only read access to the registry
|
||||
/// is available and any attempt to write to the registry will
|
||||
/// result in an exception.
|
||||
///
|
||||
/// extraSam is used to pass extra flags (in addition to KEY_READ and KEY_WRITE)
|
||||
/// to the samDesired argument of RegOpenKeyEx() or RegCreateKeyEx().
|
||||
|
||||
~WinRegistryKey();
|
||||
/// Destroys the WinRegistryKey.
|
||||
|
||||
void setString(const std::string& name, const std::string& value);
|
||||
/// Sets the string value (REG_SZ) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
||||
std::string getString(const std::string& name);
|
||||
/// Returns the string value (REG_SZ) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void setStringExpand(const std::string& name, const std::string& value);
|
||||
/// Sets the expandable string value (REG_EXPAND_SZ) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
||||
std::string getStringExpand(const std::string& name);
|
||||
/// Returns the string value (REG_EXPAND_SZ) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
/// All references to environment variables (%VAR%) in the string
|
||||
/// are expanded.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void setInt(const std::string& name, int value);
|
||||
/// Sets the numeric (REG_DWORD) value with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
||||
int getInt(const std::string& name);
|
||||
/// Returns the numeric value (REG_DWORD) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void deleteValue(const std::string& name);
|
||||
/// Deletes the value with the given name.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void deleteKey();
|
||||
/// Recursively deletes the key and all subkeys.
|
||||
|
||||
bool exists();
|
||||
/// Returns true iff the key exists.
|
||||
|
||||
Type type(const std::string& name);
|
||||
/// Returns the type of the key value.
|
||||
|
||||
bool exists(const std::string& name);
|
||||
/// Returns true iff the given value exists under that key.
|
||||
|
||||
void subKeys(Keys& keys);
|
||||
/// Appends all subKey names to keys.
|
||||
|
||||
void values(Values& vals);
|
||||
/// Appends all value names to vals;
|
||||
|
||||
bool isReadOnly() const;
|
||||
/// Returns true iff the key has been opened for read-only access only.
|
||||
|
||||
protected:
|
||||
void open();
|
||||
void close();
|
||||
std::string key() const;
|
||||
std::string key(const std::string& valueName) const;
|
||||
void handleSetError(const std::string& name);
|
||||
static HKEY handleFor(const std::string& rootKey);
|
||||
|
||||
private:
|
||||
WinRegistryKey();
|
||||
WinRegistryKey(const WinRegistryKey&);
|
||||
WinRegistryKey& operator = (const WinRegistryKey&);
|
||||
|
||||
HKEY _hRootKey;
|
||||
std::string _subKey;
|
||||
HKEY _hKey;
|
||||
bool _readOnly;
|
||||
REGSAM _extraSam;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline bool WinRegistryKey::isReadOnly() const
|
||||
{
|
||||
return _readOnly;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_WinRegistryKey_INCLUDED
|
||||
//
|
||||
// WinRegistryKey.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/WinRegistryKey.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Windows
|
||||
// Module: WinRegistryKey
|
||||
//
|
||||
// Definition of the WinRegistryKey class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_WinRegistryKey_INCLUDED
|
||||
#define Util_WinRegistryKey_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API WinRegistryKey
|
||||
/// This class implements a convenient interface to the
|
||||
/// Windows Registry.
|
||||
///
|
||||
/// This class is only available on Windows platforms.
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::string> Keys;
|
||||
typedef std::vector<std::string> Values;
|
||||
|
||||
enum Type
|
||||
{
|
||||
REGT_NONE = 0,
|
||||
REGT_STRING = 1,
|
||||
REGT_STRING_EXPAND = 2,
|
||||
REGT_DWORD = 4
|
||||
};
|
||||
|
||||
WinRegistryKey(const std::string& key, bool readOnly = false, REGSAM extraSam = 0);
|
||||
/// Creates the WinRegistryKey.
|
||||
///
|
||||
/// The key must start with one of the root key names
|
||||
/// like HKEY_CLASSES_ROOT, e.g. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services.
|
||||
///
|
||||
/// If readOnly is true, then only read access to the registry
|
||||
/// is available and any attempt to write to the registry will
|
||||
/// result in an exception.
|
||||
///
|
||||
/// extraSam is used to pass extra flags (in addition to KEY_READ and KEY_WRITE)
|
||||
/// to the samDesired argument of RegOpenKeyEx() or RegCreateKeyEx().
|
||||
|
||||
WinRegistryKey(HKEY hRootKey, const std::string& subKey, bool readOnly = false, REGSAM extraSam = 0);
|
||||
/// Creates the WinRegistryKey.
|
||||
///
|
||||
/// If readOnly is true, then only read access to the registry
|
||||
/// is available and any attempt to write to the registry will
|
||||
/// result in an exception.
|
||||
///
|
||||
/// extraSam is used to pass extra flags (in addition to KEY_READ and KEY_WRITE)
|
||||
/// to the samDesired argument of RegOpenKeyEx() or RegCreateKeyEx().
|
||||
|
||||
~WinRegistryKey();
|
||||
/// Destroys the WinRegistryKey.
|
||||
|
||||
void setString(const std::string& name, const std::string& value);
|
||||
/// Sets the string value (REG_SZ) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
||||
std::string getString(const std::string& name);
|
||||
/// Returns the string value (REG_SZ) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void setStringExpand(const std::string& name, const std::string& value);
|
||||
/// Sets the expandable string value (REG_EXPAND_SZ) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
||||
std::string getStringExpand(const std::string& name);
|
||||
/// Returns the string value (REG_EXPAND_SZ) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
/// All references to environment variables (%VAR%) in the string
|
||||
/// are expanded.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void setInt(const std::string& name, int value);
|
||||
/// Sets the numeric (REG_DWORD) value with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
|
||||
int getInt(const std::string& name);
|
||||
/// Returns the numeric value (REG_DWORD) with the given name.
|
||||
/// An empty name denotes the default value.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void deleteValue(const std::string& name);
|
||||
/// Deletes the value with the given name.
|
||||
///
|
||||
/// Throws a NotFoundException if the value does not exist.
|
||||
|
||||
void deleteKey();
|
||||
/// Recursively deletes the key and all subkeys.
|
||||
|
||||
bool exists();
|
||||
/// Returns true iff the key exists.
|
||||
|
||||
Type type(const std::string& name);
|
||||
/// Returns the type of the key value.
|
||||
|
||||
bool exists(const std::string& name);
|
||||
/// Returns true iff the given value exists under that key.
|
||||
|
||||
void subKeys(Keys& keys);
|
||||
/// Appends all subKey names to keys.
|
||||
|
||||
void values(Values& vals);
|
||||
/// Appends all value names to vals;
|
||||
|
||||
bool isReadOnly() const;
|
||||
/// Returns true iff the key has been opened for read-only access only.
|
||||
|
||||
protected:
|
||||
void open();
|
||||
void close();
|
||||
std::string key() const;
|
||||
std::string key(const std::string& valueName) const;
|
||||
void handleSetError(const std::string& name);
|
||||
static HKEY handleFor(const std::string& rootKey);
|
||||
|
||||
private:
|
||||
WinRegistryKey();
|
||||
WinRegistryKey(const WinRegistryKey&);
|
||||
WinRegistryKey& operator = (const WinRegistryKey&);
|
||||
|
||||
HKEY _hRootKey;
|
||||
std::string _subKey;
|
||||
HKEY _hKey;
|
||||
bool _readOnly;
|
||||
REGSAM _extraSam;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline bool WinRegistryKey::isReadOnly() const
|
||||
{
|
||||
return _readOnly;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_WinRegistryKey_INCLUDED
|
||||
|
||||
@@ -1,163 +1,163 @@
|
||||
//
|
||||
// WinService.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/WinService.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Windows
|
||||
// Module: WinService
|
||||
//
|
||||
// Definition of the WinService class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_WinService_INCLUDED
|
||||
#define Util_WinService_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
#define POCO_LPQUERY_SERVICE_CONFIG LPQUERY_SERVICE_CONFIGW
|
||||
#else
|
||||
#define POCO_LPQUERY_SERVICE_CONFIG LPQUERY_SERVICE_CONFIGA
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API WinService
|
||||
/// This class provides an object-oriented interface to
|
||||
/// the Windows Service Control Manager for registering,
|
||||
/// unregistering, configuring, starting and stopping
|
||||
/// services.
|
||||
///
|
||||
/// This class is only available on Windows platforms.
|
||||
{
|
||||
public:
|
||||
enum Startup
|
||||
{
|
||||
SVC_AUTO_START,
|
||||
SVC_MANUAL_START,
|
||||
SVC_DISABLED
|
||||
};
|
||||
|
||||
WinService(const std::string& name);
|
||||
/// Creates the WinService, using the given service name.
|
||||
|
||||
~WinService();
|
||||
/// Destroys the WinService.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the service name.
|
||||
|
||||
std::string displayName() const;
|
||||
/// Returns the service's display name.
|
||||
|
||||
std::string path() const;
|
||||
/// Returns the path to the service executable.
|
||||
///
|
||||
/// Throws a NotFoundException if the service has not been registered.
|
||||
|
||||
void registerService(const std::string& path, const std::string& displayName);
|
||||
/// Creates a Windows service with the executable specified by path
|
||||
/// and the given displayName.
|
||||
///
|
||||
/// Throws a ExistsException if the service has already been registered.
|
||||
|
||||
void registerService(const std::string& path);
|
||||
/// Creates a Windows service with the executable specified by path
|
||||
/// and the given displayName. The service name is used as display name.
|
||||
///
|
||||
/// Throws a ExistsException if the service has already been registered.
|
||||
|
||||
void unregisterService();
|
||||
/// Deletes the Windows service.
|
||||
///
|
||||
/// Throws a NotFoundException if the service has not been registered.
|
||||
|
||||
bool isRegistered() const;
|
||||
/// Returns true if the service has been registered with the Service Control Manager.
|
||||
|
||||
bool isRunning() const;
|
||||
/// Returns true if the service is currently running.
|
||||
|
||||
void start();
|
||||
/// Starts the service.
|
||||
/// Does nothing if the service is already running.
|
||||
///
|
||||
/// Throws a NotFoundException if the service has not been registered.
|
||||
|
||||
void stop();
|
||||
/// Stops the service.
|
||||
/// Does nothing if the service is not running.
|
||||
///
|
||||
/// Throws a NotFoundException if the service has not been registered.
|
||||
|
||||
void setStartup(Startup startup);
|
||||
/// Sets the startup mode for the service.
|
||||
|
||||
Startup getStartup() const;
|
||||
/// Returns the startup mode for the service.
|
||||
|
||||
void setDescription(const std::string& description);
|
||||
/// Sets the service description in the registry.
|
||||
|
||||
std::string getDescription() const;
|
||||
/// Returns the service description from the registry.
|
||||
|
||||
static const int STARTUP_TIMEOUT;
|
||||
|
||||
protected:
|
||||
static const std::string REGISTRY_KEY;
|
||||
static const std::string REGISTRY_DESCRIPTION;
|
||||
|
||||
private:
|
||||
void open() const;
|
||||
bool tryOpen() const;
|
||||
void close() const;
|
||||
POCO_LPQUERY_SERVICE_CONFIG config() const;
|
||||
|
||||
WinService();
|
||||
WinService(const WinService&);
|
||||
WinService& operator = (const WinService&);
|
||||
|
||||
std::string _name;
|
||||
SC_HANDLE _scmHandle;
|
||||
mutable SC_HANDLE _svcHandle;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_WinService_INCLUDED
|
||||
//
|
||||
// WinService.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/WinService.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Windows
|
||||
// Module: WinService
|
||||
//
|
||||
// Definition of the WinService class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_WinService_INCLUDED
|
||||
#define Util_WinService_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/UnWindows.h"
|
||||
|
||||
|
||||
#if defined(POCO_WIN32_UTF8)
|
||||
#define POCO_LPQUERY_SERVICE_CONFIG LPQUERY_SERVICE_CONFIGW
|
||||
#else
|
||||
#define POCO_LPQUERY_SERVICE_CONFIG LPQUERY_SERVICE_CONFIGA
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API WinService
|
||||
/// This class provides an object-oriented interface to
|
||||
/// the Windows Service Control Manager for registering,
|
||||
/// unregistering, configuring, starting and stopping
|
||||
/// services.
|
||||
///
|
||||
/// This class is only available on Windows platforms.
|
||||
{
|
||||
public:
|
||||
enum Startup
|
||||
{
|
||||
SVC_AUTO_START,
|
||||
SVC_MANUAL_START,
|
||||
SVC_DISABLED
|
||||
};
|
||||
|
||||
WinService(const std::string& name);
|
||||
/// Creates the WinService, using the given service name.
|
||||
|
||||
~WinService();
|
||||
/// Destroys the WinService.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the service name.
|
||||
|
||||
std::string displayName() const;
|
||||
/// Returns the service's display name.
|
||||
|
||||
std::string path() const;
|
||||
/// Returns the path to the service executable.
|
||||
///
|
||||
/// Throws a NotFoundException if the service has not been registered.
|
||||
|
||||
void registerService(const std::string& path, const std::string& displayName);
|
||||
/// Creates a Windows service with the executable specified by path
|
||||
/// and the given displayName.
|
||||
///
|
||||
/// Throws a ExistsException if the service has already been registered.
|
||||
|
||||
void registerService(const std::string& path);
|
||||
/// Creates a Windows service with the executable specified by path
|
||||
/// and the given displayName. The service name is used as display name.
|
||||
///
|
||||
/// Throws a ExistsException if the service has already been registered.
|
||||
|
||||
void unregisterService();
|
||||
/// Deletes the Windows service.
|
||||
///
|
||||
/// Throws a NotFoundException if the service has not been registered.
|
||||
|
||||
bool isRegistered() const;
|
||||
/// Returns true if the service has been registered with the Service Control Manager.
|
||||
|
||||
bool isRunning() const;
|
||||
/// Returns true if the service is currently running.
|
||||
|
||||
void start();
|
||||
/// Starts the service.
|
||||
/// Does nothing if the service is already running.
|
||||
///
|
||||
/// Throws a NotFoundException if the service has not been registered.
|
||||
|
||||
void stop();
|
||||
/// Stops the service.
|
||||
/// Does nothing if the service is not running.
|
||||
///
|
||||
/// Throws a NotFoundException if the service has not been registered.
|
||||
|
||||
void setStartup(Startup startup);
|
||||
/// Sets the startup mode for the service.
|
||||
|
||||
Startup getStartup() const;
|
||||
/// Returns the startup mode for the service.
|
||||
|
||||
void setDescription(const std::string& description);
|
||||
/// Sets the service description in the registry.
|
||||
|
||||
std::string getDescription() const;
|
||||
/// Returns the service description from the registry.
|
||||
|
||||
static const int STARTUP_TIMEOUT;
|
||||
|
||||
protected:
|
||||
static const std::string REGISTRY_KEY;
|
||||
static const std::string REGISTRY_DESCRIPTION;
|
||||
|
||||
private:
|
||||
void open() const;
|
||||
bool tryOpen() const;
|
||||
void close() const;
|
||||
POCO_LPQUERY_SERVICE_CONFIG config() const;
|
||||
|
||||
WinService();
|
||||
WinService(const WinService&);
|
||||
WinService& operator = (const WinService&);
|
||||
|
||||
std::string _name;
|
||||
SC_HANDLE _scmHandle;
|
||||
mutable SC_HANDLE _svcHandle;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_WinService_INCLUDED
|
||||
|
||||
@@ -1,217 +1,217 @@
|
||||
//
|
||||
// XMLConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/XMLConfiguration.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: XMLConfiguration
|
||||
//
|
||||
// Definition of the XMLConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_XMLConfiguration_INCLUDED
|
||||
#define Util_XMLConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/MapConfiguration.h"
|
||||
#include "Poco/DOM/Document.h"
|
||||
#include "Poco/DOM/AutoPtr.h"
|
||||
#include "Poco/DOM/DOMWriter.h"
|
||||
#include "Poco/SAX/InputSource.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API XMLConfiguration: public AbstractConfiguration
|
||||
/// This configuration class extracts configuration properties
|
||||
/// from an XML document. An XPath-like syntax for property
|
||||
/// names is supported to allow full access to the XML document.
|
||||
/// XML namespaces are not supported. The name of the root element
|
||||
/// of the XML document is not significant and ignored.
|
||||
/// Periods in tag names are not supported.
|
||||
///
|
||||
/// Given the following XML document as an example:
|
||||
///
|
||||
/// <config>
|
||||
/// <prop1>value1</prop1>
|
||||
/// <prop2>value2</prop2>
|
||||
/// <prop3>
|
||||
/// <prop4 attr="value3"/>
|
||||
/// <prop4 attr="value4"/>
|
||||
/// </prop3>
|
||||
/// <prop5 id="first">value5</prop5>
|
||||
/// <prop5 id="second">value6</prop5>
|
||||
/// </config>
|
||||
///
|
||||
/// The following property names would be valid and would
|
||||
/// yield the shown values:
|
||||
///
|
||||
/// prop1 -> value1
|
||||
/// prop2 -> value2
|
||||
/// prop3.prop4 -> (empty string)
|
||||
/// prop3.prop4[@attr] -> value3
|
||||
/// prop3.prop4[1][@attr] -> value4
|
||||
/// prop5[0] -> value5
|
||||
/// prop5[1] -> value6
|
||||
/// prop5[@id=first] -> value5
|
||||
/// prop5[@id='second'] -> value6
|
||||
///
|
||||
/// Enumerating attributes is not supported.
|
||||
/// Calling keys("prop3.prop4") will return an empty range.
|
||||
///
|
||||
/// As a special feature, the delimiter character used to delimit
|
||||
/// property names can be changed to something other than period ('.') by
|
||||
/// passing the desired character to the constructor. This allows
|
||||
/// working with XML documents having element names with periods
|
||||
/// in them.
|
||||
{
|
||||
public:
|
||||
XMLConfiguration();
|
||||
/// Creates an empty XMLConfiguration.
|
||||
|
||||
XMLConfiguration(char delim);
|
||||
/// Creates an empty XMLConfiguration, using the given
|
||||
/// delimiter char instead of the default '.'.
|
||||
|
||||
XMLConfiguration(Poco::XML::InputSource* pInputSource);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given InputSource.
|
||||
|
||||
XMLConfiguration(Poco::XML::InputSource* pInputSource, char delim);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given InputSource. Uses the given delimiter char instead
|
||||
/// of the default '.'.
|
||||
|
||||
XMLConfiguration(std::istream& istr);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given stream.
|
||||
|
||||
XMLConfiguration(std::istream& istr, char delim);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given stream. Uses the given delimiter char instead
|
||||
/// of the default '.'.
|
||||
|
||||
XMLConfiguration(const std::string& path);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given path.
|
||||
|
||||
XMLConfiguration(const std::string& path, char delim);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given path. Uses the given delimiter char instead
|
||||
/// of the default '.'.
|
||||
|
||||
XMLConfiguration(const Poco::XML::Document* pDocument);
|
||||
/// Creates the XMLConfiguration using the given XML document.
|
||||
|
||||
XMLConfiguration(const Poco::XML::Document* pDocument, char delim);
|
||||
/// Creates the XMLConfiguration using the given XML document.
|
||||
/// Uses the given delimiter char instead of the default '.'.
|
||||
|
||||
XMLConfiguration(const Poco::XML::Node* pNode);
|
||||
/// Creates the XMLConfiguration using the given XML node.
|
||||
|
||||
XMLConfiguration(const Poco::XML::Node* pNode, char delim);
|
||||
/// Creates the XMLConfiguration using the given XML node.
|
||||
/// Uses the given delimiter char instead of the default '.'.
|
||||
|
||||
void load(Poco::XML::InputSource* pInputSource);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given InputSource.
|
||||
|
||||
void load(std::istream& istr);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given stream.
|
||||
|
||||
void load(const std::string& path);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given file.
|
||||
|
||||
void load(const Poco::XML::Document* pDocument);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given XML document.
|
||||
|
||||
void load(const Poco::XML::Node* pNode);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given XML node.
|
||||
|
||||
void loadEmpty(const std::string& rootElementName);
|
||||
/// Loads an empty XML document containing only the
|
||||
/// root element with the given name.
|
||||
|
||||
void save(const std::string& path) const;
|
||||
/// Writes the XML document containing the configuration data
|
||||
/// to the file given by path.
|
||||
|
||||
void save(std::ostream& str) const;
|
||||
/// Writes the XML document containing the configuration data
|
||||
/// to the given stream.
|
||||
|
||||
void save(Poco::XML::DOMWriter& writer, const std::string& path) const;
|
||||
/// Writes the XML document containing the configuration data
|
||||
/// to the file given by path, using the given DOMWriter.
|
||||
///
|
||||
/// This can be used to use a DOMWriter with custom options.
|
||||
|
||||
void save(Poco::XML::DOMWriter& writer, std::ostream& str) const;
|
||||
/// Writes the XML document containing the configuration data
|
||||
/// to the given stream.
|
||||
///
|
||||
/// This can be used to use a DOMWriter with custom options.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
~XMLConfiguration();
|
||||
|
||||
private:
|
||||
const Poco::XML::Node* findNode(const std::string& key) const;
|
||||
Poco::XML::Node* findNode(const std::string& key);
|
||||
Poco::XML::Node* findNode(std::string::const_iterator& it, const std::string::const_iterator& end, Poco::XML::Node* pNode, bool create = false) const;
|
||||
static Poco::XML::Node* findElement(const std::string& name, Poco::XML::Node* pNode, bool create);
|
||||
static Poco::XML::Node* findElement(int index, Poco::XML::Node* pNode, bool create);
|
||||
static Poco::XML::Node* findElement(const std::string& attr, const std::string& value, Poco::XML::Node* pNode);
|
||||
static Poco::XML::Node* findAttribute(const std::string& name, Poco::XML::Node* pNode, bool create);
|
||||
|
||||
Poco::XML::AutoPtr<Poco::XML::Node> _pRoot;
|
||||
Poco::XML::AutoPtr<Poco::XML::Document> _pDocument;
|
||||
char _delim;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_XMLConfiguration_INCLUDED
|
||||
//
|
||||
// XMLConfiguration.h
|
||||
//
|
||||
// $Id: //poco/1.4/Util/include/Poco/Util/XMLConfiguration.h#2 $
|
||||
//
|
||||
// Library: Util
|
||||
// Package: Configuration
|
||||
// Module: XMLConfiguration
|
||||
//
|
||||
// Definition of the XMLConfiguration class.
|
||||
//
|
||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Util_XMLConfiguration_INCLUDED
|
||||
#define Util_XMLConfiguration_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Util/Util.h"
|
||||
#include "Poco/Util/MapConfiguration.h"
|
||||
#include "Poco/DOM/Document.h"
|
||||
#include "Poco/DOM/AutoPtr.h"
|
||||
#include "Poco/DOM/DOMWriter.h"
|
||||
#include "Poco/SAX/InputSource.h"
|
||||
#include <istream>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Util {
|
||||
|
||||
|
||||
class Util_API XMLConfiguration: public AbstractConfiguration
|
||||
/// This configuration class extracts configuration properties
|
||||
/// from an XML document. An XPath-like syntax for property
|
||||
/// names is supported to allow full access to the XML document.
|
||||
/// XML namespaces are not supported. The name of the root element
|
||||
/// of the XML document is not significant and ignored.
|
||||
/// Periods in tag names are not supported.
|
||||
///
|
||||
/// Given the following XML document as an example:
|
||||
///
|
||||
/// <config>
|
||||
/// <prop1>value1</prop1>
|
||||
/// <prop2>value2</prop2>
|
||||
/// <prop3>
|
||||
/// <prop4 attr="value3"/>
|
||||
/// <prop4 attr="value4"/>
|
||||
/// </prop3>
|
||||
/// <prop5 id="first">value5</prop5>
|
||||
/// <prop5 id="second">value6</prop5>
|
||||
/// </config>
|
||||
///
|
||||
/// The following property names would be valid and would
|
||||
/// yield the shown values:
|
||||
///
|
||||
/// prop1 -> value1
|
||||
/// prop2 -> value2
|
||||
/// prop3.prop4 -> (empty string)
|
||||
/// prop3.prop4[@attr] -> value3
|
||||
/// prop3.prop4[1][@attr] -> value4
|
||||
/// prop5[0] -> value5
|
||||
/// prop5[1] -> value6
|
||||
/// prop5[@id=first] -> value5
|
||||
/// prop5[@id='second'] -> value6
|
||||
///
|
||||
/// Enumerating attributes is not supported.
|
||||
/// Calling keys("prop3.prop4") will return an empty range.
|
||||
///
|
||||
/// As a special feature, the delimiter character used to delimit
|
||||
/// property names can be changed to something other than period ('.') by
|
||||
/// passing the desired character to the constructor. This allows
|
||||
/// working with XML documents having element names with periods
|
||||
/// in them.
|
||||
{
|
||||
public:
|
||||
XMLConfiguration();
|
||||
/// Creates an empty XMLConfiguration.
|
||||
|
||||
XMLConfiguration(char delim);
|
||||
/// Creates an empty XMLConfiguration, using the given
|
||||
/// delimiter char instead of the default '.'.
|
||||
|
||||
XMLConfiguration(Poco::XML::InputSource* pInputSource);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given InputSource.
|
||||
|
||||
XMLConfiguration(Poco::XML::InputSource* pInputSource, char delim);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given InputSource. Uses the given delimiter char instead
|
||||
/// of the default '.'.
|
||||
|
||||
XMLConfiguration(std::istream& istr);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given stream.
|
||||
|
||||
XMLConfiguration(std::istream& istr, char delim);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given stream. Uses the given delimiter char instead
|
||||
/// of the default '.'.
|
||||
|
||||
XMLConfiguration(const std::string& path);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given path.
|
||||
|
||||
XMLConfiguration(const std::string& path, char delim);
|
||||
/// Creates an XMLConfiguration and loads the XML document from
|
||||
/// the given path. Uses the given delimiter char instead
|
||||
/// of the default '.'.
|
||||
|
||||
XMLConfiguration(const Poco::XML::Document* pDocument);
|
||||
/// Creates the XMLConfiguration using the given XML document.
|
||||
|
||||
XMLConfiguration(const Poco::XML::Document* pDocument, char delim);
|
||||
/// Creates the XMLConfiguration using the given XML document.
|
||||
/// Uses the given delimiter char instead of the default '.'.
|
||||
|
||||
XMLConfiguration(const Poco::XML::Node* pNode);
|
||||
/// Creates the XMLConfiguration using the given XML node.
|
||||
|
||||
XMLConfiguration(const Poco::XML::Node* pNode, char delim);
|
||||
/// Creates the XMLConfiguration using the given XML node.
|
||||
/// Uses the given delimiter char instead of the default '.'.
|
||||
|
||||
void load(Poco::XML::InputSource* pInputSource);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given InputSource.
|
||||
|
||||
void load(std::istream& istr);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given stream.
|
||||
|
||||
void load(const std::string& path);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given file.
|
||||
|
||||
void load(const Poco::XML::Document* pDocument);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given XML document.
|
||||
|
||||
void load(const Poco::XML::Node* pNode);
|
||||
/// Loads the XML document containing the configuration data
|
||||
/// from the given XML node.
|
||||
|
||||
void loadEmpty(const std::string& rootElementName);
|
||||
/// Loads an empty XML document containing only the
|
||||
/// root element with the given name.
|
||||
|
||||
void save(const std::string& path) const;
|
||||
/// Writes the XML document containing the configuration data
|
||||
/// to the file given by path.
|
||||
|
||||
void save(std::ostream& str) const;
|
||||
/// Writes the XML document containing the configuration data
|
||||
/// to the given stream.
|
||||
|
||||
void save(Poco::XML::DOMWriter& writer, const std::string& path) const;
|
||||
/// Writes the XML document containing the configuration data
|
||||
/// to the file given by path, using the given DOMWriter.
|
||||
///
|
||||
/// This can be used to use a DOMWriter with custom options.
|
||||
|
||||
void save(Poco::XML::DOMWriter& writer, std::ostream& str) const;
|
||||
/// Writes the XML document containing the configuration data
|
||||
/// to the given stream.
|
||||
///
|
||||
/// This can be used to use a DOMWriter with custom options.
|
||||
|
||||
protected:
|
||||
bool getRaw(const std::string& key, std::string& value) const;
|
||||
void setRaw(const std::string& key, const std::string& value);
|
||||
void enumerate(const std::string& key, Keys& range) const;
|
||||
void removeRaw(const std::string& key);
|
||||
~XMLConfiguration();
|
||||
|
||||
private:
|
||||
const Poco::XML::Node* findNode(const std::string& key) const;
|
||||
Poco::XML::Node* findNode(const std::string& key);
|
||||
Poco::XML::Node* findNode(std::string::const_iterator& it, const std::string::const_iterator& end, Poco::XML::Node* pNode, bool create = false) const;
|
||||
static Poco::XML::Node* findElement(const std::string& name, Poco::XML::Node* pNode, bool create);
|
||||
static Poco::XML::Node* findElement(int index, Poco::XML::Node* pNode, bool create);
|
||||
static Poco::XML::Node* findElement(const std::string& attr, const std::string& value, Poco::XML::Node* pNode);
|
||||
static Poco::XML::Node* findAttribute(const std::string& name, Poco::XML::Node* pNode, bool create);
|
||||
|
||||
Poco::XML::AutoPtr<Poco::XML::Node> _pRoot;
|
||||
Poco::XML::AutoPtr<Poco::XML::Document> _pDocument;
|
||||
char _delim;
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Util
|
||||
|
||||
|
||||
#endif // Util_XMLConfiguration_INCLUDED
|
||||
|
||||
Reference in New Issue
Block a user