1 /**
2 Data class wrapper for decoded JSON.
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.jsonparseresult;
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 Data class wrapper for decoded JSON.
27 
28 Returned by $(D JSON.parse), $(D JSONParseResult) contains the decoded JSON or error information if the JSON source wasn't successfully parsed. You can check if the JSON source was successfully parsed with `if json_result.error == OK`.
29 */
30 @GodotBaseClass struct JSONParseResult
31 {
32 	package(godot) enum string _GODOT_internal_name = "JSONParseResult";
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_error") GodotMethod!(GodotError) getError;
43 		@GodotName("get_error_line") GodotMethod!(long) getErrorLine;
44 		@GodotName("get_error_string") GodotMethod!(String) getErrorString;
45 		@GodotName("get_result") GodotMethod!(Variant) getResult;
46 		@GodotName("set_error") GodotMethod!(void, long) setError;
47 		@GodotName("set_error_line") GodotMethod!(void, long) setErrorLine;
48 		@GodotName("set_error_string") GodotMethod!(void, String) setErrorString;
49 		@GodotName("set_result") GodotMethod!(void, Variant) setResult;
50 	}
51 	/// 
52 	pragma(inline, true) bool opEquals(in JSONParseResult other) const
53 	{ return _godot_object.ptr is other._godot_object.ptr; }
54 	/// 
55 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
56 	{ _godot_object.ptr = n; return null; }
57 	/// 
58 	pragma(inline, true) bool opEquals(typeof(null) n) const
59 	{ return _godot_object.ptr is n; }
60 	/// 
61 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
62 	mixin baseCasts;
63 	/// Construct a new instance of JSONParseResult.
64 	/// Note: use `memnew!JSONParseResult` instead.
65 	static JSONParseResult _new()
66 	{
67 		static godot_class_constructor constructor;
68 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("JSONParseResult");
69 		if(constructor is null) return typeof(this).init;
70 		return cast(JSONParseResult)(constructor());
71 	}
72 	@disable new(size_t s);
73 	/**
74 	
75 	*/
76 	GodotError getError() const
77 	{
78 		checkClassBinding!(typeof(this))();
79 		return ptrcall!(GodotError)(GDNativeClassBinding.getError, _godot_object);
80 	}
81 	/**
82 	
83 	*/
84 	long getErrorLine() const
85 	{
86 		checkClassBinding!(typeof(this))();
87 		return ptrcall!(long)(GDNativeClassBinding.getErrorLine, _godot_object);
88 	}
89 	/**
90 	
91 	*/
92 	String getErrorString() const
93 	{
94 		checkClassBinding!(typeof(this))();
95 		return ptrcall!(String)(GDNativeClassBinding.getErrorString, _godot_object);
96 	}
97 	/**
98 	
99 	*/
100 	Variant getResult() const
101 	{
102 		checkClassBinding!(typeof(this))();
103 		return ptrcall!(Variant)(GDNativeClassBinding.getResult, _godot_object);
104 	}
105 	/**
106 	
107 	*/
108 	void setError(in long error)
109 	{
110 		checkClassBinding!(typeof(this))();
111 		ptrcall!(void)(GDNativeClassBinding.setError, _godot_object, error);
112 	}
113 	/**
114 	
115 	*/
116 	void setErrorLine(in long error_line)
117 	{
118 		checkClassBinding!(typeof(this))();
119 		ptrcall!(void)(GDNativeClassBinding.setErrorLine, _godot_object, error_line);
120 	}
121 	/**
122 	
123 	*/
124 	void setErrorString(in String error_string)
125 	{
126 		checkClassBinding!(typeof(this))();
127 		ptrcall!(void)(GDNativeClassBinding.setErrorString, _godot_object, error_string);
128 	}
129 	/**
130 	
131 	*/
132 	void setResult(VariantArg0)(in VariantArg0 result)
133 	{
134 		checkClassBinding!(typeof(this))();
135 		ptrcall!(void)(GDNativeClassBinding.setResult, _godot_object, result);
136 	}
137 	/**
138 	The error type if the JSON source was not successfully parsed. See the $(D error) constants.
139 	*/
140 	@property GodotError error()
141 	{
142 		return getError();
143 	}
144 	/// ditto
145 	@property void error(long v)
146 	{
147 		setError(v);
148 	}
149 	/**
150 	The line number where the error occurred if the JSON source was not successfully parsed.
151 	*/
152 	@property long errorLine()
153 	{
154 		return getErrorLine();
155 	}
156 	/// ditto
157 	@property void errorLine(long v)
158 	{
159 		setErrorLine(v);
160 	}
161 	/**
162 	The error message if the JSON source was not successfully parsed. See the $(D error) constants.
163 	*/
164 	@property String errorString()
165 	{
166 		return getErrorString();
167 	}
168 	/// ditto
169 	@property void errorString(String v)
170 	{
171 		setErrorString(v);
172 	}
173 	/**
174 	A $(D Variant) containing the parsed JSON. Use $(D @GDScript.typeof) or the `is` keyword to check if it is what you expect. For example, if the JSON source starts with curly braces (`{}`), a $(D Dictionary) will be returned. If the JSON source starts with brackets (`$(D ]`), an [Array) will be returned.
175 	$(B Note:) The JSON specification does not define integer or float types, but only a $(I number) type. Therefore, parsing a JSON text will convert all numerical values to $(D double) types.
176 	$(B Note:) JSON objects do not preserve key order like Godot dictionaries, thus, you should not rely on keys being in a certain order if a dictionary is constructed from JSON. In contrast, JSON arrays retain the order of their elements:
177 	
178 	
179 	var p = JSON.parse('$(D "hello", "world", "!")')
180 	if typeof(p.result) == TYPE_ARRAY:
181 	    print(p.result$(D 0)) # Prints "hello"
182 	else:
183 	    push_error("Unexpected results.")
184 	
185 	
186 	*/
187 	@property Variant result()
188 	{
189 		return getResult();
190 	}
191 	/// ditto
192 	@property void result(Variant v)
193 	{
194 		setResult(v);
195 	}
196 }