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

/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/*
 *
 * Copyright (C) 2016  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 "gxml/gxml.h"
#include <glib.h>
#include <gee.h>
#include <glib-object.h>
#include <libxml/tree.h>
#include <string.h>
#include "gxml.h"

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	GXML_XCHILD_NODE_0_PROPERTY,
	GXML_XCHILD_NODE_NUM_PROPERTIES
};
static GParamSpec* gxml_xchild_node_properties[GXML_XCHILD_NODE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	GXML_XNON_DOCUMENT_CHILD_NODE_0_PROPERTY,
	GXML_XNON_DOCUMENT_CHILD_NODE_PREVIOUS_ELEMENT_SIBLING_PROPERTY,
	GXML_XNON_DOCUMENT_CHILD_NODE_NEXT_ELEMENT_SIBLING_PROPERTY,
	GXML_XNON_DOCUMENT_CHILD_NODE_NUM_PROPERTIES
};
static GParamSpec* gxml_xnon_document_child_node_properties[GXML_XNON_DOCUMENT_CHILD_NODE_NUM_PROPERTIES];

static gpointer gxml_xchild_node_parent_class = NULL;
static GXmlDomChildNodeIface * gxml_xchild_node_gxml_dom_child_node_parent_iface = NULL;
static gpointer gxml_xnon_document_child_node_parent_class = NULL;
static GXmlDomNonDocumentTypeChildNodeIface * gxml_xnon_document_child_node_gxml_dom_non_document_type_child_node_parent_iface = NULL;

static void gxml_xchild_node_real_remove (GXmlDomChildNode* base);
static GType gxml_xchild_node_get_type_once (void);
static GType gxml_xnon_document_child_node_get_type_once (void);
static void _vala_gxml_xnon_document_child_node_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
gxml_xchild_node_real_remove (GXmlDomChildNode* base)
{
	GXmlXChildNode * self;
	GXmlDomNode* _tmp0_;
	GXmlDomNode* _tmp1_;
	GXmlDomNode* _tmp2_;
	gboolean _tmp3_;
	self = (GXmlXChildNode*) base;
	_tmp0_ = gxml_dom_node_get_parent_node ((GXmlDomNode*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = _tmp1_;
	_tmp3_ = _tmp2_ != NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		gint i = 0;
		GXmlDomNode* _tmp4_;
		GXmlDomNode* _tmp5_;
		GXmlDomNode* _tmp6_;
		GXmlDomNodeList* _tmp7_;
		GXmlDomNodeList* _tmp8_;
		GXmlDomNodeList* _tmp9_;
		gint _tmp10_;
		GXmlDomNode* _tmp11_;
		GXmlDomNode* _tmp12_;
		GXmlDomNode* _tmp13_;
		GXmlDomNodeList* _tmp14_;
		GXmlDomNodeList* _tmp15_;
		GXmlDomNodeList* _tmp16_;
		gpointer _tmp17_;
		GXmlDomNode* _tmp18_;
		_tmp4_ = gxml_dom_node_get_parent_node ((GXmlDomNode*) self);
		_tmp5_ = _tmp4_;
		_tmp6_ = _tmp5_;
		_tmp7_ = gxml_dom_node_get_child_nodes (_tmp6_);
		_tmp8_ = _tmp7_;
		_tmp9_ = _tmp8_;
		_tmp10_ = gee_list_index_of ((GeeList*) _tmp9_, (GXmlDomNode*) self);
		_g_object_unref0 (_tmp9_);
		_g_object_unref0 (_tmp6_);
		i = _tmp10_;
		_tmp11_ = gxml_dom_node_get_parent_node ((GXmlDomNode*) self);
		_tmp12_ = _tmp11_;
		_tmp13_ = _tmp12_;
		_tmp14_ = gxml_dom_node_get_child_nodes (_tmp13_);
		_tmp15_ = _tmp14_;
		_tmp16_ = _tmp15_;
		_tmp17_ = gee_list_remove_at ((GeeList*) _tmp16_, i);
		_tmp18_ = (GXmlDomNode*) _tmp17_;
		_g_object_unref0 (_tmp18_);
		_g_object_unref0 (_tmp16_);
		_g_object_unref0 (_tmp13_);
	}
}

GXmlXChildNode*
gxml_xchild_node_construct (GType object_type)
{
	GXmlXChildNode * self = NULL;
	self = (GXmlXChildNode*) gxml_xnode_construct (object_type);
	return self;
}

GXmlXChildNode*
gxml_xchild_node_new (void)
{
	return gxml_xchild_node_construct (GXML_TYPE_XCHILD_NODE);
}

static void
gxml_xchild_node_class_init (GXmlXChildNodeClass * klass,
                             gpointer klass_data)
{
	gxml_xchild_node_parent_class = g_type_class_peek_parent (klass);
}

static void
gxml_xchild_node_gxml_dom_child_node_interface_init (GXmlDomChildNodeIface * iface,
                                                     gpointer iface_data)
{
	gxml_xchild_node_gxml_dom_child_node_parent_iface = g_type_interface_peek_parent (iface);
	iface->remove = (void (*) (GXmlDomChildNode*)) gxml_xchild_node_real_remove;
}

static void
gxml_xchild_node_instance_init (GXmlXChildNode * self,
                                gpointer klass)
{
}

/**
 * DOM4 class for child nodes, powered by libxml2 library.
 */
