1 /** 2 Low-level class for creating parsers for XML files. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.xmlparser; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.classdb; 23 import godot.reference; 24 /** 25 Low-level class for creating parsers for XML files. 26 27 This class can serve as base to make custom XML parsers. Since XML is a very flexible standard, this interface is low level so it can be applied to any possible schema. 28 */ 29 @GodotBaseClass struct XMLParser 30 { 31 enum string _GODOT_internal_name = "XMLParser"; 32 public: 33 @nogc nothrow: 34 union { godot_object _godot_object; Reference _GODOT_base; } 35 alias _GODOT_base this; 36 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 37 package(godot) __gshared bool _classBindingInitialized = false; 38 package(godot) static struct _classBinding 39 { 40 __gshared: 41 @GodotName("read") GodotMethod!(GodotError) read; 42 @GodotName("get_node_type") GodotMethod!(XMLParser.NodeType) getNodeType; 43 @GodotName("get_node_name") GodotMethod!(String) getNodeName; 44 @GodotName("get_node_data") GodotMethod!(String) getNodeData; 45 @GodotName("get_node_offset") GodotMethod!(long) getNodeOffset; 46 @GodotName("get_attribute_count") GodotMethod!(long) getAttributeCount; 47 @GodotName("get_attribute_name") GodotMethod!(String, long) getAttributeName; 48 @GodotName("get_attribute_value") GodotMethod!(String, long) getAttributeValue; 49 @GodotName("has_attribute") GodotMethod!(bool, String) hasAttribute; 50 @GodotName("get_named_attribute_value") GodotMethod!(String, String) getNamedAttributeValue; 51 @GodotName("get_named_attribute_value_safe") GodotMethod!(String, String) getNamedAttributeValueSafe; 52 @GodotName("is_empty") GodotMethod!(bool) isEmpty; 53 @GodotName("get_current_line") GodotMethod!(long) getCurrentLine; 54 @GodotName("skip_section") GodotMethod!(void) skipSection; 55 @GodotName("seek") GodotMethod!(GodotError, long) seek; 56 @GodotName("open") GodotMethod!(GodotError, String) open; 57 @GodotName("open_buffer") GodotMethod!(GodotError, PoolByteArray) openBuffer; 58 } 59 bool opEquals(in XMLParser other) const { return _godot_object.ptr is other._godot_object.ptr; } 60 XMLParser opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 61 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 62 mixin baseCasts; 63 static XMLParser _new() 64 { 65 static godot_class_constructor constructor; 66 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("XMLParser"); 67 if(constructor is null) return typeof(this).init; 68 return cast(XMLParser)(constructor()); 69 } 70 @disable new(size_t s); 71 /// 72 enum NodeType : int 73 { 74 /** 75 There's no node (no file or buffer opened) 76 */ 77 nodeNone = 0, 78 /** 79 Element (tag) 80 */ 81 nodeElement = 1, 82 /** 83 End of element 84 */ 85 nodeElementEnd = 2, 86 /** 87 Text node 88 */ 89 nodeText = 3, 90 /** 91 Comment node 92 */ 93 nodeComment = 4, 94 /** 95 CDATA content 96 */ 97 nodeCdata = 5, 98 /** 99 Unknown node 100 */ 101 nodeUnknown = 6, 102 } 103 /// 104 enum Constants : int 105 { 106 nodeNone = 0, 107 nodeElement = 1, 108 nodeElementEnd = 2, 109 nodeText = 3, 110 nodeComment = 4, 111 nodeCdata = 5, 112 nodeUnknown = 6, 113 } 114 /** 115 Read the next node of the file. This returns an error code. 116 */ 117 GodotError read() 118 { 119 checkClassBinding!(typeof(this))(); 120 return ptrcall!(GodotError)(_classBinding.read, _godot_object); 121 } 122 /** 123 Get the type of the current node. Compare with `NODE_*` constants. 124 */ 125 XMLParser.NodeType getNodeType() 126 { 127 checkClassBinding!(typeof(this))(); 128 return ptrcall!(XMLParser.NodeType)(_classBinding.getNodeType, _godot_object); 129 } 130 /** 131 Get the name of the current element node. This will raise an error if the current node type is not `NODE_ELEMENT` nor `NODE_ELEMENT_END` 132 */ 133 String getNodeName() const 134 { 135 checkClassBinding!(typeof(this))(); 136 return ptrcall!(String)(_classBinding.getNodeName, _godot_object); 137 } 138 /** 139 Get the contents of a text node. This will raise an error in any other type of node. 140 */ 141 String getNodeData() const 142 { 143 checkClassBinding!(typeof(this))(); 144 return ptrcall!(String)(_classBinding.getNodeData, _godot_object); 145 } 146 /** 147 Get the byte offset of the current node since the beginning of the file or buffer. 148 */ 149 long getNodeOffset() const 150 { 151 checkClassBinding!(typeof(this))(); 152 return ptrcall!(long)(_classBinding.getNodeOffset, _godot_object); 153 } 154 /** 155 Get the amount of attributes in the current element. 156 */ 157 long getAttributeCount() const 158 { 159 checkClassBinding!(typeof(this))(); 160 return ptrcall!(long)(_classBinding.getAttributeCount, _godot_object); 161 } 162 /** 163 Get the name of the attribute specified by the index in `idx` argument. 164 */ 165 String getAttributeName(in long idx) const 166 { 167 checkClassBinding!(typeof(this))(); 168 return ptrcall!(String)(_classBinding.getAttributeName, _godot_object, idx); 169 } 170 /** 171 Get the value of the attribute specified by the index in `idx` argument. 172 */ 173 String getAttributeValue(in long idx) const 174 { 175 checkClassBinding!(typeof(this))(); 176 return ptrcall!(String)(_classBinding.getAttributeValue, _godot_object, idx); 177 } 178 /** 179 Check whether or not the current element has a certain attribute. 180 */ 181 bool hasAttribute(StringArg0)(in StringArg0 name) const 182 { 183 checkClassBinding!(typeof(this))(); 184 return ptrcall!(bool)(_classBinding.hasAttribute, _godot_object, name); 185 } 186 /** 187 Get the value of a certain attribute of the current element by name. This will raise an error if the element has no such attribute. 188 */ 189 String getNamedAttributeValue(StringArg0)(in StringArg0 name) const 190 { 191 checkClassBinding!(typeof(this))(); 192 return ptrcall!(String)(_classBinding.getNamedAttributeValue, _godot_object, name); 193 } 194 /** 195 Get the value of a certain attribute of the current element by name. This will return an empty $(D String) if the attribute is not found. 196 */ 197 String getNamedAttributeValueSafe(StringArg0)(in StringArg0 name) const 198 { 199 checkClassBinding!(typeof(this))(); 200 return ptrcall!(String)(_classBinding.getNamedAttributeValueSafe, _godot_object, name); 201 } 202 /** 203 Check whether the current element is empty (this only works for completely empty tags, e.g. <element \>). 204 */ 205 bool isEmpty() const 206 { 207 checkClassBinding!(typeof(this))(); 208 return ptrcall!(bool)(_classBinding.isEmpty, _godot_object); 209 } 210 /** 211 Get the current line in the parsed file (currently not implemented). 212 */ 213 long getCurrentLine() const 214 { 215 checkClassBinding!(typeof(this))(); 216 return ptrcall!(long)(_classBinding.getCurrentLine, _godot_object); 217 } 218 /** 219 Skips the current section. If the node contains other elements, they will be ignored and the cursor will go to the closing of the current element. 220 */ 221 void skipSection() 222 { 223 checkClassBinding!(typeof(this))(); 224 ptrcall!(void)(_classBinding.skipSection, _godot_object); 225 } 226 /** 227 Move the buffer cursor to a certain offset (since the beginning) and read the next node there. This returns an error code. 228 */ 229 GodotError seek(in long position) 230 { 231 checkClassBinding!(typeof(this))(); 232 return ptrcall!(GodotError)(_classBinding.seek, _godot_object, position); 233 } 234 /** 235 Open a XML file for parsing. This returns an error code. 236 */ 237 GodotError open(StringArg0)(in StringArg0 file) 238 { 239 checkClassBinding!(typeof(this))(); 240 return ptrcall!(GodotError)(_classBinding.open, _godot_object, file); 241 } 242 /** 243 Open a XML raw buffer for parsing. This returns an error code. 244 */ 245 GodotError openBuffer(in PoolByteArray buffer) 246 { 247 checkClassBinding!(typeof(this))(); 248 return ptrcall!(GodotError)(_classBinding.openBuffer, _godot_object, buffer); 249 } 250 }