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

/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 0; tab-width: 2 -*- */
/* NodeList.vala
 *
 * Copyright (C) 2011-2013  Richard Schwarting <aquarichy@gmail.com>
 * Copyright (C) 2013-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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Authors:
 *      Richard Schwarting <aquarichy@gmail.com>
 *      Daniel Espinosa <esodan@gmail.com>
 */

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


#define GXML_TYPE_XNODE_LIST (gxml_xnode_list_get_type ())
#define GXML_XNODE_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_XNODE_LIST, GXmlxNodeList))
#define GXML_IS_XNODE_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_XNODE_LIST))
#define GXML_XNODE_LIST_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_XNODE_LIST, GXmlxNodeListIface))

typedef struct _GXmlxNodeList GXmlxNodeList;
typedef struct _GXmlxNodeListIface GXmlxNodeListIface;

#define GXML_TYPE_XNODE (gxml_xnode_get_type ())
#define GXML_XNODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_XNODE, GXmlxNode))
#define GXML_XNODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GXML_TYPE_XNODE, GXmlxNodeClass))
#define GXML_IS_XNODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_XNODE))
#define GXML_IS_XNODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GXML_TYPE_XNODE))
#define GXML_XNODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GXML_TYPE_XNODE, GXmlxNodeClass))

typedef struct _GXmlxNode GXmlxNode;
typedef struct _GXmlxNodeClass GXmlxNodeClass;

#define GXML_TYPE_LINKED_LIST (gxml_linked_list_get_type ())
#define GXML_LINKED_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_LINKED_LIST, GXmlLinkedList))
#define GXML_LINKED_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GXML_TYPE_LINKED_LIST, GXmlLinkedListClass))
#define GXML_IS_LINKED_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_LINKED_LIST))
#define GXML_IS_LINKED_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GXML_TYPE_LINKED_LIST))
#define GXML_LINKED_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GXML_TYPE_LINKED_LIST, GXmlLinkedListClass))

typedef struct _GXmlLinkedList GXmlLinkedList;
typedef struct _GXmlLinkedListClass GXmlLinkedListClass;
typedef struct _GXmlLinkedListPrivate GXmlLinkedListPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GXmlxNodeListIface {
	GTypeInterface parent_iface;
	GXmlxNode* (*item) (GXmlxNodeList* self, gulong idx);
	GXmlxNode* (*insert_before) (GXmlxNodeList* self, GXmlxNode* new_child, GXmlxNode* ref_child);
	GXmlxNode* (*replace_child) (GXmlxNodeList* self, GXmlxNode* new_child, GXmlxNode* old_child);
	GXmlxNode* (*remove_child) (GXmlxNodeList* self, GXmlxNode* old_child);
	GXmlxNode* (*append_child) (GXmlxNodeList* self, GXmlxNode* new_child);
	gchar* (*to_string) (GXmlxNodeList* self, gboolean in_line);
	GXmlxNode* (*first) (GXmlxNodeList* self);
	GXmlxNode* (*last) (GXmlxNodeList* self);
	GXmlxNode* (*get) (GXmlxNodeList* self, gint n);
	gulong (*get_length) (GXmlxNodeList* self);
	void (*set_length) (GXmlxNodeList* self, gulong value);
};

struct _GXmlLinkedList {
	GeeLinkedList parent_instance;
	GXmlLinkedListPrivate * priv;
	GXmlxNode* root;
};

struct _GXmlLinkedListClass {
	GeeLinkedListClass parent_class;
};


static gpointer gxml_linked_list_parent_class = NULL;
static GXmlxNodeListIface* gxml_linked_list_gxml_xnode_list_parent_iface = NULL;

GType gxml_xnode_get_type (void) G_GNUC_CONST;
GType gxml_xnode_list_get_type (void) G_GNUC_CONST;
GType gxml_linked_list_get_type (void) G_GNUC_CONST;
enum  {
	GXML_LINKED_LIST_DUMMY_PROPERTY,
	GXML_LINKED_LIST_LENGTH
};
GXmlLinkedList* gxml_linked_list_new (GXmlxNode* root);
GXmlLinkedList* gxml_linked_list_construct (GType object_type, GXmlxNode* root);
static GXmlxNode* gxml_linked_list_real_insert_before (GXmlxNodeList* base, GXmlxNode* new_child, GXmlxNode* ref_child);
static GXmlxNode* gxml_linked_list_real_replace_child (GXmlxNodeList* base, GXmlxNode* new_child, GXmlxNode* old_child);
static GXmlxNode* gxml_linked_list_real_remove_child (GXmlxNodeList* base, GXmlxNode* old_child);
static GXmlxNode* gxml_linked_list_real_append_child (GXmlxNodeList* base, GXmlxNode* new_child);
static GXmlxNode* gxml_linked_list_real_item (GXmlxNodeList* base, gulong idx);
GXmlxNode* gxml_xnode_list_get (GXmlxNodeList* self, gint n);
static gchar* gxml_linked_list_real_to_string (GXmlxNodeList* base, gboolean in_line);
gchar* gxml_xnode_stringify (GXmlxNode* self, gboolean format, gint level);
static GObject * gxml_linked_list_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
void gxml_init_init (void);
static void gxml_linked_list_finalize (GObject* obj);
gulong gxml_xnode_list_get_length (GXmlxNodeList* self);
static void _vala_gxml_linked_list_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
void gxml_xnode_list_set_length (GXmlxNodeList* self, gulong value);
static void _vala_gxml_linked_list_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


