mirror of https://github.com/deavmi/niknaks
Compare commits
3 Commits
2cecbf1467
...
f65b442376
Author | SHA1 | Date |
---|---|---|
Tristan B. Velloza Kildaire | f65b442376 | |
Tristan B. Velloza Kildaire | a1631da8d9 | |
Tristan B. Velloza Kildaire | b3dadf6228 |
|
@ -2,6 +2,12 @@ module niknaks.config;
|
|||
|
||||
import std.string : format;
|
||||
|
||||
|
||||
version(unittest)
|
||||
{
|
||||
import std.stdio : writeln;
|
||||
}
|
||||
|
||||
private union ConfigValue
|
||||
{
|
||||
string text;
|
||||
|
@ -284,7 +290,7 @@ public struct Registry
|
|||
return true;
|
||||
}
|
||||
|
||||
public ConfigEntry getEntry(string name)
|
||||
public ConfigEntry opIndex(string name)
|
||||
{
|
||||
ConfigEntry entry;
|
||||
if(!getEntry_nothrow(name, entry))
|
||||
|
@ -362,39 +368,71 @@ public struct Registry
|
|||
newEntry(name, entry, this.allowOverwriteEntry, false);
|
||||
}
|
||||
|
||||
public ConfigEntry opIndex(string name)
|
||||
{
|
||||
return getEntry(name);
|
||||
}
|
||||
|
||||
|
||||
// ALlows overwriting ALWAYS
|
||||
// or should it NOT?
|
||||
|
||||
/**
|
||||
* Assigns the provided configuration
|
||||
* entry to the provided name
|
||||
*
|
||||
* Take note that using this method
|
||||
* will both create the entry if it
|
||||
* does not yet exist
|
||||
*
|
||||
* Params:
|
||||
* entry = the entry to add
|
||||
* name = the name at which to
|
||||
* add the entry
|
||||
*/
|
||||
public void opIndexAssign(ConfigEntry entry, string name)
|
||||
{
|
||||
newEntry(name, entry, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* See_Also: `opIndexAssign(ConfigEntry, string)`
|
||||
*/
|
||||
public void opIndexAssign(int numeric, string name)
|
||||
{
|
||||
opIndexAssign(ConfigEntry.ofNumeric(numeric), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* See_Also: `opIndexAssign(ConfigEntry, string)`
|
||||
*/
|
||||
public void opIndexAssign(string entry, string name)
|
||||
{
|
||||
opIndexAssign(ConfigEntry.ofText(entry), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* See_Also: `opIndexAssign(ConfigEntry, string)`
|
||||
*/
|
||||
public void opIndexAssign(bool flag, string name)
|
||||
{
|
||||
opIndexAssign(ConfigEntry.ofFlag(flag), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* See_Also: `opIndexAssign(ConfigEntry, string)`
|
||||
*/
|
||||
public void opIndexAssign(string[] array, string name)
|
||||
{
|
||||
opIndexAssign(ConfigEntry.ofArray(array), name);
|
||||
}
|
||||
|
||||
public RegistryEntry[] getEntries()
|
||||
/**
|
||||
* Returns all the entries in the
|
||||
* registry as a mapping of their
|
||||
* name to their configuration entry
|
||||
*
|
||||
* See_Also: RegistryEntry
|
||||
* Returns: an array of registry
|
||||
* entries
|
||||
*/
|
||||
public RegistryEntry[] opSlice()
|
||||
{
|
||||
RegistryEntry[] entrieS;
|
||||
foreach(string entryName; this.entries.keys())
|
||||
|
@ -404,18 +442,14 @@ public struct Registry
|
|||
|
||||
return entrieS;
|
||||
}
|
||||
|
||||
public RegistryEntry[] opSlice()
|
||||
{
|
||||
return getEntries();
|
||||
}
|
||||
}
|
||||
|
||||
version(unittest)
|
||||
{
|
||||
import std.stdio : writeln;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests out the working with the
|
||||
* registry in order to manage
|
||||
* a set of named configuration
|
||||
* entries
|
||||
*/
|
||||
unittest
|
||||
{
|
||||
Registry reg = Registry(false);
|
||||
|
|
Loading…
Reference in New Issue