Registry

A registry for managing multiple mappings of string-based names to configuration entries

Constructors

this
this(bool allowOverwritingOfEntries)

Creates a new Registry and sets the overwriting policy

Members

Functions

getEntry_nothrow
bool getEntry_nothrow(string name, ConfigEntry entry)

Obtain a configuration entry at the given key

hasEntry
bool hasEntry(string name)

Checks if an entry is present

newEntry
void newEntry(string name, ConfigEntry entry)

Creates a new entry and adds it

newEntry
void newEntry(string name, int numeric)
newEntry
void newEntry(string name, string text)
newEntry
void newEntry(string name, bool flag)
newEntry
void newEntry(string name, string[] array)
opBinaryRight
ConfigEntry* opBinaryRight(string name)

Obtains a pointer to the configuration entry at the given key. Allowing you to swap out its contents directly if you want to.

opIndex
ConfigEntry opIndex(string name)

Obtain a configuration entry at the given key

opIndexAssign
void opIndexAssign(ConfigEntry entry, string name)

Assigns the provided configuration entry to the provided name

opIndexAssign
void opIndexAssign(size_t numeric, string name)
opIndexAssign
void opIndexAssign(string entry, string name)
opIndexAssign
void opIndexAssign(bool flag, string name)
opIndexAssign
void opIndexAssign(string[] array, string name)
opSlice
RegistryEntry[] opSlice()

Returns all the entries in the registry as a mapping of their name to their configuration entry

setAllowOverwrite
void setAllowOverwrite(bool flag)

Set whether or not the overwriting of an entry should be allowed

setEntry
void setEntry(string name, ConfigEntry entry)

Sets the entry at the given name to the provided entry

Examples

Tests out the working with the registry in order to manage a set of named configuration entries

Registry reg = Registry(false);

// Add an entry
reg.newEntry("name", "Tristan");

// Check it exists
assert(reg.hasEntry("name"));

// Adding it again should fail
try
{
    reg.newEntry("name", "Tristan2");
    assert(false);
}
catch(RegistryException e)
{

}

// Check that the entry still has the right value
assert(cast(string)reg["name"] == "Tristan");

// // Add a new entry and test its prescence
reg["age"] = 24;
assert(cast(int)reg["age"]);

// // Update it
reg["age"] = 25;
assert(cast(int)reg["age"] == 25);

// Obtain a handle on the configuration
// entry, then update it and read it back
// to confirm
ConfigEntry* ageEntry = "age" in reg;
*ageEntry = ConfigEntry.ofNumeric(69_420);
assert(cast(int)reg["age"] == 69_420);

// Should not be able to set entry it not yet existent
try
{
    reg.setEntry("male", ConfigEntry.ofFlag(true));
    assert(false);
}
catch(RegistryException e)
{

}

// All entries
RegistryEntry[] all = reg[];
assert(all.length == 2);
writeln(all);

Meta