Config

Container for configuration files with compile-time format and members.

The file is saved in a text file in format "field: value", one per line, with every value converted into a string. Supported values are the basic numeric types, string and arrays of these two.

Use value to indicate a field with a static type, _ to insert an empty line and a string to insert a comment.

struct Config (
E...
) if (
areValidArgs!E
) {}

Members

Functions

load
void load(string file)

Loads the values from a file.

save
void save(string file)
void save()

Saves the field's values into a file. If none is given the values are saved in the same file they have been loaded from (if the load method has been called), otherwise the file is not saved.

Examples

Config!(Value!string("name"), _, Value!uint("players", 0), Value!uint("max", 256), _, Value!(uint[])("array")) example;
assert(example.players == 0);
assert(example.max == 256);

alias Example = Config!("comment", value("field", "value"), _, value("int", 12u));
Example.init.save("example.txt");
assert(read("example.txt") == "# comment\nfield: value\n\nint: 12\n"); // with posix's line-endings

Meta