1 /** 2 * Interface for reading files and convert it to the `rpdl.tree.RpdlTree` 3 * 4 * Copyright: © 2017 Andrey Kabylin 5 * License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. 6 */ 7 8 module rpdl.reader; 9 10 import std.file; 11 import std.stdio; 12 import std.conv; 13 14 import rpdl.node; 15 import rpdl.value; 16 import rpdl.exception; 17 18 /// Declare interface for readers and tell them - how to read each type of node to file. 19 interface IReader { 20 /// 21 void readObjects(); 22 23 /// Read `rpdl.node.ObjectNode` and insert it to `parent` 24 void readObject(Node parent); 25 26 /// Read `rpdl.node.Parameter` and insert it to `parent` 27 void readParameter(Node parent); 28 29 /// Read `rpdl.value.Value` and insert it to `parent` 30 void readValue(Node parent); 31 32 /// Read `rpdl.value.NumberValue` and insert it to `parent` 33 void readNumberValue(Node parent); 34 35 /// Read `rpdl.value.BooleanValue` and insert it to `parent` 36 void readBooleanValue(Node parent); 37 38 /// Read `rpdl.value.StringValue` and insert it to `parent` 39 void readStringValue(Node parent); 40 41 /// Read `rpdl.value.IdentifierValue` and insert it to `parent` 42 void readIdentifierValue(Node parent); 43 44 /// Read `rpdl.value.ArrayValue` and insert it to `parent` 45 void readArrayValue(Node parent); 46 } 47 48 abstract class Reader : IReader { 49 this(Node root) { 50 this.root = root; 51 } 52 53 void read(in string fileName) { 54 this.file = File(fileName, "r"); 55 readObjects(); 56 } 57 58 protected: 59 Node root; 60 File file; 61 62 override void readObjects() {} 63 override void readObject(Node parent) {} 64 override void readParameter(Node parent) {} 65 override void readValue(Node parent) {} 66 override void readNumberValue(Node parent) {} 67 override void readBooleanValue(Node parent) {} 68 override void readStringValue(Node parent) {} 69 override void readIdentifierValue(Node parent) {} 70 override void readArrayValue(Node parent) {} 71 }