Rename node objects

This commit is contained in:
Mike Bierlee 2022-09-24 01:15:16 +03:00
parent c6e85e8eba
commit cde58e1224

View file

@ -29,7 +29,7 @@ class PathParseException : Exception {
interface ConfigNode { interface ConfigNode {
} }
class NodeValue : ConfigNode { class ValueNode : ConfigNode {
string value; string value;
this() { this() {
@ -40,7 +40,7 @@ class NodeValue : ConfigNode {
} }
} }
class NodeObject : ConfigNode { class ObjectNode : ConfigNode {
ConfigNode[string] children; ConfigNode[string] children;
this() { this() {
@ -51,7 +51,7 @@ class NodeObject : ConfigNode {
} }
} }
class NodeArray : ConfigNode { class ArrayNode : ConfigNode {
ConfigNode[] children; ConfigNode[] children;
this() { this() {
@ -63,7 +63,7 @@ class NodeArray : ConfigNode {
this(string[] values...) { this(string[] values...) {
foreach (string value; values) { foreach (string value; values) {
children ~= new NodeValue(value); children ~= new ValueNode(value);
} }
} }
} }
@ -126,7 +126,7 @@ class ConfigDictionary {
enforce!ConfigReadException(configPath.length > 0, "Supplied config path is empty"); enforce!ConfigReadException(configPath.length > 0, "Supplied config path is empty");
if (configPath == ".") { if (configPath == ".") {
auto rootValue = cast(NodeValue) rootNode; auto rootValue = cast(ValueNode) rootNode;
if (rootValue) { if (rootValue) {
return rootValue.value; return rootValue.value;
} else { } else {
@ -140,7 +140,7 @@ class ConfigDictionary {
while (currentPathSegment !is null) { while (currentPathSegment !is null) {
auto arrayPath = cast(ArrayPathSegment) currentPathSegment; auto arrayPath = cast(ArrayPathSegment) currentPathSegment;
if (arrayPath) { if (arrayPath) {
auto arrayNode = cast(NodeArray) currentNode; auto arrayNode = cast(ArrayNode) currentNode;
if (arrayNode) { if (arrayNode) {
currentNode = arrayNode.children[arrayPath.index]; currentNode = arrayNode.children[arrayPath.index];
} }
@ -149,7 +149,7 @@ class ConfigDictionary {
currentPathSegment = path.getNextSegment(); currentPathSegment = path.getNextSegment();
} }
auto value = cast(NodeValue) currentNode; auto value = cast(ValueNode) currentNode;
if (value) { if (value) {
return value.value; return value.value;
} else { } else {
@ -164,9 +164,9 @@ version (unittest) {
@("Dictionary creation") @("Dictionary creation")
unittest { unittest {
auto root = new NodeObject([ auto root = new ObjectNode([
"english": new NodeArray([new NodeValue("one"), new NodeValue("two")]), "english": new ArrayNode([new ValueNode("one"), new ValueNode("two")]),
"spanish": new NodeArray(new NodeValue("uno"), new NodeValue("dos")) "spanish": new ArrayNode(new ValueNode("uno"), new ValueNode("dos"))
]); ]);
auto dictionary = new ConfigDictionary(); auto dictionary = new ConfigDictionary();
@ -183,7 +183,7 @@ version (unittest) {
@("Get value in dictionary with empty path fails") @("Get value in dictionary with empty path fails")
unittest { unittest {
auto dictionary = new ConfigDictionary(); auto dictionary = new ConfigDictionary();
dictionary.rootNode = new NodeValue("hehehe"); dictionary.rootNode = new ValueNode("hehehe");
assertThrown!ConfigReadException(dictionary.get("")); assertThrown!ConfigReadException(dictionary.get(""));
} }
@ -191,7 +191,7 @@ version (unittest) {
@("Get value in root") @("Get value in root")
unittest { unittest {
auto dictionary = new ConfigDictionary(); auto dictionary = new ConfigDictionary();
dictionary.rootNode = new NodeValue("yup"); dictionary.rootNode = new ValueNode("yup");
assert(dictionary.get(".") == "yup"); assert(dictionary.get(".") == "yup");
} }
@ -199,7 +199,7 @@ version (unittest) {
@("Get value in root fails when root is not a value") @("Get value in root fails when root is not a value")
unittest { unittest {
auto dictionary = new ConfigDictionary(); auto dictionary = new ConfigDictionary();
dictionary.rootNode = new NodeArray(); dictionary.rootNode = new ArrayNode();
assertThrown!ConfigReadException(dictionary.get(".")); assertThrown!ConfigReadException(dictionary.get("."));
} }
@ -207,7 +207,7 @@ version (unittest) {
@("Get array value from root") @("Get array value from root")
unittest { unittest {
auto dictionary = new ConfigDictionary(); auto dictionary = new ConfigDictionary();
dictionary.rootNode = new NodeArray("aap", "noot", "mies"); dictionary.rootNode = new ArrayNode("aap", "noot", "mies");
assert(dictionary.get("[0]") == "aap"); assert(dictionary.get("[0]") == "aap");
assert(dictionary.get("[1]") == "noot"); assert(dictionary.get("[1]") == "noot");