static GType
gxml_xchild_node_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GXmlXChildNodeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gxml_xchild_node_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GXmlXChildNode), 0, (GInstanceInitFunc) gxml_xchild_node_instance_init, NULL };
	static const GInterfaceInfo gxml_dom_child_node_info = { (GInterfaceInitFunc) gxml_xchild_node_gxml_dom_child_node_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gxml_xchild_node_type_id;
	gxml_xchild_node_type_id = g_type_register_static (GXML_TYPE_XNODE, "GXmlXChildNode", &g_define_type_info, 0);
	g_type_add_interface_static (gxml_xchild_node_type_id, GXML_TYPE_DOM_CHILD_NODE, &gxml_dom_child_node_info);
	return gxml_xchild_node_type_id;
}

GType
gxml_xchild_node_get_type (void)
{
	static volatile gsize gxml_xchild_node_type_id__once = 0;
	if (g_once_init_enter (&gxml_xchild_node_type_id__once)) {
		GType gxml_xchild_node_type_id;
		gxml_xchild_node_type_id = gxml_xchild_node_get_type_once ();
		g_once_init_leave (&gxml_xchild_node_type_id__once, gxml_xchild_node_type_id);
	}
	return gxml_xchild_node_type_id__once;
}

static GXmlDomElement*
gxml_xnon_document_child_node_real_get_previous_element_sibling (GXmlDomNonDocumentTypeChildNode* base)
{
	GXmlDomElement* result;
	GXmlXNonDocumentChildNode* self;
	xmlNode* _tmp0_;
	xmlNode* n = NULL;
	xmlNode* _tmp1_;
	xmlNode* _tmp2_;
	xmlNode* _tmp3_;
	GXmlDomDocument* _tmp4_;
	GXmlDomDocument* _tmp5_;
	xmlNode* _tmp6_;
	GXmlXElement* _tmp7_;
	self = (GXmlXNonDocumentChildNode*) base;
	_tmp0_ = ((GXmlXNode*) self)->_node;
	if (_tmp0_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp1_ = ((GXmlXNode*) self)->_node;
	_tmp2_ = xmlPreviousElementSibling (_tmp1_);
	n = _tmp2_;
	_tmp3_ = n;
	if (_tmp3_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp4_ = gxml_dom_node_get_owner_document ((GXmlDomNode*) self);
	_tmp5_ = _tmp4_;
	_tmp6_ = n;
	_tmp7_ = gxml_xelement_new (GXML_IS_XDOCUMENT (_tmp5_) ? ((GXmlXDocument*) _tmp5_) : NULL, _tmp6_);
	result = (GXmlDomElement*) _tmp7_;
	return result;
}

static GXmlDomElement*
gxml_xnon_document_child_node_real_get_next_element_sibling (GXmlDomNonDocumentTypeChildNode* base)
{
	GXmlDomElement* result;
	GXmlXNonDocumentChildNode* self;
	xmlNode* _tmp0_;
	xmlNode* n = NULL;
	xmlNode* _tmp1_;
	xmlNode* _tmp2_;
	xmlNode* _tmp3_;
	GXmlDomDocument* _tmp4_;
	GXmlDomDocument* _tmp5_;
	xmlNode* _tmp6_;
	GXmlXElement* _tmp7_;
	self = (GXmlXNonDocumentChildNode*) base;
	_tmp0_ = ((GXmlXNode*) self)->_node;
	if (_tmp0_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp1_ = ((GXmlXNode*) self)->_node;
	_tmp2_ = xmlNextElementSibling (_tmp1_);
	n = _tmp2_;
	_tmp3_ = n;
	if (_tmp3_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp4_ = gxml_dom_node_get_owner_document ((GXmlDomNode*) self);
	_tmp5_ = _tmp4_;
	_tmp6_ = n;
	_tmp7_ = gxml_xelement_new (GXML_IS_XDOCUMENT (_tmp5_) ? ((GXmlXDocument*) _tmp5_) : NULL, _tmp6_);
	result = (GXmlDomElement*) _tmp7_;
	return result;
}

GXmlXNonDocumentChildNode*
gxml_xnon_document_child_node_construct (GType object_type)
{
	GXmlXNonDocumentChildNode * self = NULL;
	self = (GXmlXNonDocumentChildNode*) gxml_xchild_node_construct (object_type);
	return self;
}

GXmlXNonDocumentChildNode*
gxml_xnon_document_child_node_new (void)
{
	return gxml_xnon_document_child_node_construct (GXML_TYPE_XNON_DOCUMENT_CHILD_NODE);
}

static void
gxml_xnon_document_child_node_class_init (GXmlXNonDocumentChildNodeClass * klass,
                                          gpointer klass_data)
{
	gxml_xnon_document_child_node_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->get_property = _vala_gxml_xnon_document_child_node_get_property;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_XNON_DOCUMENT_CHILD_NODE_PREVIOUS_ELEMENT_SIBLING_PROPERTY, gxml_xnon_document_child_node_properties[GXML_XNON_DOCUMENT_CHILD_NODE_PREVIOUS_ELEMENT_SIBLING_PROPERTY] = g_param_spec_object ("previous-element-sibling", "previous-element-sibling", "previous-element-sibling", GXML_TYPE_DOM_ELEMENT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_XNON_DOCUMENT_CHILD_NODE_NEXT_ELEMENT_SIBLING_PROPERTY, gxml_xnon_document_child_node_properties[GXML_XNON_DOCUMENT_CHILD_NODE_NEXT_ELEMENT_SIBLING_PROPERTY] = g_param_spec_object ("next-element-sibling", "next-element-sibling", "next-element-sibling", GXML_TYPE_DOM_ELEMENT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
gxml_xnon_document_child_node_gxml_dom_non_document_type_child_node_interface_init (GXmlDomNonDocumentTypeChildNodeIface * iface,
                                                                                    gpointer iface_data)
{
	gxml_xnon_document_child_node_gxml_dom_non_document_type_child_node_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_previous_element_sibling = gxml_xnon_document_child_node_real_get_previous_element_sibling;
	iface->get_next_element_sibling = gxml_xnon_document_child_node_real_get_next_element_sibling;
}

static void
gxml_xnon_document_child_node_instance_init (GXmlXNonDocumentChildNode * self,
                                             gpointer klass)
{
}

static GType
gxml_xnon_document_child_node_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GXmlXNonDocumentChildNodeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gxml_xnon_document_child_node_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GXmlXNonDocumentChildNode), 0, (GInstanceInitFunc) gxml_xnon_document_child_node_instance_init, NULL };
	static const GInterfaceInfo gxml_dom_non_document_type_child_node_info = { (GInterfaceInitFunc) gxml_xnon_document_child_node_gxml_dom_non_document_type_child_node_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gxml_xnon_document_child_node_type_id;
	gxml_xnon_document_child_node_type_id = g_type_register_static (GXML_TYPE_XCHILD_NODE, "GXmlXNonDocumentChildNode", &g_define_type_info, 0);
	g_type_add_interface_static (gxml_xnon_document_child_node_type_id, GXML_TYPE_DOM_NON_DOCUMENT_TYPE_CHILD_NODE, &gxml_dom_non_document_type_child_node_info);
	return gxml_xnon_document_child_node_type_id;
}

GType
gxml_xnon_document_child_node_get_type (void)
{
	static volatile gsize gxml_xnon_document_child_node_type_id__once = 0;
	if (g_once_init_enter (&gxml_xnon_document_child_node_type_id__once)) {
		GType gxml_xnon_document_child_node_type_id;
		gxml_xnon_document_child_node_type_id = gxml_xnon_document_child_node_get_type_once ();
		g_once_init_leave (&gxml_xnon_document_child_node_type_id__once, gxml_xnon_document_child_node_type_id);
	}
	return gxml_xnon_document_child_node_type_id__once;
}

static void
_vala_gxml_xnon_document_child_node_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec)
{
	GXmlXNonDocumentChildNode * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GXML_TYPE_XNON_DOCUMENT_CHILD_NODE, GXmlXNonDocumentChildNode);
	switch (property_id) {
		case GXML_XNON_DOCUMENT_CHILD_NODE_PREVIOUS_ELEMENT_SIBLING_PROPERTY:
		g_value_take_object (value, gxml_dom_non_document_type_child_node_get_previous_element_sibling ((GXmlDomNonDocumentTypeChildNode*) self));
		break;
		case GXML_XNON_DOCUMENT_CHILD_NODE_NEXT_ELEMENT_SIBLING_PROPERTY:
		g_value_take_object (value, gxml_dom_non_document_type_child_node_get_next_element_sibling ((GXmlDomNonDocumentTypeChildNode*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

