1 /** 2 * Copyright: © 2012-2014 Anton Gushcha 3 * License: Subject to the terms of the MIT license, as written in the included LICENSE file. 4 * Authors: NCrashed <ncrashed@gmail.com>, 5 * LeMarwin <lemarwin42@gmail.com>, 6 * Nazgull09 <nazgull90@gmail.com> 7 */ 8 module devol.argument; 9 10 import devol.type; 11 import devol.serializable; 12 import std.array; 13 import std.conv; 14 15 import dyaml.all; 16 17 import devol.std.line; 18 import devol.std.argscope; 19 20 abstract class Argument : ISerializable 21 { 22 this(Type type) 23 { 24 pType = type; 25 } 26 27 @property Type type() 28 { 29 assert(pType); 30 return pType; 31 } 32 33 @property string tostring(uint depth=0) 34 { 35 return ""; 36 } 37 38 @property ulong children() 39 { 40 return 1; 41 } 42 43 @property ulong leafs() 44 { 45 return 1; 46 } 47 48 private Type pType; 49 50 Node saveYaml(); 51 52 static Argument loadYaml(Type type, Node node) 53 { 54 switch(node["class"].as!string) 55 { 56 case("line"): 57 { 58 return Line.loadYaml(node); 59 } 60 case("scope"): 61 { 62 return ArgScope.loadYaml(node); 63 } 64 case("plain"): 65 { 66 return type.loadArgument(node); 67 } 68 default: 69 { 70 assert(false, "Failed to load! Unknown label!"); 71 } 72 } 73 } 74 75 string genDot(ref size_t nameIndex, out string nodeName) 76 { 77 auto builder = appender!string; 78 nodeName = "n"~to!string(nameIndex++); 79 builder.put(nodeName); 80 builder.put("; \n"); 81 82 builder.put(nodeName); 83 builder.put("[label=\""); 84 builder.put(tostring(0)); 85 builder.put("\"] ;\n"); 86 87 return builder.data; 88 } 89 90 void randomChange(); 91 void randomChange(string maxChange); 92 @property Argument dup(); 93 }