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