/* Element.c generated by valac 0.28.1, the Vala compiler
 * generated from Element.vala, do not modify */

/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 0; tab-width: 2 -*- */
/* Element.vala
 *
 * Copyright (C) 2015  Daniel Espinosa <esodan@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *      Daniel Espinosa <esodan@gmail.com>
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gio/gio.h>


#define GXML_TYPE_NODE (gxml_node_get_type ())
#define GXML_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_NODE, GXmlNode))
#define GXML_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_NODE))
#define GXML_NODE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_NODE, GXmlNodeIface))

typedef struct _GXmlNode GXmlNode;
typedef struct _GXmlNodeIface GXmlNodeIface;

#define GXML_TYPE_ELEMENT_LIST (gxml_element_list_get_type ())
#define GXML_ELEMENT_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_ELEMENT_LIST, GXmlElementList))
#define GXML_ELEMENT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GXML_TYPE_ELEMENT_LIST, GXmlElementListClass))
#define GXML_IS_ELEMENT_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_ELEMENT_LIST))
#define GXML_IS_ELEMENT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GXML_TYPE_ELEMENT_LIST))
#define GXML_ELEMENT_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GXML_TYPE_ELEMENT_LIST, GXmlElementListClass))

typedef struct _GXmlElementList GXmlElementList;
typedef struct _GXmlElementListClass GXmlElementListClass;

#define GXML_TYPE_NAMESPACE (gxml_namespace_get_type ())
#define GXML_NAMESPACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_NAMESPACE, GXmlNamespace))
#define GXML_IS_NAMESPACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_NAMESPACE))
#define GXML_NAMESPACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_NAMESPACE, GXmlNamespaceIface))

typedef struct _GXmlNamespace GXmlNamespace;
typedef struct _GXmlNamespaceIface GXmlNamespaceIface;

#define GXML_TYPE_NODE_TYPE (gxml_node_type_get_type ())

#define GXML_TYPE_DOCUMENT (gxml_document_get_type ())
#define GXML_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_DOCUMENT, GXmlDocument))
#define GXML_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_DOCUMENT))
#define GXML_DOCUMENT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_DOCUMENT, GXmlDocumentIface))

typedef struct _GXmlDocument GXmlDocument;
typedef struct _GXmlDocumentIface GXmlDocumentIface;

#define GXML_TYPE_ELEMENT (gxml_element_get_type ())
#define GXML_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_ELEMENT, GXmlElement))
#define GXML_IS_ELEMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_ELEMENT))
#define GXML_ELEMENT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_ELEMENT, GXmlElementIface))

typedef struct _GXmlElement GXmlElement;
typedef struct _GXmlElementIface GXmlElementIface;
typedef struct _GXmlElementListPrivate GXmlElementListPrivate;

struct _GXmlNamespaceIface {
	GTypeInterface parent_iface;
	gchar* (*get_uri) (GXmlNamespace* self);
	gchar* (*get_prefix) (GXmlNamespace* self);
};

typedef enum  {
	GXML_NODE_TYPE_X_UNKNOWN = 0,
	GXML_NODE_TYPE_ELEMENT = 1,
	GXML_NODE_TYPE_ATTRIBUTE,
	GXML_NODE_TYPE_TEXT,
	GXML_NODE_TYPE_CDATA_SECTION,
	GXML_NODE_TYPE_ENTITY_REFERENCE,
	GXML_NODE_TYPE_ENTITY,
	GXML_NODE_TYPE_PROCESSING_INSTRUCTION,
	GXML_NODE_TYPE_COMMENT,
	GXML_NODE_TYPE_DOCUMENT,
	GXML_NODE_TYPE_DOCUMENT_TYPE,
	GXML_NODE_TYPE_DOCUMENT_FRAGMENT,
	GXML_NODE_TYPE_NOTATION
} GXmlNodeType;

struct _GXmlDocumentIface {
	GTypeInterface parent_iface;
	GXmlNode* (*create_element) (GXmlDocument* self, const gchar* name, GError** error);
	GXmlNode* (*create_text) (GXmlDocument* self, const gchar* text);
	GXmlNode* (*create_comment) (GXmlDocument* self, const gchar* text);
	GXmlNode* (*create_cdata) (GXmlDocument* self, const gchar* text);
	GXmlNode* (*create_pi) (GXmlDocument* self, const gchar* target, const gchar* data);
	gboolean (*save) (GXmlDocument* self, GCancellable* cancellable, GError** error);
	gboolean (*save_as) (GXmlDocument* self, GFile* f, GCancellable* cancellable, GError** error);
	gboolean (*get_indent) (GXmlDocument* self);
	void (*set_indent) (GXmlDocument* self, gboolean value);
	gboolean (*get_ns_top) (GXmlDocument* self);
	void (*set_ns_top) (GXmlDocument* self, gboolean value);
	gboolean (*get_prefix_default_ns) (GXmlDocument* self);
	void (*set_prefix_default_ns) (GXmlDocument* self, gboolean value);
	gboolean (*get_backup) (GXmlDocument* self);
	void (*set_backup) (GXmlDocument* self, gboolean value);
	GXmlNode* (*get_root) (GXmlDocument* self);
	GFile* (*get_file) (GXmlDocument* self);
	void (*set_file) (GXmlDocument* self, GFile* value);
};

struct _GXmlNodeIface {
	GTypeInterface parent_iface;
	GXmlNode* (*get) (GXmlNode* self, const gchar* key);
	GXmlElementList* (*get_elements_by_property_value) (GXmlNode* self, const gchar* property, const gchar* value);
	gchar* (*to_string) (GXmlNode* self);
	gboolean (*set_namespace) (GXmlNode* self, const gchar* uri, const gchar* prefix);
	gchar* (*ns_prefix) (GXmlNode* self);
	gchar* (*ns_uri) (GXmlNode* self);
	GeeList* (*get_namespaces) (GXmlNode* self);
	GeeBidirList* (*get_childs) (GXmlNode* self);
	GeeBidirList* (*get_children) (GXmlNode* self);
	GeeMap* (*get_attrs) (GXmlNode* self);
	gchar* (*get_name) (GXmlNode* self);
	gchar* (*get_value) (GXmlNode* self);
	void (*set_value) (GXmlNode* self, const gchar* value);
	GXmlNodeType (*get_type_node) (GXmlNode* self);
	GXmlDocument* (*get_document) (GXmlNode* self);
	GXmlNode* (*get_parent) (GXmlNode* self);
};

struct _GXmlElementIface {
	GTypeInterface parent_iface;
	void (*normalize) (GXmlElement* self);
	void (*set_attr) (GXmlElement* self, const gchar* name, const gchar* value);
	GXmlNode* (*get_attr) (GXmlElement* self, const gchar* name);
	void (*remove_attr) (GXmlElement* self, const gchar* name);
	void (*set_ns_attr) (GXmlElement* self, GXmlNamespace* ns, const gchar* name, const gchar* value);
	GXmlNode* (*get_ns_attr) (GXmlElement* self, const gchar* name, const gchar* uri);
	gchar* (*get_tag_name) (GXmlElement* self);
	gchar* (*get_content) (GXmlElement* self);
	void (*set_content) (GXmlElement* self, const gchar* value);
};

struct _GXmlElementList {
	GeeArrayList parent_instance;
	GXmlElementListPrivate * priv;
};

struct _GXmlElementListClass {
	GeeArrayListClass parent_class;
};


static gpointer gxml_element_list_parent_class = NULL;

GType gxml_element_list_get_type (void) G_GNUC_CONST;
GType gxml_namespace_get_type (void) G_GNUC_CONST;
GType gxml_node_type_get_type (void) G_GNUC_CONST;
GType gxml_document_get_type (void) G_GNUC_CONST;
GType gxml_node_get_type (void) G_GNUC_CONST;
GType gxml_element_get_type (void) G_GNUC_CONST;
void gxml_element_normalize (GXmlElement* self);
void gxml_element_set_attr (GXmlElement* self, const gchar* name, const gchar* value);
GXmlNode* gxml_element_get_attr (GXmlElement* self, const gchar* name);
void gxml_element_remove_attr (GXmlElement* self, const gchar* name);
void gxml_element_set_ns_attr (GXmlElement* self, GXmlNamespace* ns, const gchar* name, const gchar* value);
GXmlNode* gxml_element_get_ns_attr (GXmlElement* self, const gchar* name, const gchar* uri);
gchar* gxml_element_get_tag_name (GXmlElement* self);
gchar* gxml_element_get_content (GXmlElement* self);
void gxml_element_set_content (GXmlElement* self, const gchar* value);
enum  {
	GXML_ELEMENT_LIST_DUMMY_PROPERTY
};
GXmlElement* gxml_element_list_get (GXmlElementList* self, gint index);
GXmlElement** gxml_element_list_to_array (GXmlElementList* self, int* result_length1);
GXmlElementList* gxml_element_list_new (void);
GXmlElementList* gxml_element_list_construct (GType object_type);


/**
     * This merges all adjacent {@link GXml.Text} nodes that are
     * descendants of this {@link GXml.Element}.
     */
