class Poco::Util::LayeredConfiguration

Overview

A LayeredConfiguration consists of a number of AbstractConfigurations. More…

#include <LayeredConfiguration.h>

class LayeredConfiguration: public Poco::Util::AbstractConfiguration
{
public:
    // structs

    struct ConfigItem;

    // methods

    void
    add(AbstractConfiguration* pConfig);

    void
    add(
        AbstractConfiguration* pConfig,
        bool shared
        );

    void
    add(
        AbstractConfiguration* pConfig,
        int priority
        );

    void
    add(
        AbstractConfiguration* pConfig,
        int priority,
        bool shared
        );

    void
    add(
        AbstractConfiguration* pConfig,
        int priority,
        bool writeable,
        bool shared
        );

    void
    addWriteable(
        AbstractConfiguration* pConfig,
        int priority
        );

    void
    addWriteable(
        AbstractConfiguration* pConfig,
        int priority,
        bool shared
        );

    void
    addFront(AbstractConfiguration* pConfig);

    void
    addFront(
        AbstractConfiguration* pConfig,
        bool shared
        );

    void
    removeConfiguration(AbstractConfiguration* pConfig);

protected:
    // typedefs

    typedef Poco::AutoPtr<AbstractConfiguration> ConfigPtr;

    // methods

    virtual
    bool
    getRaw(
        const std::string& key,
        std::string& value
        ) const;

    virtual
    void
    setRaw(
        const std::string& key,
        const std::string& value
        );

    virtual
    void
    enumerate(
        const std::string& key,
        Keys& range
        ) const;

    virtual
    void
    removeRaw(const std::string& key);

    int
    lowest() const;

    int
    highest() const;

    void
    insert(const ConfigItem& item);
};

Inherited Members

public:
    // typedefs

    typedef std::vector<std::string> Keys;

    // classes

    class KeyValue;

    // fields

    Poco::BasicEvent<KeyValue> propertyChanging;
    Poco::BasicEvent<const KeyValue> propertyChanged;
    Poco::BasicEvent<const std::string> propertyRemoving;
    Poco::BasicEvent<const std::string> propertyRemoved;

    // methods

    void
    duplicate() const;

    void
    release() const;

    int
    referenceCount() const;

    bool
    hasProperty(const std::string& key) const;

    bool
    hasOption(const std::string& key) const;

    bool
    has(const std::string& key) const;

    std::string
    getString(const std::string& key) const;

    std::string
    getString(
        const std::string& key,
        const std::string& defaultValue
        ) const;

    std::string
    getRawString(const std::string& key) const;

    std::string
    getRawString(
        const std::string& key,
        const std::string& defaultValue
        ) const;

    int
    getInt(const std::string& key) const;

    unsigned int
    getUInt(const std::string& key) const;

    int
    getInt(
        const std::string& key,
        int defaultValue
        ) const;

    unsigned int
    getUInt(
        const std::string& key,
        unsigned int defaultValue
        ) const;

    double
    getDouble(const std::string& key) const;

    double
    getDouble(
        const std::string& key,
        double defaultValue
        ) const;

    bool
    getBool(const std::string& key) const;

    bool
    getBool(
        const std::string& key,
        bool defaultValue
        ) const;

    virtual
    void
    setString(
        const std::string& key,
        const std::string& value
        );

    virtual
    void
    setInt(
        const std::string& key,
        int value
        );

    virtual
    void
    setUInt(
        const std::string& key,
        unsigned int value
        );

    virtual
    void
    setDouble(
        const std::string& key,
        double value
        );

    virtual
    void
    setBool(
        const std::string& key,
        bool value
        );

    void
    keys(Keys& range) const;

    void
    keys(
        const std::string& key,
        Keys& range
        ) const;

    const AbstractConfiguration*
    createView(const std::string& prefix) const;

    AbstractConfiguration*
    createView(const std::string& prefix);

    std::string
    expand(const std::string& value) const;

    void
    remove(const std::string& key);

    void
    enableEvents(bool enable = true);

    bool
    eventsEnabled() const;

protected:
    // methods

    virtual
    bool
    getRaw(
        const std::string& key,
        std::string& value
        ) const = 0;

    virtual
    void
    setRaw(
        const std::string& key,
        const std::string& value
        ) = 0;

    virtual
    void
    enumerate(
        const std::string& key,
        Keys& range
        ) const = 0;

    virtual
    void
    removeRaw(const std::string& key);

    void
    setRawWithEvent(
        const std::string& key,
        std::string value
        );

    static
    int
    parseInt(const std::string& value);

    static
    unsigned
    parseUInt(const std::string& value);

    static
    bool
    parseBool(const std::string& value);

Detailed Documentation

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.

Methods

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).

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.

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.

virtual
bool
getRaw(
    const std::string& key,
    std::string& value
    ) const

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
    )

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

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.