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

Configuration value parser and writer.

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

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) && (foo.a = ConfigurationValue<int>::fromString(a, flags));
        (i >> b) && (foo.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