void gxml_element_normalize (GXmlElement* self) {
	g_return_if_fail (self != NULL);
	GXML_ELEMENT_GET_INTERFACE (self)->normalize (self);
}


/**
     * Add a new {@link GXml.Attribute} to this {@link GXml.Element}.
     *
     * You should provide a name and a value.
     */
void gxml_element_set_attr (GXmlElement* self, const gchar* name, const gchar* value) {
	g_return_if_fail (self != NULL);
	GXML_ELEMENT_GET_INTERFACE (self)->set_attr (self, name, value);
}


/**
     * Search for a {@link GXml.Attribute} with given name.
     *
     * All attributes could be get using {@link GXml.Node.attrs} property.
     */
GXmlNode* gxml_element_get_attr (GXmlElement* self, const gchar* name) {
	g_return_val_if_fail (self != NULL, NULL);
	return GXML_ELEMENT_GET_INTERFACE (self)->get_attr (self, name);
}


/**
     * Search for a {@link GXml.Attribute} with given name and removes it.
     */
void gxml_element_remove_attr (GXmlElement* self, const gchar* name) {
	g_return_if_fail (self != NULL);
	GXML_ELEMENT_GET_INTERFACE (self)->remove_attr (self, name);
}


/**
     * Set an {@link GXml.Attribute} with a given name, value and namespace.
     */
