template<class T>
Corrade::Utility::ConfigurationValue struct

Configuration value parser and writer.

Functions in this struct are called internally by ConfigurationGroup functions to convert values from and to templated types. Reimplement the structure with template specialization to allow saving and getting non-standard types into and from configuration files.

Example: custom structure

We have structure named Foo and want to store it in configuration file as a sequence of two integers separated by a space.

#include <Corrade/Utility/ConfigurationGroup.h>

struct Foo {
    int a, b;
};

namespace Corrade { namespace Utility {

template<> struct ConfigurationValue<Foo> {
    static std::string toString(const Foo& value, ConfigurationValueFlags flags) {
        return
            ConfigurationValue<int>::toString(value.a, flags) + ' ' +
            ConfigurationValue<int>::toString(value.b, flags);
    }

    static Foo fromString(const std::string& stringValue, ConfigurationValueFlags flags) {
        std::istringstream i(stringValue);
        std::string a, b;

        Foo foo;
        (i >> a) && (area.a = ConfigurationValue<int>::fromString(a, flags));
        (i >> b) && (area.b = ConfigurationValue<int>::fromString(a, flags));
        return foo;
    }
};

}}

When saving the structure into configuration file using e.g. configuration->addValue("fooValue", Foo{6, 7});, the result will look like this:

fooValue=6 7

Public static functions

static auto toString(const T& value, ConfigurationValueFlags flags) -> std::string
Convert value to string.
static auto fromString(const std::string& stringValue, ConfigurationValueFlags flags) -> T
Convert value from string.

Function documentation

template<class T>
static std::string Corrade::Utility::ConfigurationValue<T>::toString(const T& value, ConfigurationValueFlags flags)

Convert value to string.

Parameters
value Value
flags Flags
Returns Value as string

template<class T>
static T Corrade::Utility::ConfigurationValue<T>::fromString(const std::string& stringValue, ConfigurationValueFlags flags)

Convert value from string.

Parameters
stringValue Value as string
flags Flags
Returns Value