GXmlLinkedList* gxml_linked_list_construct (GType object_type, GXmlxNode* root) {
	GXmlLinkedList * self = NULL;
	GXmlxNode* _tmp0_ = NULL;
	GXmlxNode* _tmp1_ = NULL;
	g_return_val_if_fail (root != NULL, NULL);
	self = (GXmlLinkedList*) gee_linked_list_construct (object_type, GXML_TYPE_XNODE, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL, NULL, NULL);
	_tmp0_ = root;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->root);
	self->root = _tmp1_;
	return self;
}


GXmlLinkedList* gxml_linked_list_new (GXmlxNode* root) {
	return gxml_linked_list_construct (GXML_TYPE_LINKED_LIST, root);
}


static GXmlxNode* gxml_linked_list_real_insert_before (GXmlxNodeList* base, GXmlxNode* new_child, GXmlxNode* ref_child) {
	GXmlLinkedList * self;
	GXmlxNode* result = NULL;
	gint i = 0;
	GXmlxNode* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	self = (GXmlLinkedList*) base;
	g_return_val_if_fail (new_child != NULL, NULL);
	i = -1;
	_tmp0_ = ref_child;
	_tmp1_ = gee_abstract_collection_contains ((GeeAbstractCollection*) self, _tmp0_);
	if (_tmp1_) {
		GXmlxNode* _tmp2_ = NULL;
		gint _tmp3_ = 0;
		gint _tmp4_ = 0;
		GXmlxNode* _tmp5_ = NULL;
		GXmlxNode* _tmp6_ = NULL;
		_tmp2_ = ref_child;
		_tmp3_ = gee_abstract_list_index_of ((GeeAbstractList*) self, _tmp2_);
		i = _tmp3_;
		_tmp4_ = i;
		_tmp5_ = new_child;
		gee_abstract_list_insert ((GeeAbstractList*) self, _tmp4_, _tmp5_);
		_tmp6_ = new_child;
		result = _tmp6_;
		return result;
	}
	result = NULL;
	return result;
}


static GXmlxNode* gxml_linked_list_real_replace_child (GXmlxNodeList* base, GXmlxNode* new_child, GXmlxNode* old_child) {
	GXmlLinkedList * self;
	GXmlxNode* result = NULL;
	GXmlxNode* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	self = (GXmlLinkedList*) base;
	g_return_val_if_fail (new_child != NULL, NULL);
	g_return_val_if_fail (old_child != NULL, NULL);
	_tmp0_ = old_child;
	_tmp1_ = gee_abstract_collection_contains ((GeeAbstractCollection*) self, _tmp0_);
	if (_tmp1_) {
		gint i = 0;
		GXmlxNode* _tmp2_ = NULL;
		gint _tmp3_ = 0;
		gint _tmp4_ = 0;
		gpointer _tmp5_ = NULL;
		GXmlxNode* _tmp6_ = NULL;
		gint _tmp7_ = 0;
		GXmlxNode* _tmp8_ = NULL;
		GXmlxNode* _tmp9_ = NULL;
		_tmp2_ = old_child;
		_tmp3_ = gee_abstract_list_index_of ((GeeAbstractList*) self, _tmp2_);
		i = _tmp3_;
		_tmp4_ = i;
		_tmp5_ = gee_abstract_list_remove_at ((GeeAbstractList*) self, _tmp4_);
		_tmp6_ = (GXmlxNode*) _tmp5_;
		_g_object_unref0 (_tmp6_);
		_tmp7_ = i;
		_tmp8_ = new_child;
		gee_abstract_list_insert ((GeeAbstractList*) self, _tmp7_, _tmp8_);
		_tmp9_ = new_child;
		result = _tmp9_;
		return result;
	}
	result = NULL;
	return result;
}