void gxml_element_set_ns_attr (GXmlElement* self, GXmlNamespace* ns, const gchar* name, const gchar* value) {
	g_return_if_fail (self != NULL);
	GXML_ELEMENT_GET_INTERFACE (self)->set_ns_attr (self, ns, name, value);
}


/**
     * Search for a {@link GXml.Attribute} with a given name and namespace uri.
     *
     * To get a attibute from {@link GXml.Node.attrs} with a given namespace
     * prefix, use "prefix:name".
     */
GXmlNode* gxml_element_get_ns_attr (GXmlElement* self, const gchar* name, const gchar* uri) {
	g_return_val_if_fail (self != NULL, NULL);
	return GXML_ELEMENT_GET_INTERFACE (self)->get_ns_attr (self, name, uri);
}


gchar* gxml_element_get_tag_name (GXmlElement* self) {
	g_return_val_if_fail (self != NULL, NULL);
	return GXML_ELEMENT_GET_INTERFACE (self)->get_tag_name (self);
}


gchar* gxml_element_get_content (GXmlElement* self) {
	g_return_val_if_fail (self != NULL, NULL);
	return GXML_ELEMENT_GET_INTERFACE (self)->get_content (self);
}


void gxml_element_set_content (GXmlElement* self, const gchar* value) {
	g_return_if_fail (self != NULL);
	GXML_ELEMENT_GET_INTERFACE (self)->set_content (self, value);
}


