1 module sily.dyaml; 2 3 import dyaml; 4 5 /** 6 Checks if node is NodeType. 7 8 Usage: 9 --- 10 node.isType!NodeType.mapping; 11 --- 12 13 Params: 14 node = Node to check 15 */ 16 public bool isType(NodeType T)(Node node) { 17 if (node.type == T) { 18 return true; 19 } 20 return false; 21 } 22 23 /** 24 Checks if node has key of NodeType. 25 26 Usage: 27 --- 28 node.hasKeyType!(NodeType.mapping)("keymap"); 29 --- 30 31 Params: 32 node = Node to get key from 33 key = Key name 34 */ 35 public bool hasKeyType(NodeType T)(Node node, string key) { 36 if (node.containsKey(key)) { 37 if (node[key].type == T) { 38 return true; 39 } 40 } 41 return false; 42 } 43 44 /** 45 Checks if node has key of type. 46 47 Usage: 48 --- 49 node.hasKeyAs!bool("useColor"); 50 --- 51 52 Params: 53 node = Node to get key from 54 key = Key name 55 */ 56 public bool hasKeyAs(T)(Node node, string key) { 57 if (node.containsKey(key)) { 58 if (node[key].convertsTo!T) { 59 return true; 60 } 61 } 62 return false; 63 } 64 65 /** 66 Puts value from node key if key exists. 67 68 Usage: 69 --- 70 node.getKey!bool(&useColor, "useColor"); 71 --- 72 73 Params: 74 node = Node to get key from 75 variable = Pointer to variable 76 field = Key name 77 */ 78 public void getKey(T)(Node node, T* variable, string field) { 79 if (node.hasKeyAs!T(field)) { 80 *variable = node[field].as!T; 81 } 82 }