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