1 /**
2 Helper class for parsing JSON data.
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.json;
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.jsonparseresult;
23 /**
24 Helper class for parsing JSON data.
25 
26 For usage example and other important hints, see $(D JSONParseResult).
27 */
28 @GodotBaseClass struct JSONSingleton
29 {
30 	enum string _GODOT_internal_name = "_JSON";
31 public:
32 @nogc nothrow:
33 	union { godot_object _godot_object; GodotObject _GODOT_base; }
34 	alias _GODOT_base this;
35 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
36 	package(godot) __gshared bool _classBindingInitialized = false;
37 	package(godot) static struct _classBinding
38 	{
39 		__gshared:
40 		godot_object _singleton;
41 		immutable char* _singletonName = "JSON";
42 		@GodotName("print") GodotMethod!(String, Variant, String, bool) print;
43 		@GodotName("parse") GodotMethod!(JSONParseResult, String) parse;
44 	}
45 	bool opEquals(in JSONSingleton other) const { return _godot_object.ptr is other._godot_object.ptr; }
46 	JSONSingleton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
47 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
48 	mixin baseCasts;
49 	static JSONSingleton _new()
50 	{
51 		static godot_class_constructor constructor;
52 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("_JSON");
53 		if(constructor is null) return typeof(this).init;
54 		return cast(JSONSingleton)(constructor());
55 	}
56 	@disable new(size_t s);
57 	/**
58 	Converts a Variant var to JSON text and returns the result. Useful for serializing data to store or send over the network.
59 	*/
60 	String print(VariantArg0, StringArg1)(in VariantArg0 value, in StringArg1 indent = "", in bool sort_keys = false)
61 	{
62 		checkClassBinding!(typeof(this))();
63 		return ptrcall!(String)(_classBinding.print, _godot_object, value, indent, sort_keys);
64 	}
65 	/**
66 	Parses a JSON encoded string and returns a $(D JSONParseResult) containing the result.
67 	*/
68 	Ref!JSONParseResult parse(StringArg0)(in StringArg0 json)
69 	{
70 		checkClassBinding!(typeof(this))();
71 		return ptrcall!(JSONParseResult)(_classBinding.parse, _godot_object, json);
72 	}
73 }
74 /// Returns: the JSONSingleton
75 @property @nogc nothrow pragma(inline, true)
76 JSONSingleton JSON()
77 {
78 	checkClassBinding!JSONSingleton();
79 	return JSONSingleton(JSONSingleton._classBinding._singleton);
80 }