static void gxml_element_base_init (GXmlElementIface * iface) {
	static gboolean initialized = FALSE;
	if (!initialized) {
		initialized = TRUE;
		/**
		     * This should be just a different name for {@link GXml.Node.name}.
		     */
		g_object_interface_install_property (iface, g_param_spec_string ("tag-name", "tag-name", "tag-name", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
		/**
		     * This should be just a different name for {@link GXml.Node.value}.
		     */
		g_object_interface_install_property (iface, g_param_spec_string ("content", "content", "content", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	}
}


/**
 * Interface to access XML document's tags, properties and content.
 *
 * Provides methods to create new XML tags properties and its values, and 
 * access to tag's contents.
 */
GType gxml_element_get_type (void) {
	static volatile gsize gxml_element_type_id__volatile = 0;
	if (g_once_init_enter (&gxml_element_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GXmlElementIface), (GBaseInitFunc) gxml_element_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
		GType gxml_element_type_id;
		gxml_element_type_id = g_type_register_static (G_TYPE_INTERFACE, "GXmlElement", &g_define_type_info, 0);
		g_type_interface_add_prerequisite (gxml_element_type_id, G_TYPE_OBJECT);
		g_type_interface_add_prerequisite (gxml_element_type_id, GXML_TYPE_NODE);
		g_once_init_leave (&gxml_element_type_id__volatile, gxml_element_type_id);
	}
	return gxml_element_type_id__volatile;
}


GXmlElement* gxml_element_list_get (GXmlElementList* self, gint index) {
	GXmlElement* result = NULL;
	gint _tmp0_ = 0;
	gpointer _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = index;
	_tmp1_ = GEE_ABSTRACT_LIST_CLASS (gxml_element_list_parent_class)->get ((GeeAbstractList*) G_TYPE_CHECK_INSTANCE_CAST (self, GEE_TYPE_ARRAY_LIST, GeeArrayList), _tmp0_);
	result = (GXmlElement*) _tmp1_;
	return result;
}


GXmlElement** gxml_element_list_to_array (GXmlElementList* self, int* result_length1) {
	GXmlElement** result = NULL;
	gint _tmp0_ = 0;
	gpointer* _tmp1_ = NULL;
	GXmlElement** _tmp2_ = NULL;
	gint _tmp2__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = gee_collection_to_array (G_TYPE_CHECK_INSTANCE_CAST (self, GEE_TYPE_COLLECTION, GeeCollection), &_tmp0_);
	_tmp2_ = (GXmlElement**) _tmp1_;
	_tmp2__length1 = (_tmp0_ * sizeof (GXmlElement*)) / sizeof (GXmlElement*);
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}


GXmlElementList* gxml_element_list_construct (GType object_type) {
	GXmlElementList * self = NULL;
	self = (GXmlElementList*) gee_array_list_construct (object_type, GXML_TYPE_ELEMENT, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
	return self;
}


GXmlElementList* gxml_element_list_new (void) {
	return gxml_element_list_construct (GXML_TYPE_ELEMENT_LIST);
}


static void gxml_element_list_class_init (GXmlElementListClass * klass) {
	gxml_element_list_parent_class = g_type_class_peek_parent (klass);
}


static void gxml_element_list_instance_init (GXmlElementList * self) {
}


/**
 * Convenient class for a list of {@link GXml.Element} objects based on
 * {@link Gee.ListArray}, with good support for bindings.
 */
GType gxml_element_list_get_type (void) {
	static volatile gsize gxml_element_list_type_id__volatile = 0;
	if (g_once_init_enter (&gxml_element_list_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GXmlElementListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gxml_element_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GXmlElementList), 0, (GInstanceInitFunc) gxml_element_list_instance_init, NULL };
		GType gxml_element_list_type_id;
		gxml_element_list_type_id = g_type_register_static (GEE_TYPE_ARRAY_LIST, "GXmlElementList", &g_define_type_info, 0);
		g_once_init_leave (&gxml_element_list_type_id__volatile, gxml_element_list_type_id);
	}
	return gxml_element_list_type_id__volatile;
}