static GXmlxNode* gxml_linked_list_real_remove_child (GXmlxNodeList* base, GXmlxNode* old_child) {
	GXmlLinkedList * self;
	GXmlxNode* result = NULL;
	GXmlxNode* _tmp0_ = NULL;
	gboolean _tmp1_ = FALSE;
	self = (GXmlLinkedList*) base;
	g_return_val_if_fail (old_child != NULL, NULL);
	_tmp0_ = old_child;
	_tmp1_ = gee_abstract_collection_contains ((GeeAbstractCollection*) self, _tmp0_);
	if (_tmp1_) {
		GXmlxNode* n = NULL;
		GXmlxNode* _tmp2_ = NULL;
		GXmlxNode* _tmp3_ = NULL;
		gint _tmp4_ = 0;
		gpointer _tmp5_ = NULL;
		GXmlxNode* _tmp6_ = NULL;
		GXmlxNode* _tmp7_ = NULL;
		_tmp2_ = old_child;
		n = _tmp2_;
		_tmp3_ = old_child;
		_tmp4_ = gee_abstract_list_index_of ((GeeAbstractList*) self, _tmp3_);
		_tmp5_ = gee_abstract_list_remove_at ((GeeAbstractList*) self, _tmp4_);
		_tmp6_ = (GXmlxNode*) _tmp5_;
		_g_object_unref0 (_tmp6_);
		_tmp7_ = n;
		result = _tmp7_;
		return result;
	}
	result = NULL;
	return result;
}


static GXmlxNode* gxml_linked_list_real_append_child (GXmlxNodeList* base, GXmlxNode* new_child) {
	GXmlLinkedList * self;
	GXmlxNode* result = NULL;
	GXmlxNode* _tmp0_ = NULL;
	GXmlxNode* _tmp1_ = NULL;
	self = (GXmlLinkedList*) base;
	g_return_val_if_fail (new_child != NULL, NULL);
	_tmp0_ = new_child;
	gee_abstract_collection_add ((GeeAbstractCollection*) self, _tmp0_);
	_tmp1_ = new_child;
	result = _tmp1_;
	return result;
}


static GXmlxNode* gxml_linked_list_real_item (GXmlxNodeList* base, gulong idx) {
	GXmlLinkedList * self;
	GXmlxNode* result = NULL;
	gulong _tmp0_ = 0UL;
	GXmlxNode* _tmp1_ = NULL;
	self = (GXmlLinkedList*) base;
	_tmp0_ = idx;
	_tmp1_ = gxml_xnode_list_get ((GXmlxNodeList*) self, (gint) _tmp0_);
	result = _tmp1_;
	return result;
}


static gchar* gxml_linked_list_real_to_string (GXmlxNodeList* base, gboolean in_line) {
	GXmlLinkedList * self;
	gchar* result = NULL;
	gchar* str = NULL;
	gchar* _tmp0_ = NULL;
	self = (GXmlLinkedList*) base;
	_tmp0_ = g_strdup ("");
	str = _tmp0_;
	{
		GXmlLinkedList* _node_list = NULL;
		GXmlLinkedList* _tmp1_ = NULL;
		gint _node_size = 0;
		GXmlLinkedList* _tmp2_ = NULL;
		gint _tmp3_ = 0;
		gint _tmp4_ = 0;
		gint _node_index = 0;
		_tmp1_ = _g_object_ref0 (self);
		_node_list = _tmp1_;
		_tmp2_ = _node_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_node_size = _tmp4_;
		_node_index = -1;
		while (TRUE) {
			gint _tmp5_ = 0;
			gint _tmp6_ = 0;
			gint _tmp7_ = 0;
			GXmlxNode* node = NULL;
			GXmlLinkedList* _tmp8_ = NULL;
			gint _tmp9_ = 0;
			GXmlxNode* _tmp10_ = NULL;
			const gchar* _tmp11_ = NULL;
			GXmlxNode* _tmp12_ = NULL;
			gchar* _tmp13_ = NULL;
			gchar* _tmp14_ = NULL;
			gchar* _tmp15_ = NULL;
			_tmp5_ = _node_index;
			_node_index = _tmp5_ + 1;
			_tmp6_ = _node_index;
			_tmp7_ = _node_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _node_list;
			_tmp9_ = _node_index;
			_tmp10_ = gxml_xnode_list_get ((GXmlxNodeList*) _tmp8_, _tmp9_);
			node = _tmp10_;
			_tmp11_ = str;
			_tmp12_ = node;
			_tmp13_ = gxml_xnode_stringify (_tmp12_, FALSE, 0);
			_tmp14_ = _tmp13_;
			_tmp15_ = g_strconcat (_tmp11_, _tmp14_, NULL);
			_g_free0 (str);
			str = _tmp15_;
			_g_free0 (_tmp14_);
			_g_object_unref0 (node);
		}
		_g_object_unref0 (_node_list);
	}
	result = str;
	return result;
}


