From ddd74c341d8944edf6c90081cabca789b0a48023 Mon Sep 17 00:00:00 2001 From: Artur Skawina Date: Sun, 29 Jan 2012 18:21:18 +0100 Subject: [PATCH] Json-glib support. --- gtk2/json.d | 2113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2113 insertions(+) create mode 100644 gtk2/json.d diff --git a/gtk2/json.d b/gtk2/json.d new file mode 100644 index 0000000..7ecb72b --- /dev/null +++ b/gtk2/json.d @@ -0,0 +1,2113 @@ +// *** DO NOT EDIT *** +// Automatically generated from "/usr/share/gir-1.0/Json-1.0.gir" + +module Json; +public import gtk2.glib2; +alias gtk2.glib2 GLib2; +public import gtk2.gobject2; +alias gtk2.gobject2 GObject2; +public import gtk2.gio2; +alias gtk2.gio2 Gio2; + +// package: "json-glib-1.0"; +// C header: "json-glib/json-glib.h"; + +// c:symbol-prefixes: ["json"] +// c:identifier-prefixes: ["Json"] + +// module Json; + + +// A JSON array type. The contents of the #JsonArray structure are private +// and should only be accessed by the provided API +struct Array { + + // Creates a new #JsonArray. + // RETURNS: the newly created #JsonArray + static Array* /*new*/ new_() { + return json_array_new(); + } + + // Creates a new #JsonArray with @n_elements slots already allocated. + // RETURNS: the newly created #JsonArray + // : number of slots to pre-allocate + static Array* /*new*/ sized_new(uint n_elements) { + return json_array_sized_new(n_elements); + } + + // Conveniently adds an array into @array. The @array takes ownership + // of the newly added #JsonArray + // + // See also: json_array_add_element(), json_node_take_array() + // : a #JsonArray + void add_array_element(Array* value) { + json_array_add_array_element(&this, value); + } + + // Conveniently adds a boolean @value into @array + // + // See also: json_array_add_element(), json_node_set_boolean() + // : a boolean value + void add_boolean_element(int value) { + json_array_add_boolean_element(&this, value); + } + + // Conveniently adds a floating point @value into @array + // + // See also: json_array_add_element(), json_node_set_double() + // : a floating point value + void add_double_element(double value) { + json_array_add_double_element(&this, value); + } + + // Appends @node inside @array. The array will take ownership of the + // #JsonNode. + // : a #JsonNode + void add_element(Node* node) { + json_array_add_element(&this, node); + } + + // Conveniently adds an integer @value into @array + // + // See also: json_array_add_element(), json_node_set_int() + // : an integer value + void add_int_element(long value) { + json_array_add_int_element(&this, value); + } + + // Conveniently adds a null element into @array + // + // See also: json_array_add_element(), %JSON_NODE_NULL + void add_null_element() { + json_array_add_null_element(&this); + } + + // Conveniently adds an object into @array. The @array takes ownership + // of the newly added #JsonObject + // + // See also: json_array_add_element(), json_node_take_object() + // : a #JsonObject + void add_object_element(Object* value) { + json_array_add_object_element(&this, value); + } + + // Conveniently adds a string @value into @array + // + // See also: json_array_add_element(), json_node_set_string() + // : a string value + void add_string_element(char* value) { + json_array_add_string_element(&this, value); + } + + // Retrieves a copy of the #JsonNode containing the value of the + // element at @index_ inside a #JsonArray + // + // index. Use json_node_free() when done. + // RETURNS: a copy of the #JsonNode at the requested + // : the index of the element to retrieve + Node* /*new*/ dup_element(uint index_) { + return json_array_dup_element(&this, index_); + } + + // Iterates over all elements of @array and calls @func on + // each one of them. + // + // It is safe to change the value of a #JsonNode of the @array + // from within the iterator @func, but it is not safe to add or + // remove elements from the @array. + // : the function to be called on each element + // : data to be passed to the function + void foreach_element(ArrayForeach func, void* data) { + json_array_foreach_element(&this, func, data); + } + + // Conveniently retrieves the array from the element at @index_ + // inside @array + // + // See also: json_array_get_element(), json_node_get_array() + // RETURNS: the array + // : the index of the element to retrieve + Array* get_array_element(uint index_) { + return json_array_get_array_element(&this, index_); + } + + // Conveniently retrieves the boolean value of the element at @index_ + // inside @array + // + // See also: json_array_get_element(), json_node_get_boolean() + // RETURNS: the integer value + // : the index of the element to retrieve + int get_boolean_element(uint index_) { + return json_array_get_boolean_element(&this, index_); + } + + // Conveniently retrieves the floating point value of the element at + // @index_ inside @array + // + // See also: json_array_get_element(), json_node_get_double() + // RETURNS: the floating point value + // : the index of the element to retrieve + double get_double_element(uint index_) { + return json_array_get_double_element(&this, index_); + } + + // Retrieves the #JsonNode containing the value of the element at @index_ + // inside a #JsonArray. + // RETURNS: a pointer to the #JsonNode at the requested index + // : the index of the element to retrieve + Node* get_element(uint index_) { + return json_array_get_element(&this, index_); + } + + // Gets the elements of a #JsonArray as a list of #JsonNodes. + // + // containing the elements of the array. The contents of the list are + // owned by the array and should never be modified or freed. Use + // g_list_free() on the returned list when done using it + // RETURNS: a #GList + GLib2.List* /*new container*/ get_elements() { + return json_array_get_elements(&this); + } + + // Conveniently retrieves the integer value of the element at @index_ + // inside @array + // + // See also: json_array_get_element(), json_node_get_int() + // RETURNS: the integer value + // : the index of the element to retrieve + long get_int_element(uint index_) { + return json_array_get_int_element(&this, index_); + } + + // Retrieves the length of a #JsonArray + // RETURNS: the length of the array + uint get_length() { + return json_array_get_length(&this); + } + + // Conveniently retrieves whether the element at @index_ is set to null + // + // See also: json_array_get_element(), JSON_NODE_TYPE(), %JSON_NODE_NULL + // RETURNS: %TRUE if the element is null + // : the index of the element to retrieve + int get_null_element(uint index_) { + return json_array_get_null_element(&this, index_); + } + + // Conveniently retrieves the object from the element at @index_ + // inside @array + // + // See also: json_array_get_element(), json_node_get_object() + // RETURNS: the object + // : the index of the element to retrieve + Object* get_object_element(uint index_) { + return json_array_get_object_element(&this, index_); + } + + // Conveniently retrieves the string value of the element at @index_ + // inside @array + // + // See also: json_array_get_element(), json_node_get_string() + // + // the #JsonArray and should not be modified or freed + // RETURNS: the string value; the returned string is owned by + // : the index of the element to retrieve + char* get_string_element(uint index_) { + return json_array_get_string_element(&this, index_); + } + + // Increase by one the reference count of a #JsonArray. + // + // increased by one. + // RETURNS: the passed #JsonArray, with the reference count + Array* /*new*/ ref_() { + return json_array_ref(&this); + } + + // Removes the #JsonNode inside @array at @index_ freeing its allocated + // resources. + // : the position of the element to be removed + void remove_element(uint index_) { + json_array_remove_element(&this, index_); + } + + // Decreases by one the reference count of a #JsonArray. If the + // reference count reaches zero, the array is destroyed and all + // its allocated resources are freed. + void unref() { + json_array_unref(&this); + } +} + + +// The function to be passed to json_array_foreach_element(). You +// should not add or remove elements to and from @array within +// this function. It is safe to change the value of @element_node. +// : the iterated #JsonArray +// : the index of the element +// : a #JsonNode containing the value at @index_ +// : data passed to the function +extern (C) alias void function (Array* array, uint index_, Node* element_node, void* user_data) ArrayForeach; + + +// Unintrospectable callback: BoxedDeserializeFunc() / () +// Deserializes the contents of the passed #JsonNode into a #GBoxed +// RETURNS: the newly created boxed type +// : a #JsonNode +extern (C) alias void* function (Node* node) BoxedDeserializeFunc; + + +// Serializes the passed #GBoxed and stores it inside a #JsonNode +// RETURNS: the newly created #JsonNode +// : a #GBoxed +extern (C) alias Node* /*new*/ function (const(void)* boxed) BoxedSerializeFunc; + + +// The JsonBuilder structure contains only +// private data and shouls be accessed using the provided API +struct Builder /* : GObject.Object */ /* Version 0.12 */ { + alias parent_instance this; + alias parent_instance super_; + alias parent_instance object; + GObject2.Object parent_instance; + private BuilderPrivate* priv; + + + // Creates a new #JsonBuilder. You can use this object to generate a + // JSON tree and obtain the root #JsonNodes. + // RETURNS: the newly created #JsonBuilder instance + static Builder* /*new*/ new_() { + return json_builder_new(); + } + + // If called after json_builder_set_member_name(), sets @value as member of the + // most recent opened object, otherwise @value is added as element of the most + // recent opened array. + // + // See also: json_builder_add_value() + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + // : the value of the member or element + Builder* add_boolean_value(int value) { + return json_builder_add_boolean_value(&this, value); + } + + // If called after json_builder_set_member_name(), sets @value as member of the + // most recent opened object, otherwise @value is added as element of the most + // recent opened array. + // + // See also: json_builder_add_value() + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + // : the value of the member or element + Builder* add_double_value(double value) { + return json_builder_add_double_value(&this, value); + } + + // If called after json_builder_set_member_name(), sets @value as member of the + // most recent opened object, otherwise @value is added as element of the most + // recent opened array. + // + // See also: json_builder_add_value() + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + // : the value of the member or element + Builder* add_int_value(long value) { + return json_builder_add_int_value(&this, value); + } + + // If called after json_builder_set_member_name(), sets null as member of the + // most recent opened object, otherwise null is added as element of the most + // recent opened array. + // + // See also: json_builder_add_value() + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + Builder* add_null_value() { + return json_builder_add_null_value(&this); + } + + // If called after json_builder_set_member_name(), sets @value as member of the + // most recent opened object, otherwise @value is added as element of the most + // recent opened array. + // + // See also: json_builder_add_value() + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + // : the value of the member or element + Builder* add_string_value(char* value) { + return json_builder_add_string_value(&this, value); + } + + // If called after json_builder_set_member_name(), sets @node as member of the + // most recent opened object, otherwise @node is added as element of the most + // recent opened array. + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + // : the value of the member or element + Builder* add_value(Node* node) { + return json_builder_add_value(&this, node); + } + + // Opens a subarray inside the given @builder. When done adding members to + // the subarray, json_builder_end_array() must be called. + // + // Can be called for first or only if the call is associated to an object member + // or an array element. + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + Builder* begin_array() { + return json_builder_begin_array(&this); + } + + // Opens a subobject inside the given @builder. When done adding members to + // the subobject, json_builder_end_object() must be called. + // + // Can be called for first or only if the call is associated to an object member + // or an array element. + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + Builder* begin_object() { + return json_builder_begin_object(&this); + } + + // Closes the subarray inside the given @builder that was opened by the most + // recent call to json_builder_begin_array(). + // + // Cannot be called after json_builder_set_member_name(). + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + Builder* end_array() { + return json_builder_end_array(&this); + } + + // Closes the subobject inside the given @builder that was opened by the most + // recent call to json_builder_begin_object(). + // + // Cannot be called after json_builder_set_member_name(). + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + Builder* end_object() { + return json_builder_end_object(&this); + } + + // Returns the root of the current constructed tree, if the build is complete + // (ie: all opened objects, object members and arrays are being closed). + // + // Free the returned value with json_node_free(). + // RETURNS: the #JsonNode, or %NULL if the build is not complete. + Node* /*new*/ get_root() { + return json_builder_get_root(&this); + } + // Resets the state of the @builder back to its initial state. + void reset() { + json_builder_reset(&this); + } + + // Set the name of the next member in an object. The next call must add a value, + // open an object or an array. + // + // Can be called only if the call is associated to an object. + // RETURNS: the #JsonBuilder, or %NULL if the call was inconsistent + // : the name of the member + Builder* set_member_name(char* member_name) { + return json_builder_set_member_name(&this, member_name); + } +} + + +// The JsonBuilder structure contains only +// private data +struct BuilderClass /* Version 0.12 */ { + private GObject2.ObjectClass parent_class; + extern (C) void function () _json_reserved1; + extern (C) void function () _json_reserved2; +} + +struct BuilderPrivate { +} + + +// JSON data streams generator. The contents of the #JsonGenerator structure +// are private and should only be accessed via the provided API. +struct Generator /* : GObject.Object */ { + alias parent_instance this; + alias parent_instance super_; + alias parent_instance object; + GObject2.Object parent_instance; + private GeneratorPrivate* priv; + + + // Creates a new #JsonGenerator. You can use this object to generate a + // JSON data stream starting from a data object model composed by + // #JsonNodes. + // RETURNS: the newly created #JsonGenerator instance + static Generator* /*new*/ new_() { + return json_generator_new(); + } + + // Retrieves the value set using json_generator_set_indent(). + // RETURNS: the number of repetitions per indentation level + uint get_indent() { + return json_generator_get_indent(&this); + } + + // Retrieves the value set using json_generator_set_indent_char(). + // RETURNS: the character to be used when indenting + dchar get_indent_char() { + return json_generator_get_indent_char(&this); + } + + // Retrieves the value set using json_generator_set_pretty(). + // + // %FALSE otherwise + // RETURNS: %TRUE if the generated JSON should be pretty-printed, and + int get_pretty() { + return json_generator_get_pretty(&this); + } + + // Retrieves a pointer to the root #JsonNode set using + // json_generator_set_root(). + // + // is owned by the #JsonGenerator and it should not be freed + // RETURNS: a #JsonNode, or %NULL. The returned node + Node* get_root() { + return json_generator_get_root(&this); + } + + // Sets the number of repetitions for each indentation level. + // : the number of repetitions of the indentation character that should be applied when pretty printing + void set_indent(uint indent_level) { + json_generator_set_indent(&this, indent_level); + } + + // Sets the character to be used when indenting + // : a Unicode character to be used when indenting + void set_indent_char(dchar indent_char) { + json_generator_set_indent_char(&this, indent_char); + } + + // Sets whether the generated JSON should be pretty printed, using the + // indentation character specified in the #JsonGenerator:indent-char + // property and the spacing specified in #JsonGenerator:indent property. + // : whether the generated string should be pretty printed + void set_pretty(int is_pretty) { + json_generator_set_pretty(&this, is_pretty); + } + + // Sets @node as the root of the JSON data stream to be serialized by + // the #JsonGenerator. + // + // The node is copied by the generator object, so it can be safely + // freed after calling this function. + // : a #JsonNode + void set_root(Node* node) { + json_generator_set_root(&this, node); + } + + // Generates a JSON data stream from @generator and returns it as a + // buffer. + // + // Use g_free() to free the allocated resources. + // RETURNS: a newly allocated buffer holding a JSON data stream. + // : return location for the length of the returned buffer, or %NULL + char* /*new*/ to_data(/*out*/ size_t* length) { + return json_generator_to_data(&this, length); + } + + // Creates a JSON data stream and puts it inside @filename, overwriting the + // current file contents. This operation is atomic. + // RETURNS: %TRUE if saving was successful. + // : path to the target file + int to_file(char* filename, GLib2.Error** error=null) { + return json_generator_to_file(&this, filename, error); + } + + // Outputs JSON data and streams it (synchronously) to @stream. + // + // on failure. In case of error, the #GError will be filled accordingly + // RETURNS: %TRUE if the write operation was successful, and %FALSE + // : a #GOutputStream + // : a #GCancellable, or %NULL + int to_stream(Gio2.OutputStream* stream, Gio2.Cancellable* cancellable, GLib2.Error** error=null) { + return json_generator_to_stream(&this, stream, cancellable, error); + } +} + +// #JsonGenerator class +struct GeneratorClass { + private GObject2.ObjectClass parent_class; + extern (C) void function () _json_reserved1; + extern (C) void function () _json_reserved2; + extern (C) void function () _json_reserved3; + extern (C) void function () _json_reserved4; +} + +struct GeneratorPrivate { +} + + +// A generic container of JSON data types. The contents of the #JsonNode +// structure are private and should only be accessed via the provided +// functions and never directly. +struct Node { + + // Creates a new #JsonNode of @type. + // RETURNS: the newly created #JsonNode + // : a #JsonNodeType + static Node* /*new*/ new_(NodeType type) { + return json_node_new(type); + } + + // Copies @node. If the node contains complex data types then the reference + // count of the objects is increased. + // RETURNS: the copied #JsonNode + Node* /*new*/ copy() { + return json_node_copy(&this); + } + + // Retrieves the #JsonArray stored inside a #JsonNode and returns it + // with its reference count increased by one. + // + // count increased. + // RETURNS: the #JsonArray with its reference + Array* /*new*/ dup_array() { + return json_node_dup_array(&this); + } + + // Retrieves the #JsonObject inside @node. The reference count of + // the returned object is increased. + // RETURNS: the #JsonObject + Object* /*new*/ dup_object() { + return json_node_dup_object(&this); + } + + // Gets a copy of the string value stored inside a #JsonNode + // + // of the #JsonNode contents. Use g_free() to free the allocated resources + // RETURNS: a newly allocated string containing a copy + char* /*new*/ dup_string() { + return json_node_dup_string(&this); + } + // Frees the resources allocated by @node. + void free() { + json_node_free(&this); + } + + // Retrieves the #JsonArray stored inside a #JsonNode + // RETURNS: the #JsonArray + Array* get_array() { + return json_node_get_array(&this); + } + + // Gets the boolean value stored inside a #JsonNode + // RETURNS: a boolean value. + int get_boolean() { + return json_node_get_boolean(&this); + } + + // Gets the double value stored inside a #JsonNode + // RETURNS: a double value. + double get_double() { + return json_node_get_double(&this); + } + + // Gets the integer value stored inside a #JsonNode + // RETURNS: an integer value. + long get_int() { + return json_node_get_int(&this); + } + + // Retrieves the #JsonNodeType of @node + // RETURNS: the type of the node + NodeType get_node_type() { + return json_node_get_node_type(&this); + } + + // Retrieves the #JsonObject stored inside a #JsonNode + // RETURNS: the #JsonObject + Object* get_object() { + return json_node_get_object(&this); + } + + // Retrieves the parent #JsonNode of @node. + // + // the root node + // RETURNS: the parent node, or %NULL if @node is + Node* get_parent() { + return json_node_get_parent(&this); + } + + // Gets the string value stored inside a #JsonNode + // RETURNS: a string value. + char* get_string() { + return json_node_get_string(&this); + } + + // Retrieves a value from a #JsonNode and copies into @value. When done + // using it, call g_value_unset() on the #GValue. + // : return location for an uninitialized value + void get_value(/*out*/ GObject2.Value* value) { + json_node_get_value(&this, value); + } + + // Returns the #GType of the payload of the node. + // RETURNS: a #GType for the payload. + Type get_value_type() { + return json_node_get_value_type(&this); + } + + // Checks whether @node is a %JSON_NODE_NULL + // + // A null node is not the same as a %NULL #JsonNode + // RETURNS: %TRUE if the node is null + int is_null() { + return json_node_is_null(&this); + } + + // Sets @array inside @node and increases the #JsonArray reference count + // : a #JsonArray + void set_array(Array* array) { + json_node_set_array(&this, array); + } + + // Sets @value as the boolean content of the @node, replacing any existing + // content. + // : a boolean value + void set_boolean(int value) { + json_node_set_boolean(&this, value); + } + + // Sets @value as the double content of the @node, replacing any existing + // content. + // : a double value + void set_double(double value) { + json_node_set_double(&this, value); + } + + // Sets @value as the integer content of the @node, replacing any existing + // content. + // : an integer value + void set_int(long value) { + json_node_set_int(&this, value); + } + + // Sets @objects inside @node. The reference count of @object is increased. + // : a #JsonObject + void set_object(Object* object) { + json_node_set_object(&this, object); + } + + // Sets the parent #JsonNode of @node + // : the parent #JsonNode of @node + void set_parent(Node* parent) { + json_node_set_parent(&this, parent); + } + + // Sets @value as the string content of the @node, replacing any existing + // content. + // : a string value + void set_string(char* value) { + json_node_set_string(&this, value); + } + + // Sets @value inside @node. The passed #GValue is copied into the #JsonNode + // : the #GValue to set + void set_value(GObject2.Value* value) { + json_node_set_value(&this, value); + } + + // Sets @array into @node without increasing the #JsonArray reference count. + // : a #JsonArray + void take_array(Array* array) { + json_node_take_array(&this, array); + } + + // Sets @object inside @node. The reference count of @object is not increased. + // : a #JsonObject + void take_object(Object* object) { + json_node_take_object(&this, object); + } + + // Retrieves the user readable name of the data type contained by @node. + // + // is owned by the node and should never be modified or freed + // RETURNS: a string containing the name of the type. The returned string + char* type_name() { + return json_node_type_name(&this); + } +} + +// Indicates the content of a #JsonNode. +enum NodeType { + OBJECT = 0, + ARRAY = 1, + VALUE = 2, + NULL = 3 +} + +// A JSON object type. The contents of the #JsonObject structure are private +// and should only be accessed by the provided API +struct Object { + + // Creates a new #JsonObject, an JSON object type representation. + // RETURNS: the newly created #JsonObject + static Object* /*new*/ new_() { + return json_object_new(); + } + + // Adds a member named @member_name and containing @node into a #JsonObject. + // The object will take ownership of the #JsonNode. + // + // This function will return if the @object already contains a member + // @member_name. + // : the name of the member + // : the value of the member + void add_member(char* member_name, Node* node) { + json_object_add_member(&this, member_name, node); + } + + // Retrieves a copy of the #JsonNode containing the value of @member_name + // inside a #JsonObject + // + // object member or %NULL. Use json_node_free() when done. + // RETURNS: a copy of the node for the requested + // : the name of the JSON object member to access + Node* /*new*/ dup_member(char* member_name) { + return json_object_dup_member(&this, member_name); + } + + // Iterates over all members of @object and calls @func on + // each one of them. + // + // It is safe to change the value of a #JsonNode of the @object + // from within the iterator @func, but it is not safe to add or + // remove members from the @object. + // : the function to be called on each member + // : data to be passed to the function + void foreach_member(ObjectForeach func, void* data) { + json_object_foreach_member(&this, func, data); + } + + // Convenience function that retrieves the array + // stored in @member_name of @object + // + // See also: json_object_get_member() + // RETURNS: the array inside the object's member + // : the name of the member + Array* get_array_member(char* member_name) { + return json_object_get_array_member(&this, member_name); + } + + // Convenience function that retrieves the boolean value + // stored in @member_name of @object + // + // See also: json_object_get_member() + // RETURNS: the boolean value of the object's member + // : the name of the member + int get_boolean_member(char* member_name) { + return json_object_get_boolean_member(&this, member_name); + } + + // Convenience function that retrieves the floating point value + // stored in @member_name of @object + // + // See also: json_object_get_member() + // RETURNS: the floating point value of the object's member + // : the name of the member + double get_double_member(char* member_name) { + return json_object_get_double_member(&this, member_name); + } + + // Convenience function that retrieves the integer value + // stored in @member_name of @object + // + // See also: json_object_get_member() + // RETURNS: the integer value of the object's member + // : the name of the member + long get_int_member(char* member_name) { + return json_object_get_int_member(&this, member_name); + } + + // Retrieves the #JsonNode containing the value of @member_name inside + // a #JsonObject. + // + // member, or %NULL + // RETURNS: a pointer to the node for the requested object + // : the name of the JSON object member to access + Node* get_member(char* member_name) { + return json_object_get_member(&this, member_name); + } + + // Retrieves all the names of the members of a #JsonObject. You can + // obtain the value for each member using json_object_get_member(). + // + // of member names. The content of the list is owned by the #JsonObject + // and should never be modified or freed. When you have finished using + // the returned list, use g_list_free() to free the resources it has + // allocated. + // RETURNS: a #GList + GLib2.List* /*new container*/ get_members() { + return json_object_get_members(&this); + } + + // Convenience function that checks whether the value + // stored in @member_name of @object is null + // + // See also: json_object_get_member() + // RETURNS: %TRUE if the value is null + // : the name of the member + int get_null_member(char* member_name) { + return json_object_get_null_member(&this, member_name); + } + + // Convenience function that retrieves the object + // stored in @member_name of @object + // + // See also: json_object_get_member() + // RETURNS: the object inside the object's member + // : the name of the member + Object* get_object_member(char* member_name) { + return json_object_get_object_member(&this, member_name); + } + + // Retrieves the number of members of a #JsonObject. + // RETURNS: the number of members + uint get_size() { + return json_object_get_size(&this); + } + + // Convenience function that retrieves the string value + // stored in @member_name of @object + // + // See also: json_object_get_member() + // RETURNS: the string value of the object's member + // : the name of the member + char* get_string_member(char* member_name) { + return json_object_get_string_member(&this, member_name); + } + + // Retrieves all the values of the members of a #JsonObject. + // + // #JsonNodes. The content of the list is owned by the #JsonObject + // and should never be modified or freed. When you have finished using the + // returned list, use g_list_free() to free the resources it has allocated. + // RETURNS: a #GList of + GLib2.List* /*new container*/ get_values() { + return json_object_get_values(&this); + } + + // Checks whether @object has a member named @member_name. + // RETURNS: %TRUE if the JSON object has the requested member + // : the name of a JSON object member + int has_member(char* member_name) { + return json_object_has_member(&this, member_name); + } + + // Increase by one the reference count of a #JsonObject. + // + // increased by one. + // RETURNS: the passed #JsonObject, with the reference count + Object* /*new*/ ref_() { + return json_object_ref(&this); + } + + // Removes @member_name from @object, freeing its allocated resources. + // : the name of the member to remove + void remove_member(char* member_name) { + json_object_remove_member(&this, member_name); + } + + // Convenience function for setting an array @value of + // @member_name inside @object. + // + // The @object will take ownership of the passed #JsonArray + // + // See also: json_object_set_member() + // : the name of the member + // : the value of the member + void set_array_member(char* member_name, Array* value) { + json_object_set_array_member(&this, member_name, value); + } + + // Convenience function for setting a boolean @value of + // @member_name inside @object. + // + // See also: json_object_set_member() + // : the name of the member + // : the value of the member + void set_boolean_member(char* member_name, int value) { + json_object_set_boolean_member(&this, member_name, value); + } + + // Convenience function for setting a floating point @value + // of @member_name inside @object. + // + // See also: json_object_set_member() + // : the name of the member + // : the value of the member + void set_double_member(char* member_name, double value) { + json_object_set_double_member(&this, member_name, value); + } + + // Convenience function for setting an integer @value of + // @member_name inside @object. + // + // See also: json_object_set_member() + // : the name of the member + // : the value of the member + void set_int_member(char* member_name, long value) { + json_object_set_int_member(&this, member_name, value); + } + + // Sets @node as the value of @member_name inside @object. + // + // If @object already contains a member called @member_name then + // the member's current value is overwritten. Otherwise, a new + // member is added to @object. + // : the name of the member + // : the value of the member + void set_member(char* member_name, Node* node) { + json_object_set_member(&this, member_name, node); + } + + // Convenience function for setting a null @value of + // @member_name inside @object. + // + // See also: json_object_set_member() + // : the name of the member + void set_null_member(char* member_name) { + json_object_set_null_member(&this, member_name); + } + + // Convenience function for setting an object @value of + // @member_name inside @object. + // + // The @object will take ownership of the passed #JsonObject + // + // See also: json_object_set_member() + // : the name of the member + // : the value of the member + void set_object_member(char* member_name, Object* value) { + json_object_set_object_member(&this, member_name, value); + } + + // Convenience function for setting a string @value of + // @member_name inside @object. + // + // See also: json_object_set_member() + // : the name of the member + // : the value of the member + void set_string_member(char* member_name, char* value) { + json_object_set_string_member(&this, member_name, value); + } + + // Decreases by one the reference count of a #JsonObject. If the + // reference count reaches zero, the object is destroyed and all + // its allocated resources are freed. + void unref() { + json_object_unref(&this); + } +} + + +// The function to be passed to json_object_foreach_member(). You +// should not add or remove members to and from @object within +// this function. It is safe to change the value of @member_node. +// : the iterated #JsonObject +// : the name of the member +// : a #JsonNode containing the @member_name value +// : data passed to the function +extern (C) alias void function (Object* object, char* member_name, Node* member_node, void* user_data) ObjectForeach; + + +// JSON data streams parser. The contents of the #JsonParser structure are +// private and should only be accessed via the provided API. +struct Parser /* : GObject.Object */ { + alias parent_instance this; + alias parent_instance super_; + alias parent_instance object; + GObject2.Object parent_instance; + private ParserPrivate* priv; + + + // Creates a new #JsonParser instance. You can use the #JsonParser to + // load a JSON stream from either a file or a buffer and then walk the + // hierarchy using the data types API. + // + // to release all the memory it allocates. + // RETURNS: the newly created #JsonParser. Use g_object_unref() + static Parser* /*new*/ new_() { + return json_parser_new(); + } + static GLib2.Quark error_quark() { + return json_parser_error_quark(); + } + + // Retrieves the line currently parsed, starting from 1. + // + // This function has defined behaviour only while parsing; calling this + // function from outside the signal handlers emitted by #JsonParser will + // yield 0. + // RETURNS: the currently parsed line, or 0. + uint get_current_line() { + return json_parser_get_current_line(&this); + } + + // Retrieves the current position inside the current line, starting + // from 0. + // + // This function has defined behaviour only while parsing; calling this + // function from outside the signal handlers emitted by #JsonParser will + // yield 0. + // RETURNS: the position in the current line, or 0. + uint get_current_pos() { + return json_parser_get_current_pos(&this); + } + + // Retrieves the top level node from the parsed JSON stream. + // + // node is owned by the #JsonParser and should never be modified + // or freed. + // RETURNS: the root #JsonNode . The returned + Node* get_root() { + return json_parser_get_root(&this); + } + + // A JSON data stream might sometimes contain an assignment, like: + // + // |[ + // var _json_data = { "member_name" : [ ... + // ]| + // + // even though it would technically constitute a violation of the RFC. + // + // #JsonParser will ignore the left hand identifier and parse the right + // hand value of the assignment. #JsonParser will record, though, the + // existence of the assignment in the data stream and the variable name + // used. + // + // @variable_name is not %NULL it will be set to the name of the variable + // used in the assignment. The string is owned by #JsonParser and should + // never be modified or freed. + // RETURNS: %TRUE if there was an assignment, %FALSE otherwise. If + // : Return location for the variable name, or %NULL + int has_assignment(/*out*/ char** variable_name=null) { + return json_parser_has_assignment(&this, variable_name); + } + + // Loads a JSON stream from a buffer and parses it. You can call this function + // multiple times with the same #JsonParser object, but the contents of the + // parser will be destroyed each time. + // + // of error, @error is set accordingly and %FALSE is returned + // RETURNS: %TRUE if the buffer was succesfully parser. In case + // : the buffer to parse + // : the length of the buffer, or -1 + int load_from_data(char* data, ssize_t length, GLib2.Error** error=null) { + return json_parser_load_from_data(&this, data, length, error); + } + + // Loads a JSON stream from the content of @filename and parses it. See + // json_parser_load_from_data(). + // + // In case of error, @error is set accordingly and %FALSE is returned + // RETURNS: %TRUE if the file was successfully loaded and parsed. + // : the path for the file to parse + int load_from_file(char* filename, GLib2.Error** error=null) { + return json_parser_load_from_file(&this, filename, error); + } + + // Loads the contents of an input stream and parses them. + // + // If @cancellable is not %NULL, then the operation can be cancelled by + // triggering the @cancellable object from another thread. If the + // operation was cancelled, the error %G_IO_ERROR_CANCELLED will be set + // on the passed @error. + // + // parsed, and %FALSE otherwise + // RETURNS: %TRUE if the data stream was successfully read and + // : an open #GInputStream + // : a #GCancellable, or %NULL + int load_from_stream(Gio2.InputStream* stream, Gio2.Cancellable* cancellable, GLib2.Error** error=null) { + return json_parser_load_from_stream(&this, stream, cancellable, error); + } + + // Asynchronously reads the contents of @stream. + // + // For more details, see json_parser_load_from_stream() which is the + // synchronous version of this call. + // + // When the operation is finished, @callback will be called. You should + // then call json_parser_load_from_stream_finish() to get the result + // of the operation. + // : a #GInputStream + // : a #GCancellable, or %NULL + // : a #GAsyncReadyCallback to call when the request is satisfied + // : the data to pass to @callback + void load_from_stream_async(Gio2.InputStream* stream, Gio2.Cancellable* cancellable, Gio2.AsyncReadyCallback callback, void* user_data) { + json_parser_load_from_stream_async(&this, stream, cancellable, callback, user_data); + } + + // Finishes an asynchronous stream loading started with + // json_parser_load_from_stream_async(). + // + // and parsed, and %FALSE otherwise. In case of error, the #GError will be + // filled accordingly. + // RETURNS: %TRUE if the content of the stream was successfully retrieves + // : a #GAsyncResult + int load_from_stream_finish(Gio2.AsyncResult* result, GLib2.Error** error=null) { + return json_parser_load_from_stream_finish(&this, result, error); + } + + // The ::array-element signal is emitted each time the #JsonParser + // has successfully parsed a single element of a #JsonArray. The + // array and element index are passed to the signal handlers. + // : a #JsonArray + // : the index of the newly parsed element + extern (C) alias static void function (Parser* this_, Array* array, int index_, void* user_data=null) signal_array_element; + + ulong signal_connect(string name, CB)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return super_.signal_connect!name(cb, data, cf); + } + + ulong signal_connect(string name:"array-element", CB:signal_array_element)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"array-element", + cast(GObject2.Callback)cb, data, null, cf); + } + + // The ::array-end signal is emitted each time the #JsonParser + // has successfully parsed an entire #JsonArray + // : the parsed #JsonArray + extern (C) alias static void function (Parser* this_, Array* array, void* user_data=null) signal_array_end; + ulong signal_connect(string name:"array-end", CB:signal_array_end)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"array-end", + cast(GObject2.Callback)cb, data, null, cf); + } + + // The ::array-start signal is emitted each time the #JsonParser + // starts parsing a #JsonArray + extern (C) alias static void function (Parser* this_, void* user_data=null) signal_array_start; + ulong signal_connect(string name:"array-start", CB:signal_array_start)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"array-start", + cast(GObject2.Callback)cb, data, null, cf); + } + + // The ::error signal is emitted each time a #JsonParser encounters + // an error in a JSON stream. + // : a pointer to the #GError + extern (C) alias static void function (Parser* this_, void* error, void* user_data=null) signal_error; + ulong signal_connect(string name:"error", CB:signal_error)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"error", + cast(GObject2.Callback)cb, data, null, cf); + } + + // The ::object-end signal is emitted each time the #JsonParser + // has successfully parsed an entire #JsonObject. + // : the parsed #JsonObject + extern (C) alias static void function (Parser* this_, Object* object, void* user_data=null) signal_object_end; + ulong signal_connect(string name:"object-end", CB:signal_object_end)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"object-end", + cast(GObject2.Callback)cb, data, null, cf); + } + + // The ::object-member signal is emitted each time the #JsonParser + // has successfully parsed a single member of a #JsonObject. The + // object and member are passed to the signal handlers. + // : a #JsonObject + // : the name of the newly parsed member + extern (C) alias static void function (Parser* this_, Object* object, char* member_name, void* user_data=null) signal_object_member; + ulong signal_connect(string name:"object-member", CB:signal_object_member)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"object-member", + cast(GObject2.Callback)cb, data, null, cf); + } + + // The ::object-start signal is emitted each time the #JsonParser + // starts parsing a #JsonObject. + extern (C) alias static void function (Parser* this_, void* user_data=null) signal_object_start; + ulong signal_connect(string name:"object-start", CB:signal_object_start)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"object-start", + cast(GObject2.Callback)cb, data, null, cf); + } + + // The ::parse-end signal is emitted when the parser successfully + // finished parsing a JSON data stream + extern (C) alias static void function (Parser* this_, void* user_data=null) signal_parse_end; + ulong signal_connect(string name:"parse-end", CB:signal_parse_end)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"parse-end", + cast(GObject2.Callback)cb, data, null, cf); + } + + // The ::parse-start signal is emitted when the parser began parsing + // a JSON data stream. + extern (C) alias static void function (Parser* this_, void* user_data=null) signal_parse_start; + ulong signal_connect(string name:"parse-start", CB:signal_parse_start)(CB cb, void* data=null, ConnectFlags cf=cast(ConnectFlags)0) { + return signal_connect_data(&this, cast(char*)"parse-start", + cast(GObject2.Callback)cb, data, null, cf); + } +} + +// #JsonParser class. +struct ParserClass { + private GObject2.ObjectClass parent_class; + extern (C) void function (Parser* parser) parse_start; + extern (C) void function (Parser* parser) object_start; + extern (C) void function (Parser* parser, Object* object, char* member_name) object_member; + extern (C) void function (Parser* parser, Object* object) object_end; + extern (C) void function (Parser* parser) array_start; + extern (C) void function (Parser* parser, Array* array, int index_) array_element; + extern (C) void function (Parser* parser, Array* array) array_end; + extern (C) void function (Parser* parser) parse_end; + extern (C) void function (Parser* parser, GLib2.Error* error) error; + extern (C) void function () _json_reserved1; + extern (C) void function () _json_reserved2; + extern (C) void function () _json_reserved3; + extern (C) void function () _json_reserved4; + extern (C) void function () _json_reserved5; + extern (C) void function () _json_reserved6; + extern (C) void function () _json_reserved7; + extern (C) void function () _json_reserved8; +} + + +// Error enumeration for #JsonParser +// +// This enumeration can be extended at later date +enum ParserError { + PARSE = 0, + TRAILING_COMMA = 1, + MISSING_COMMA = 2, + MISSING_COLON = 3, + INVALID_BAREWORD = 4, + UNKNOWN = 5 +} +struct ParserPrivate { +} + + +// The JsonPath structure is an opaque object +// whose members cannot be directly accessed except through the provided +// API. +struct Path /* : GObject.Object */ /* Version 0.14 */ { + alias method_parent this; + alias method_parent super_; + alias method_parent object; + GObject2.Object method_parent; + + + // Creates a new #JsonPath instance. + // + // Once created, the #JsonPath object should be used with json_path_compile() + // and json_path_match(). + // + // g_object_unref() to free the allocated resources when done + // RETURNS: the newly created #JsonPath instance. Use + static Path* /*new*/ new_() { + return json_path_new(); + } + static GLib2.Quark error_quark() { + return json_path_error_quark(); + } + + // Queries a JSON tree using a JSONPath expression. + // + // This function is a simple wrapper around json_path_new(), + // json_path_compile() and json_path_match(). It implicitly + // creates a #JsonPath instance, compiles @expression and + // matches it against the JSON tree pointed by @root. + // + // %JSON_NODE_ARRAY containing an array of matching #JsonNodes. + // Use json_node_free() when done + // RETURNS: a newly-created #JsonNode of type + // : a JSONPath expression + // : the root of a JSON tree + static Node* /*new*/ query(char* expression, Node* root, GLib2.Error** error=null) { + return json_path_query(expression, root, error); + } + + // Validates and decomposes @expression. + // + // A JSONPath expression must be compiled before calling json_path_match(). + // + // the %JSON_PATH_ERROR domain and a code from the #JsonPathError + // enumeration, and %FALSE will be returned + // RETURNS: %TRUE on success; on error, @error will be set with + // : a JSONPath expression + int compile(char* expression, GLib2.Error** error=null) { + return json_path_compile(&this, expression, error); + } + + // Matches the JSON tree pointed by @root using the expression compiled + // into the #JsonPath. + // + // The matching #JsonNodes will be copied into a #JsonArray and + // returned wrapped in a #JsonNode. + // + // %JSON_NODE_ARRAY containing an array of matching #JsonNodes. + // Use json_node_free() when done + // RETURNS: a newly-created #JsonNode of type + // : a #JsonNode + Node* /*new*/ match(Node* root) { + return json_path_match(&this, root); + } +} + + +// The JsonPathClass structure is an opaque +// object class whose members cannot be directly accessed. +struct PathClass /* Version 0.14 */ { +} + +// Error code enumeration for the %JSON_PATH_ERROR domain. +enum PathError /* Version 0.14 */ { + PATH_ERROR_INVALID_QUERY = 0 +} + +// The JsonReader structure contains only +// private data and should only be accessed using the provided API +struct Reader /* : GObject.Object */ /* Version 0.12 */ { + alias parent_instance this; + alias parent_instance super_; + alias parent_instance object; + GObject2.Object parent_instance; + private ReaderPrivate* priv; + + + // Creates a new #JsonReader. You can use this object to read the contents of + // the JSON tree starting from @node + // + // release the allocated resources when done + // RETURNS: the newly created #JsonReader. Use g_object_unref() to + // : a #JsonNode, or %NULL + static Reader* /*new*/ new_(Node* node=null) { + return json_reader_new(node); + } + static GLib2.Quark error_quark() { + return json_reader_error_quark(); + } + + // Counts the elements of the current position, if @reader is + // positioned on an array + // + // the #JsonReader is set in an error state + // RETURNS: the number of elements, or -1. In case of failure + int count_elements() { + return json_reader_count_elements(&this); + } + + // Counts the members of the current position, if @reader is + // positioned on an object + // + // the #JsonReader is set in an error state + // RETURNS: the number of members, or -1. In case of failure + int count_members() { + return json_reader_count_members(&this); + } + + // Moves the cursor back to the previous node after being positioned + // inside an array + // + // This function resets the error state of @reader, if any was set + void end_element() { + json_reader_end_element(&this); + } + + // Moves the cursor back to the previous node after being positioned + // inside an object + // + // This function resets the error state of @reader, if any was set + void end_member() { + json_reader_end_member(&this); + } + + // Retrieves the boolean value of the current position of @reader + // RETURNS: the boolean value + int get_boolean_value() { + return json_reader_get_boolean_value(&this); + } + + // Retrieves the floating point value of the current position of @reader + // RETURNS: the floating point value + double get_double_value() { + return json_reader_get_double_value(&this); + } + + // Retrieves the #GError currently set on @reader, if the #JsonReader + // is in error state + // RETURNS: the pointer to the error, or %NULL + GLib2.Error* get_error() { + return json_reader_get_error(&this); + } + + // Retrieves the integer value of the current position of @reader + // RETURNS: the integer value + long get_int_value() { + return json_reader_get_int_value(&this); + } + + // Retrieves the name of the current member. + // RETURNS: the name of the member, or %NULL + char* get_member_name() { + return json_reader_get_member_name(&this); + } + + // Checks whether the value of the current position of @reader is 'null' + // RETURNS: %TRUE if 'null' is set, and %FALSE otherwise + int get_null_value() { + return json_reader_get_null_value(&this); + } + + // Retrieves the string value of the current position of @reader + // RETURNS: the string value + char* get_string_value() { + return json_reader_get_string_value(&this); + } + + // Retrieves the #JsonNode of the current position of @reader + // + // is owned by the #JsonReader and it should not be modified or freed + // directly + // RETURNS: a #JsonNode, or %NULL. The returned node + Node* get_value() { + return json_reader_get_value(&this); + } + + // Checks whether the @reader is currently on an array + // + // otherwise + // RETURNS: %TRUE if the #JsonReader is on an array, and %FALSE + int is_array() { + return json_reader_is_array(&this); + } + + // Checks whether the @reader is currently on an object + // + // otherwise + // RETURNS: %TRUE if the #JsonReader is on an object, and %FALSE + int is_object() { + return json_reader_is_object(&this); + } + + // Checks whether the @reader is currently on a value + // + // otherwise + // RETURNS: %TRUE if the #JsonReader is on a value, and %FALSE + int is_value() { + return json_reader_is_value(&this); + } + + // Retrieves a list of member names from the current position, if @reader + // is positioned on an object. + // + // array of strings holding the members name. Use g_strfreev() when + // done. + // RETURNS: a newly allocated, %NULL-terminated + char** /*new*/ list_members() { + return json_reader_list_members(&this); + } + + // Advances the cursor of @reader to the element @index_ of the array + // or the object at the current position. + // + // You can use the json_reader_get_value* family of functions to retrieve + // the value of the element; for instance: + // + // |[ + // json_reader_read_element (reader, 0); + // int_value = json_reader_get_int_value (reader); + // ]| + // + // After reading the value, json_reader_end_element() should be called to + // reposition the cursor inside the #JsonReader, e.g.: + // + // |[ + // json_reader_read_element (reader, 1); + // str_value = json_reader_get_string_value (reader); + // json_reader_end_element (reader); + // + // json_reader_read_element (reader, 2); + // str_value = json_reader_get_string_value (reader); + // json_reader_end_element (reader); + // ]| + // + // If @reader is not currently on an array or an object, or if the @index_ is + // bigger than the size of the array or the object, the #JsonReader will be + // put in an error state until json_reader_end_element() is called. + // RETURNS: %TRUE on success, and %FALSE otherwise + // : the index of the element + int read_element(uint index_) { + return json_reader_read_element(&this, index_); + } + + // Advances the cursor of @reader to the @member_name of the object at the + // current position. + // + // You can use the json_reader_get_value* family of functions to retrieve + // the value of the member; for instance: + // + // |[ + // json_reader_read_member (reader, "width"); + // width = json_reader_get_int_value (reader); + // ]| + // + // After reading the value, json_reader_end_member() should be called to + // reposition the cursor inside the #JsonReader, e.g.: + // + // |[ + // json_reader_read_member (reader, "author"); + // author = json_reader_get_string_value (reader); + // json_reader_end_element (reader); + // + // json_reader_read_element (reader, "title"); + // title = json_reader_get_string_value (reader); + // json_reader_end_element (reader); + // ]| + // + // If @reader is not currently on an object, or if the @member_name is not + // defined in the object, the #JsonReader will be put in an error state until + // json_reader_end_member() is called. + // RETURNS: %TRUE on success, and %FALSE otherwise + // : the name of the member to read + int read_member(char* member_name) { + return json_reader_read_member(&this, member_name); + } + + // Sets the root #JsonNode to be read by @reader. The @reader will take + // a copy of @root + // + // If another #JsonNode is currently set as root, it will be replaced. + // : a #JsonNode + void set_root(Node* root=null) { + json_reader_set_root(&this, root); + } +} + + +// The JsonReaderClass structure contains only +// private data +struct ReaderClass /* Version 0.12 */ { + private GObject2.ObjectClass parent_class; + extern (C) void function () _json_padding0; + extern (C) void function () _json_padding1; + extern (C) void function () _json_padding2; + extern (C) void function () _json_padding3; + extern (C) void function () _json_padding4; +} + +// Error codes enumeration for #JsonReader errors +enum ReaderError /* Version 0.12 */ { + NO_ARRAY = 0, + INVALID_INDEX = 1, + NO_OBJECT = 2, + INVALID_MEMBER = 3, + INVALID_NODE = 4, + NO_VALUE = 5, + INVALID_TYPE = 6 +} +struct ReaderPrivate { +} + +struct Serializable { + + // Calls the default implementation of the #JsonSerializable + // deserialize_property() virtual function + // + // This function can be used inside a custom implementation + // of the deserialize_property() virtual function in lieu of: + // + // |[ + // JsonSerializable *iface; + // gboolean res; + // + // iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE); + // res = iface->deserialize_property (serializable, property_name, + // value, + // pspec, + // property_node); + // ]| + // RETURNS: %TRUE if the property was successfully deserialized. + // : the name of the property + // : a pointer to an uninitialized #GValue + // : a #GParamSpec + // : a #JsonNode containing the serialized property + int default_deserialize_property(char* property_name, GObject2.Value* value, GObject2.ParamSpec* pspec, Node* property_node) { + return json_serializable_default_deserialize_property(&this, property_name, value, pspec, property_node); + } + + // Calls the default implementation of the #JsonSerializable + // serialize_property() virtual function + // + // This function can be used inside a custom implementation + // of the serialize_property() virtual function in lieu of: + // + // |[ + // JsonSerializable *iface; + // JsonNode *node; + // + // iface = g_type_default_interface_peek (JSON_TYPE_SERIALIZABLE); + // node = iface->serialize_property (serializable, property_name, + // value, + // pspec); + // ]| + // + // property + // RETURNS: a #JsonNode containing the serialized + // : the name of the property + // : the value of the property + // : a #GParamSpec + Node* /*new*/ default_serialize_property(char* property_name, GObject2.Value* value, GObject2.ParamSpec* pspec) { + return json_serializable_default_serialize_property(&this, property_name, value, pspec); + } + + // Asks a #JsonSerializable implementation to deserialize the + // property contained inside @property_node into @value. + // RETURNS: %TRUE if the property was successfully deserialized. + // : the name of the property + // : a pointer to an uninitialized #GValue + // : a #GParamSpec + // : a #JsonNode containing the serialized property + int deserialize_property(char* property_name, /*out*/ GObject2.Value* value, GObject2.ParamSpec* pspec, Node* property_node) { + return json_serializable_deserialize_property(&this, property_name, value, pspec, property_node); + } + + // FIXME + // + // or %NULL if no property was found + // RETURNS: the #GParamSpec for the property + // : the name of the property + GObject2.ParamSpec* find_property(char* name) { + return json_serializable_find_property(&this, name); + } + void get_property(GObject2.ParamSpec* pspec, GObject2.Value* value) { + json_serializable_get_property(&this, pspec, value); + } + + // FIXME + // + // of #GParamSpec. Use g_free() to free the array when done. + // RETURNS: an array + // : return location for the length of the array of #GParamSpec returned by the function + GObject2.ParamSpec** /*new container*/ list_properties(/*out*/ uint* n_pspecs) { + return json_serializable_list_properties(&this, n_pspecs); + } + + // Asks a #JsonSerializable implementation to serialize a #GObject + // property into a #JsonNode object. + // RETURNS: a #JsonNode containing the serialized property + // : the name of the property + // : the value of the property + // : a #GParamSpec + Node* /*new*/ serialize_property(char* property_name, GObject2.Value* value, GObject2.ParamSpec* pspec) { + return json_serializable_serialize_property(&this, property_name, value, pspec); + } + void set_property(GObject2.ParamSpec* pspec, GObject2.Value* value) { + json_serializable_set_property(&this, pspec, value); + } +} + + +// Interface that allows serializing and deserializing #GObjects +// with properties storing complex data types. The json_serialize_gobject() +// function will check if the passed #GObject implements this interface, +// so it can also be used to override the default property serialization +// sequence. +struct SerializableIface { + private GObject2.TypeInterface g_iface; + + // RETURNS: a #JsonNode containing the serialized property + // : the name of the property + // : the value of the property + // : a #GParamSpec + extern (C) Node* /*new*/ function (Serializable* serializable, char* property_name, GObject2.Value* value, GObject2.ParamSpec* pspec) serialize_property; + + // RETURNS: %TRUE if the property was successfully deserialized. + // : the name of the property + // : a pointer to an uninitialized #GValue + // : a #GParamSpec + // : a #JsonNode containing the serialized property + extern (C) int function (Serializable* serializable, char* property_name, /*out*/ GObject2.Value* value, GObject2.ParamSpec* pspec, Node* property_node) deserialize_property; + + // RETURNS: the #GParamSpec for the property + // : the name of the property + extern (C) GObject2.ParamSpec* function (Serializable* serializable, char* name) find_property; + // Unintrospectable functionp: list_properties() / () + extern (C) GObject2.ParamSpec** function (Serializable* serializable, uint* n_pspecs) list_properties; + extern (C) void function (Serializable* serializable, GObject2.ParamSpec* pspec, GObject2.Value* value) set_property; + extern (C) void function (Serializable* serializable, GObject2.ParamSpec* pspec, GObject2.Value* value) get_property; +} + + +// Checks whether it is possible to deserialize a #GBoxed of +// type @gboxed_type from a #JsonNode of type @node_type +// RETURNS: %TRUE if the type can be deserialized, %FALSE otherwise +// : a boxed type +// : a #JsonNode type +static int boxed_can_deserialize(Type gboxed_type, NodeType node_type) { + return json_boxed_can_deserialize(gboxed_type, node_type); +} + + +// Checks whether it is possible to serialize a #GBoxed of +// type @gboxed_type into a #JsonNode. The type of the +// #JsonNode is placed inside @node_type if the function +// returns %TRUE and it's undefined otherwise. +// +// and %FALSE otherwise. +// RETURNS: %TRUE if the type can be serialized, +// : a boxed type +// : the #JsonNode type to which the boxed type can be serialized into +static int boxed_can_serialize(Type gboxed_type, /*out*/ NodeType* node_type) { + return json_boxed_can_serialize(gboxed_type, node_type); +} + + +// Deserializes @node into a #GBoxed of @gboxed_type +// +// g_boxed_free() to release the resources allocated by this +// function +// RETURNS: the newly allocated #GBoxed. Use +// : a boxed type +// : a #JsonNode +static void* /*new*/ boxed_deserialize(Type gboxed_type, Node* node) { + return json_boxed_deserialize(gboxed_type, node); +} + + +// Unintrospectable function: boxed_register_deserialize_func() / json_boxed_register_deserialize_func() +// Registers a deserialization function for a #GBoxed of type @gboxed_type +// from a #JsonNode of type @node_type +// : a boxed type +// : a node type +// : deserialization function for @boxed_type from a #JsonNode of type @node_type +static void boxed_register_deserialize_func(Type gboxed_type, NodeType node_type, BoxedDeserializeFunc deserialize_func) { + json_boxed_register_deserialize_func(gboxed_type, node_type, deserialize_func); +} + + +// Unintrospectable function: boxed_register_serialize_func() / json_boxed_register_serialize_func() +// Registers a serialization function for a #GBoxed of type @gboxed_type +// to a #JsonNode of type @node_type +// : a boxed type +// : a node type +// : serialization function for @boxed_type into a #JsonNode of type @node_type +static void boxed_register_serialize_func(Type gboxed_type, NodeType node_type, BoxedSerializeFunc serialize_func) { + json_boxed_register_serialize_func(gboxed_type, node_type, serialize_func); +} + + +// Serializes @boxed, a pointer to a #GBoxed of type @gboxed_type, +// into a #JsonNode +// +// boxed type, or %NULL if serialization either failed or was not possible +// RETURNS: a #JsonNode with the serialization of the +// : a boxed type +// : a pointer to a #GBoxed of type @gboxed_type +static Node* /*new*/ boxed_serialize(Type gboxed_type, const(void)* boxed) { + return json_boxed_serialize(gboxed_type, boxed); +} + + +// Deserializes a JSON data stream and creates the corresponding +// #GObject class. If @gtype implements the #JsonSerializableIface +// interface, it will be asked to deserialize all the JSON members +// into the respective properties; otherwise, the default implementation +// will be used to translate the compatible JSON native types. +// +// Note: the JSON data stream must be an object declaration. +// RETURNS: a #GObject or %NULL +// : the #GType of object to construct +// : a JSON data stream +// : length of the data stream +static GObject2.Object* /*new*/ construct_gobject(Type gtype, char* data, size_t length, GLib2.Error** error=null) { + return json_construct_gobject(gtype, data, length, error); +} + + +// Creates a new #GObject of type @gtype, and constructs it +// using the members of the passed #JsonObject +// +// instance. Use g_object_unref() to free the resources +// allocated by this function +// RETURNS: The newly created #GObject +// : the type of the #GObject to create +// : a #JsonNode of type %JSON_NODE_OBJECT describing the instance of type @gtype +static GObject2.Object* /*new*/ gobject_deserialize(Type gtype, Node* node) { + return json_gobject_deserialize(gtype, node); +} + + +// Deserializes a JSON data stream and creates the corresponding +// #GObject class. If @gtype implements the #JsonSerializableIface +// interface, it will be asked to deserialize all the JSON members +// into the respective properties; otherwise, the default implementation +// will be used to translate the compatible JSON native types. +// +// Note: the JSON data stream must be an object declaration. +// RETURNS: a #GObject or %NULL +// : the #GType of object to construct +// : a JSON data stream +// : length of the data stream, or -1 if it is NUL-terminated +static GObject2.Object* /*new*/ gobject_from_data(Type gtype, char* data, ssize_t length, GLib2.Error** error=null) { + return json_gobject_from_data(gtype, data, length, error); +} + + +// Creates a #JsonNode representing the passed #GObject +// instance. Each member of the returned JSON object will +// map to a property of the #GObject +// +// of type %JSON_NODE_OBJECT. Use json_node_free() to free +// the resources allocated by this function +// RETURNS: the newly created #JsonNode +// : a #GObject +static Node* /*new*/ gobject_serialize(GObject2.Object* gobject) { + return json_gobject_serialize(gobject); +} + + +// Serializes a #GObject into a JSON data stream, iterating recursively +// over each property. +// +// If @gobject implements the #JsonSerializableIface interface, it will +// be asked to serialize all its properties; otherwise, the default +// implementation will be use to translate the compatible types into +// JSON native types. +// RETURNS: a JSON data stream representing the passed #GObject +// : a #GObject +// : return value for the length of the buffer, or %NULL +static char* /*new*/ gobject_to_data(GObject2.Object* gobject, /*out*/ size_t* length) { + return json_gobject_to_data(gobject, length); +} + + +// Converts a JSON data structure to a GVariant value using @signature to +// resolve ambiguous data types. If no error occurs, the resulting #GVariant +// is guaranteed to conform to @signature. +// +// If @signature is not %NULL but does not represent a valid GVariant type +// string, %NULL is returned and error is set to %G_IO_ERROR_INVALID_ARGUMENT. +// If a @signature is provided but the JSON structure cannot be mapped to it, +// %NULL is returned and error is set to %G_IO_ERROR_INVALID_DATA. +// If @signature is %NULL, the conversion is done based strictly on the types +// in the JSON nodes. +// +// @signature, or %NULL on error +// RETURNS: A newly created #GVariant compliant with +// : A #JsonNode to convert +// : A valid #GVariant type string, or %NULL +static GLib2.Variant* /*new*/ gvariant_deserialize(Node* json_node, char* signature, GLib2.Error** error=null) { + return json_gvariant_deserialize(json_node, signature, error); +} + + +// Converts a JSON string to a #GVariant value. This method works exactly +// like json_gvariant_deserialize(), but takes a JSON encoded string instead. +// The string is first converted to a #JsonNode using #JsonParser, and then +// json_gvariant_deserialize() is called. +// +// @signature, or %NULL on error +// RETURNS: A newly created #GVariant compliant with +// : A JSON data string +// : The length of @json, or -1 if %NULL-terminated +// : A valid #GVariant type string, or %NULL +static GLib2.Variant* /*new*/ gvariant_deserialize_data(char* json, ssize_t length, char* signature, GLib2.Error** error=null) { + return json_gvariant_deserialize_data(json, length, signature, error); +} + + +// Converts @variant to a JSON tree. +// +// JSON data structure obtained from @variant +// RETURNS: A #JsonNode representing the root of the +// : A #GVariant to convert +static Node* /*new*/ gvariant_serialize(GLib2.Variant* variant) { + return json_gvariant_serialize(variant); +} + + +// Converts @variant to its JSON encoded string representation. This method +// is actually a helper function. It uses json_gvariant_serialize() to obtain the +// JSON tree, and then #JsonGenerator to stringify it. +// +// @variant +// RETURNS: The JSON encoded string corresponding to +// : A #GVariant to convert +// : Return location for the length of the returned string, or %NULL +static char* /*new*/ gvariant_serialize_data(GLib2.Variant* variant, /*out*/ size_t* length=null) { + return json_gvariant_serialize_data(variant, length); +} + + +// Serializes a #GObject into a JSON data stream. If @gobject implements +// the #JsonSerializableIface interface, it will be asked to serizalize all +// its properties; otherwise, the default implementation will be use to +// translate the compatible types into JSON native types. +// RETURNS: a JSON data stream representing the passed #GObject +// : a #GObject +// : return value for the length of the buffer, or %NULL +static char* /*new*/ serialize_gobject(GObject2.Object* gobject, /*out*/ size_t* length) { + return json_serialize_gobject(gobject, length); +} + + +// C prototypes: + +extern (C) { +Array* /*new*/ json_array_new(); +Array* /*new*/ json_array_sized_new(uint n_elements); +void json_array_add_array_element(Array* this_, Array* value); +void json_array_add_boolean_element(Array* this_, int value); +void json_array_add_double_element(Array* this_, double value); +void json_array_add_element(Array* this_, Node* node); +void json_array_add_int_element(Array* this_, long value); +void json_array_add_null_element(Array* this_); +void json_array_add_object_element(Array* this_, Object* value); +void json_array_add_string_element(Array* this_, char* value); +Node* /*new*/ json_array_dup_element(Array* this_, uint index_); +void json_array_foreach_element(Array* this_, ArrayForeach func, void* data); +Array* json_array_get_array_element(Array* this_, uint index_); +int json_array_get_boolean_element(Array* this_, uint index_); +double json_array_get_double_element(Array* this_, uint index_); +Node* json_array_get_element(Array* this_, uint index_); +GLib2.List* /*new container*/ json_array_get_elements(Array* this_); +long json_array_get_int_element(Array* this_, uint index_); +uint json_array_get_length(Array* this_); +int json_array_get_null_element(Array* this_, uint index_); +Object* json_array_get_object_element(Array* this_, uint index_); +char* json_array_get_string_element(Array* this_, uint index_); +Array* /*new*/ json_array_ref(Array* this_); +void json_array_remove_element(Array* this_, uint index_); +void json_array_unref(Array* this_); +Builder* /*new*/ json_builder_new(); +Builder* json_builder_add_boolean_value(Builder* this_, int value); +Builder* json_builder_add_double_value(Builder* this_, double value); +Builder* json_builder_add_int_value(Builder* this_, long value); +Builder* json_builder_add_null_value(Builder* this_); +Builder* json_builder_add_string_value(Builder* this_, char* value); +Builder* json_builder_add_value(Builder* this_, Node* node); +Builder* json_builder_begin_array(Builder* this_); +Builder* json_builder_begin_object(Builder* this_); +Builder* json_builder_end_array(Builder* this_); +Builder* json_builder_end_object(Builder* this_); +Node* /*new*/ json_builder_get_root(Builder* this_); +void json_builder_reset(Builder* this_); +Builder* json_builder_set_member_name(Builder* this_, char* member_name); +Generator* /*new*/ json_generator_new(); +uint json_generator_get_indent(Generator* this_); +dchar json_generator_get_indent_char(Generator* this_); +int json_generator_get_pretty(Generator* this_); +Node* json_generator_get_root(Generator* this_); +void json_generator_set_indent(Generator* this_, uint indent_level); +void json_generator_set_indent_char(Generator* this_, dchar indent_char); +void json_generator_set_pretty(Generator* this_, int is_pretty); +void json_generator_set_root(Generator* this_, Node* node); +char* /*new*/ json_generator_to_data(Generator* this_, /*out*/ size_t* length); +int json_generator_to_file(Generator* this_, char* filename, GLib2.Error** error); +int json_generator_to_stream(Generator* this_, Gio2.OutputStream* stream, Gio2.Cancellable* cancellable, GLib2.Error** error); +Node* /*new*/ json_node_new(NodeType type); +Node* /*new*/ json_node_copy(Node* this_); +Array* /*new*/ json_node_dup_array(Node* this_); +Object* /*new*/ json_node_dup_object(Node* this_); +char* /*new*/ json_node_dup_string(Node* this_); +void json_node_free(Node* this_); +Array* json_node_get_array(Node* this_); +int json_node_get_boolean(Node* this_); +double json_node_get_double(Node* this_); +long json_node_get_int(Node* this_); +NodeType json_node_get_node_type(Node* this_); +Object* json_node_get_object(Node* this_); +Node* json_node_get_parent(Node* this_); +char* json_node_get_string(Node* this_); +void json_node_get_value(Node* this_, /*out*/ GObject2.Value* value); +Type json_node_get_value_type(Node* this_); +int json_node_is_null(Node* this_); +void json_node_set_array(Node* this_, Array* array); +void json_node_set_boolean(Node* this_, int value); +void json_node_set_double(Node* this_, double value); +void json_node_set_int(Node* this_, long value); +void json_node_set_object(Node* this_, Object* object); +void json_node_set_parent(Node* this_, Node* parent); +void json_node_set_string(Node* this_, char* value); +void json_node_set_value(Node* this_, GObject2.Value* value); +void json_node_take_array(Node* this_, Array* array); +void json_node_take_object(Node* this_, Object* object); +char* json_node_type_name(Node* this_); +Object* /*new*/ json_object_new(); +void json_object_add_member(Object* this_, char* member_name, Node* node); +Node* /*new*/ json_object_dup_member(Object* this_, char* member_name); +void json_object_foreach_member(Object* this_, ObjectForeach func, void* data); +Array* json_object_get_array_member(Object* this_, char* member_name); +int json_object_get_boolean_member(Object* this_, char* member_name); +double json_object_get_double_member(Object* this_, char* member_name); +long json_object_get_int_member(Object* this_, char* member_name); +Node* json_object_get_member(Object* this_, char* member_name); +GLib2.List* /*new container*/ json_object_get_members(Object* this_); +int json_object_get_null_member(Object* this_, char* member_name); +Object* json_object_get_object_member(Object* this_, char* member_name); +uint json_object_get_size(Object* this_); +char* json_object_get_string_member(Object* this_, char* member_name); +GLib2.List* /*new container*/ json_object_get_values(Object* this_); +int json_object_has_member(Object* this_, char* member_name); +Object* /*new*/ json_object_ref(Object* this_); +void json_object_remove_member(Object* this_, char* member_name); +void json_object_set_array_member(Object* this_, char* member_name, Array* value); +void json_object_set_boolean_member(Object* this_, char* member_name, int value); +void json_object_set_double_member(Object* this_, char* member_name, double value); +void json_object_set_int_member(Object* this_, char* member_name, long value); +void json_object_set_member(Object* this_, char* member_name, Node* node); +void json_object_set_null_member(Object* this_, char* member_name); +void json_object_set_object_member(Object* this_, char* member_name, Object* value); +void json_object_set_string_member(Object* this_, char* member_name, char* value); +void json_object_unref(Object* this_); +Parser* /*new*/ json_parser_new(); +GLib2.Quark json_parser_error_quark(); +uint json_parser_get_current_line(Parser* this_); +uint json_parser_get_current_pos(Parser* this_); +Node* json_parser_get_root(Parser* this_); +int json_parser_has_assignment(Parser* this_, /*out*/ char** variable_name=null); +int json_parser_load_from_data(Parser* this_, char* data, ssize_t length, GLib2.Error** error); +int json_parser_load_from_file(Parser* this_, char* filename, GLib2.Error** error); +int json_parser_load_from_stream(Parser* this_, Gio2.InputStream* stream, Gio2.Cancellable* cancellable, GLib2.Error** error); +void json_parser_load_from_stream_async(Parser* this_, Gio2.InputStream* stream, Gio2.Cancellable* cancellable, Gio2.AsyncReadyCallback callback, void* user_data); +int json_parser_load_from_stream_finish(Parser* this_, Gio2.AsyncResult* result, GLib2.Error** error); +Path* /*new*/ json_path_new(); +GLib2.Quark json_path_error_quark(); +Node* /*new*/ json_path_query(char* expression, Node* root, GLib2.Error** error); +int json_path_compile(Path* this_, char* expression, GLib2.Error** error); +Node* /*new*/ json_path_match(Path* this_, Node* root); +Reader* /*new*/ json_reader_new(Node* node=null); +GLib2.Quark json_reader_error_quark(); +int json_reader_count_elements(Reader* this_); +int json_reader_count_members(Reader* this_); +void json_reader_end_element(Reader* this_); +void json_reader_end_member(Reader* this_); +int json_reader_get_boolean_value(Reader* this_); +double json_reader_get_double_value(Reader* this_); +GLib2.Error* json_reader_get_error(Reader* this_); +long json_reader_get_int_value(Reader* this_); +char* json_reader_get_member_name(Reader* this_); +int json_reader_get_null_value(Reader* this_); +char* json_reader_get_string_value(Reader* this_); +Node* json_reader_get_value(Reader* this_); +int json_reader_is_array(Reader* this_); +int json_reader_is_object(Reader* this_); +int json_reader_is_value(Reader* this_); +char** /*new*/ json_reader_list_members(Reader* this_); +int json_reader_read_element(Reader* this_, uint index_); +int json_reader_read_member(Reader* this_, char* member_name); +void json_reader_set_root(Reader* this_, Node* root=null); +int json_serializable_default_deserialize_property(Serializable* this_, char* property_name, GObject2.Value* value, GObject2.ParamSpec* pspec, Node* property_node); +Node* /*new*/ json_serializable_default_serialize_property(Serializable* this_, char* property_name, GObject2.Value* value, GObject2.ParamSpec* pspec); +int json_serializable_deserialize_property(Serializable* this_, char* property_name, /*out*/ GObject2.Value* value, GObject2.ParamSpec* pspec, Node* property_node); +GObject2.ParamSpec* json_serializable_find_property(Serializable* this_, char* name); +void json_serializable_get_property(Serializable* this_, GObject2.ParamSpec* pspec, GObject2.Value* value); +GObject2.ParamSpec** /*new container*/ json_serializable_list_properties(Serializable* this_, /*out*/ uint* n_pspecs); +Node* /*new*/ json_serializable_serialize_property(Serializable* this_, char* property_name, GObject2.Value* value, GObject2.ParamSpec* pspec); +void json_serializable_set_property(Serializable* this_, GObject2.ParamSpec* pspec, GObject2.Value* value); +int json_boxed_can_deserialize(Type gboxed_type, NodeType node_type); +int json_boxed_can_serialize(Type gboxed_type, /*out*/ NodeType* node_type); +void* /*new*/ json_boxed_deserialize(Type gboxed_type, Node* node); +void json_boxed_register_deserialize_func(Type gboxed_type, NodeType node_type, BoxedDeserializeFunc deserialize_func); +void json_boxed_register_serialize_func(Type gboxed_type, NodeType node_type, BoxedSerializeFunc serialize_func); +Node* /*new*/ json_boxed_serialize(Type gboxed_type, const(void)* boxed); +GObject2.Object* /*new*/ json_construct_gobject(Type gtype, char* data, size_t length, GLib2.Error** error); +GObject2.Object* /*new*/ json_gobject_deserialize(Type gtype, Node* node); +GObject2.Object* /*new*/ json_gobject_from_data(Type gtype, char* data, ssize_t length, GLib2.Error** error); +Node* /*new*/ json_gobject_serialize(GObject2.Object* gobject); +char* /*new*/ json_gobject_to_data(GObject2.Object* gobject, /*out*/ size_t* length); +GLib2.Variant* /*new*/ json_gvariant_deserialize(Node* json_node, char* signature, GLib2.Error** error); +GLib2.Variant* /*new*/ json_gvariant_deserialize_data(char* json, ssize_t length, char* signature, GLib2.Error** error); +Node* /*new*/ json_gvariant_serialize(GLib2.Variant* variant); +char* /*new*/ json_gvariant_serialize_data(GLib2.Variant* variant, /*out*/ size_t* length=null); +char* /*new*/ json_serialize_gobject(GObject2.Object* gobject, /*out*/ size_t* length); +} -- 2.11.4.GIT