Skip to content

ConfigSchema

#include <mrx/core/config/ConfigSchema.hpp>
class mrx::core::ConfigSchema

Declares and validates a typed application configuration schema.

ConfigSchema separates the schema definition from the parser. The load() convenience method reads a QSettings INI file, while validate() accepts normalized dotted values from another parser. A typical declaration is:

ConfigSchema schema;
schema.section(QStringLiteral("network"))
    .required<QString>(QStringLiteral("host"))
    .optional<quint16>(QStringLiteral("port"), 8080)
    .range(1, 65535);

const ConfigResult result = schema.load(QStringLiteral("application.ini"));
if (result)
{
    const Config config = result.value();
    const quint16 port = config.value<quint16>(QStringLiteral("network"), QStringLiteral("port"));
    const ConfigResult updated = schema.validatedValue(
        config, QStringLiteral("network"), QStringLiteral("port"), QStringLiteral("6000")
    );
}

Supported declarations include QString, bool, signed and unsigned integral types, floating point types, and Qt meta-object registered enumerations. Lists are intentionally not part of this initial API.

ReturnNameDescription
ConfigSchemaConstructs an empty configuration schema.
SectionsectionDeclares a required section and returns its fluent builder.
SectionoptionalSectionDeclares a section that may be absent and returns its fluent builder.
ConfigResultload constLoads and validates an INI file using QSettings::IniFormat.
ConfigResultvalidate constValidates normalized dotted values without coupling the schema to a parser.
boolhasSection constChecks whether the schema declares a section.
boolhasProperty constChecks whether the schema declares a property inside a section.
ConfigResultvalidatedValue constValidates one proposed property value over an existing immutable Config snapshot.

ConfigSchema()

Constructs an empty configuration schema.

Use section() and optionalSection() to declare the accepted configuration shape before calling load() or validate().


Section section(const QString& name)

Declares a required section and returns its fluent builder.

Builder used to declare properties in the section.

NameTypeDescription
nameconst QString&INI section name.

Section optionalSection(const QString& name)

Declares a section that may be absent and returns its fluent builder.

Builder used to declare properties in the optional section.

NameTypeDescription
nameconst QString&INI section name.

const
ConfigResult load(const QString& fileName) const

Loads and validates an INI file using QSettings::IniFormat.

Successful normalized configuration or all parser/validation errors.

NameTypeDescription
fileNameconst QString&Path to the configuration file.

const
ConfigResult validate(const QMap<QString, QVariant>& values) const

Validates normalized dotted values without coupling the schema to a parser.

Successful normalized configuration or all validation errors.

NameTypeDescription
valuesconst QMap<QString, QVariant>&Map keyed as section.property.

const
bool hasSection(const QString& section) const

Checks whether the schema declares a section.

true when the section exists in the schema, regardless of whether it is required.

This is schema introspection only. It does not inspect a loaded Config and does not imply that the section is present in a candidate value map.

NameTypeDescription
sectionconst QString&Section name to look up exactly as declared through section() or optionalSection().

const
bool hasProperty(const QString& section, const QString& property) const

Checks whether the schema declares a property inside a section.

true when both the section and property are declared by the schema.

This is schema introspection only. It does not inspect a loaded Config and does not imply that the property is present in a candidate value map.

NameTypeDescription
sectionconst QString&Section name to look up exactly as declared.
propertyconst QString&Property name to look up exactly as declared inside section.

const
ConfigResult validatedValue(const Config& current, const QString& section, const QString& property, const QVariant& value) const

Validates one proposed property value over an existing immutable Config snapshot.

Successful normalized configuration for the overlay, or all schema/validation errors.

validatedValue() is the write-overlay companion to validate(). It first rejects undeclared section/property paths with UnknownSection or UnknownProperty so an application can block unsupported writes before it persists a value. For declared paths, it copies current, overlays section.property with value, and then runs the normal full-schema validation pass. Required siblings, defaults, conversions, range constraints, and custom validators are therefore evaluated in the context of the supplied snapshot without adding persistence or runtime settings-manager policy to ConfigSchema. The returned ConfigResult can be chained into another validatedValue() call by passing its value() after checking the result is successful.

NameTypeDescription
currentconst Config&Current successful Config snapshot; it is not modified.
sectionconst QString&Declared section that owns the property being changed.
propertyconst QString&Declared property receiving the proposed value.
valueconst QVariant&Proposed raw value, parsed and validated using the property’s schema declaration.