static gulong gxml_linked_list_real_get_length (GXmlxNodeList* base) {
	gulong result;
	GXmlLinkedList* self;
	gint _tmp0_ = 0;
	gint _tmp1_ = 0;
	self = (GXmlLinkedList*) base;
	_tmp0_ = gee_abstract_collection_get_size ((GeeCollection*) self);
	_tmp1_ = _tmp0_;
	result = (gulong) _tmp1_;
	return result;
}


static void gxml_linked_list_real_set_length (GXmlxNodeList* base, gulong value) {
	GXmlLinkedList* self;
	self = (GXmlLinkedList*) base;
	g_object_notify ((GObject *) self, "length");
}


static GObject * gxml_linked_list_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	GXmlLinkedList * self;
	parent_class = G_OBJECT_CLASS (gxml_linked_list_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GXML_TYPE_LINKED_LIST, GXmlLinkedList);
	gxml_init_init ();
	return obj;
}


static void gxml_linked_list_class_init (GXmlLinkedListClass * klass) {
	gxml_linked_list_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_gxml_linked_list_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gxml_linked_list_set_property;
	G_OBJECT_CLASS (klass)->constructor = gxml_linked_list_constructor;
	G_OBJECT_CLASS (klass)->finalize = gxml_linked_list_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_LINKED_LIST_LENGTH, g_param_spec_ulong ("length", "length", "length", 0, G_MAXULONG, 0UL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void gxml_linked_list_gxml_xnode_list_interface_init (GXmlxNodeListIface * iface) {
	gxml_linked_list_gxml_xnode_list_parent_iface = g_type_interface_peek_parent (iface);
	iface->insert_before = (GXmlxNode* (*)(GXmlxNodeList*, GXmlxNode*, GXmlxNode*)) gxml_linked_list_real_insert_before;
	iface->replace_child = (GXmlxNode* (*)(GXmlxNodeList*, GXmlxNode*, GXmlxNode*)) gxml_linked_list_real_replace_child;
	iface->remove_child = (GXmlxNode* (*)(GXmlxNodeList*, GXmlxNode*)) gxml_linked_list_real_remove_child;
	iface->append_child = (GXmlxNode* (*)(GXmlxNodeList*, GXmlxNode*)) gxml_linked_list_real_append_child;
	iface->item = (GXmlxNode* (*)(GXmlxNodeList*, gulong)) gxml_linked_list_real_item;
	iface->to_string = (gchar* (*)(GXmlxNodeList*, gboolean)) gxml_linked_list_real_to_string;
	iface->first = (gpointer (*)(GXmlxNodeList*)) gee_linked_list_first;
	iface->last = (gpointer (*)(GXmlxNodeList*)) gee_linked_list_last;
	iface->get = (gpointer (*)(GXmlxNodeList*, gint)) gee_abstract_list_get;
	iface->get_length = gxml_linked_list_real_get_length;
	iface->set_length = gxml_linked_list_real_set_length;
}


static void gxml_linked_list_instance_init (GXmlLinkedList * self) {
}


static void gxml_linked_list_finalize (GObject* obj) {
	GXmlLinkedList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GXML_TYPE_LINKED_LIST, GXmlLinkedList);
	_g_object_unref0 (self->root);
	G_OBJECT_CLASS (gxml_linked_list_parent_class)->finalize (obj);
}


GType gxml_linked_list_get_type (void) {
	static volatile gsize gxml_linked_list_type_id__volatile = 0;
	if (g_once_init_enter (&gxml_linked_list_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GXmlLinkedListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gxml_linked_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GXmlLinkedList), 0, (GInstanceInitFunc) gxml_linked_list_instance_init, NULL };
		static const GInterfaceInfo gxml_xnode_list_info = { (GInterfaceInitFunc) gxml_linked_list_gxml_xnode_list_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType gxml_linked_list_type_id;
		gxml_linked_list_type_id = g_type_register_static (GEE_TYPE_LINKED_LIST, "GXmlLinkedList", &g_define_type_info, 0);
		g_type_add_interface_static (gxml_linked_list_type_id, GXML_TYPE_XNODE_LIST, &gxml_xnode_list_info);
		g_once_init_leave (&gxml_linked_list_type_id__volatile, gxml_linked_list_type_id);
	}
	return gxml_linked_list_type_id__volatile;
}


static void _vala_gxml_linked_list_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	GXmlLinkedList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GXML_TYPE_LINKED_LIST, GXmlLinkedList);
	switch (property_id) {
		case GXML_LINKED_LIST_LENGTH:
		g_value_set_ulong (value, gxml_xnode_list_get_length ((GXmlxNodeList*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_gxml_linked_list_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	GXmlLinkedList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GXML_TYPE_LINKED_LIST, GXmlLinkedList);
	switch (property_id) {
		case GXML_LINKED_LIST_LENGTH:
		gxml_xnode_list_set_length ((GXmlxNodeList*) self, g_value_get_ulong (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



