class ugcs::vsm::Properties

Overview

This class represents persistent set of properties which can be stored and loaded in/from any stream. More…

#include <properties.h>

class Properties
{
public:
    // typedefs

    typedef std::shared_ptr<Properties> Ptr;
    typedef ugcs::vsm::Param_exception<Exception_dummy_struct,> Exception;
    typedef ugcs::vsm::Derived_exception<Exception, Parse_exception_dummy_struct> Parse_exception;
    typedef ugcs::vsm::Derived_exception<Exception, Not_found_exception_dummy_struct> Not_found_exception;
    typedef ugcs::vsm::Derived_exception<Exception, Not_convertible_exception_dummy_struct> Not_convertible_exception;

    // structs

    struct Exception_dummy_struct;
    struct Not_convertible_exception_dummy_struct;
    struct Not_found_exception_dummy_struct;
    struct Parse_exception_dummy_struct;

    // classes

    class Iterator;
    class Property;

    // methods

    template <typename... Args>
    static Ptr Get_instance(Args&&... args);

    void Load(std::istream& stream);
    bool Exists(const std::string& key) const;
    std::string Get(const std::string& key) const;
    int32_t Get_int(const std::string& key) const;
    double Get_float(const std::string& key) const;
    void Set_description(const std::string& key, const std::string& description);
    void Set(const std::string& key, const std::string& value);
    void Set(const std::string& key, int32_t value);
    void Set(const std::string& key, double value);
    void Delete(const std::string& key);
    void Store(std::ostream& stream);
    Iterator begin(const std::string& prefix = std::string(), char separator = '.') const;
    Iterator end() const;
};

Detailed Documentation

This class represents persistent set of properties which can be stored and loaded in/from any stream.

Each property is a key and its value. The format of the text representation and overall concepts are corresponding to Java properties - http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html.

Typedefs

typedef std::shared_ptr<Properties> Ptr

Pointer type.

typedef ugcs::vsm::Derived_exception<Exception, Parse_exception_dummy_struct> Parse_exception

Definition of a new exception type.

typedef ugcs::vsm::Derived_exception<Exception, Not_found_exception_dummy_struct> Not_found_exception

Definition of a new exception type.

typedef ugcs::vsm::Derived_exception<Exception, Not_convertible_exception_dummy_struct> Not_convertible_exception

Definition of a new exception type.

Methods

template <typename... Args>
static Ptr Get_instance(Args&&... args)

Get global or create new properties instance.

void Load(std::istream& stream)

Load properties from text stream.

Parameters:

stream

Input text stream.

Parse_exception

if invalid data read from the specified stream.

bool Exists(const std::string& key) const

Check if the property with the specified key exists.

std::string Get(const std::string& key) const

Get string value of the property.

Parameters:

key

Key of the value to retrieve.

Not_found_exception

Value with specified key is not found.

Returns:

String representation of the value.

int32_t Get_int(const std::string& key) const

Get integer value of the property.

Base for the number is automatically detected - values which start by “0x” or “0X” prefix are interpreted as hexadecimal, started by “0” - as octal, all the rest as decimal.

Parameters:

key

Key of the value to retrieve.

Not_found_exception

if the value with specified key is not found.

Not_convertible_exception

if the value cannot be converted to integer representation.

Returns:

Integer representation of the value.

double Get_float(const std::string& key) const

Get floating point number value of the property.

Parameters:

key

Key of the value to retrieve.

Not_found_exception

if the value with specified key is not found.

Not_convertible_exception

if the value cannot be converted to floating point number representation.

Returns:

Floating point number representation of the value.

void Set_description(const std::string& key, const std::string& description)

Set the description of the property.

If the key does not exist the new entry is added with no value.

Parameters:

key

Key for the new property.

description

Description string of the property. Can be multi-line (separated by

). Blank lines are allowed. All lines will be prepended by ‘#’ on Store.

void Set(const std::string& key, const std::string& value)

Set string value of the property.

If the key does not exist the new entry is added.

Parameters:

key

Key for the new property.

value

String representation for the property.

void Set(const std::string& key, int32_t value)

Set integer value of the property.

If the key does not exist the new entry is added.

Parameters:

key

Key for the new property.

value

Integer representation for the property.

void Set(const std::string& key, double value)

Set floating point number value of the property.

If the key does not exist the new entry is added.

Parameters:

key

Key for the new property.

value

Floating point number representation for the property.

void Delete(const std::string& key)

Delete the property with the specified key.

Parameters:

key

Key of the property to delete.

Not_found_exception

if the value with specified key is not found.

void Store(std::ostream& stream)

Store properties into the specified stream.

Iterator begin(const std::string& prefix = std::string(), char separator = '.') const

Begin properties iteration.

Parameters:

prefix

Prefix to match property name with.

separator

Separator used for property name components separation.

Returns:

Iterator object.

Iterator end() const

Iterator for one-past-the-end position.