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

/* GAttribute.vala
 *
 * 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 <libxml/tree.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.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_XATTRIBUTE_0_PROPERTY,
	GXML_XATTRIBUTE_NAME_PROPERTY,
	GXML_XATTRIBUTE_VALUE_PROPERTY,
	GXML_XATTRIBUTE_PREFIX_PROPERTY,
	GXML_XATTRIBUTE_PARENT_PROPERTY,
	GXML_XATTRIBUTE_NAMESPACE_URI_PROPERTY,
	GXML_XATTRIBUTE_LOCAL_NAME_PROPERTY,
	GXML_XATTRIBUTE_NUM_PROPERTIES
};
static GParamSpec* gxml_xattribute_properties[GXML_XATTRIBUTE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GXmlXAttributePrivate {
	xmlAttr* _attr;
};

static gint GXmlXAttribute_private_offset;
static gpointer gxml_xattribute_parent_class = NULL;
static GXmlDomAttrIface * gxml_xattribute_gxml_dom_attr_parent_iface = NULL;

static void gxml_xattribute_finalize (GObject * obj);
static GType gxml_xattribute_get_type_once (void);
static void _vala_gxml_xattribute_get_property (GObject * object,
                                         guint property_id,
                                         GValue * value,
                                         GParamSpec * pspec);
static void _vala_gxml_xattribute_set_property (GObject * object,
                                         guint property_id,
                                         const GValue * value,
                                         GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
gxml_xattribute_get_instance_private (GXmlXAttribute* self)
{
	return G_STRUCT_MEMBER_P (self, GXmlXAttribute_private_offset);
}

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

GXmlXAttribute*
gxml_xattribute_construct (GType object_type,
                           GXmlXDocument* doc,
                           xmlAttr* node)
{
	GXmlXAttribute * self = NULL;
	xmlAttr* _tmp0_;
	xmlNode* _tmp1_;
	GXmlXDocument* _tmp2_;
	g_return_val_if_fail (doc != NULL, NULL);
	self = (GXmlXAttribute*) gxml_xnode_construct (object_type);
	self->priv->_attr = node;
	_tmp0_ = self->priv->_attr;
	_tmp1_ = _tmp0_->parent;
	((GXmlXNode*) self)->_node = _tmp1_;
	_tmp2_ = _g_object_ref0 (doc);
	_g_object_unref0 (((GXmlXNode*) self)->_doc);
	((GXmlXNode*) self)->_doc = _tmp2_;
	return self;
}

GXmlXAttribute*
gxml_xattribute_new (GXmlXDocument* doc,
                     xmlAttr* node)
{
	return gxml_xattribute_construct (GXML_TYPE_XATTRIBUTE, doc, node);
}

static gchar*
gxml_xattribute_real_get_name (GXmlXNode* base)
{
	gchar* result;
	GXmlXAttribute* self;
	xmlAttr* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	self = (GXmlXAttribute*) base;
	_tmp0_ = self->priv->_attr;
	_tmp1_ = _tmp0_->name;
	_tmp2_ = g_strdup (_tmp1_);
	result = _tmp2_;
	return result;
}

static gchar*
gxml_xattribute_real_get_value (GXmlXNode* base)
{
	gchar* result;
	GXmlXAttribute* self;
	gchar* nullstr = NULL;
	xmlNode* _tmp0_;
	xmlAttr* _tmp1_;
	xmlNs* _tmp2_;
	self = (GXmlXAttribute*) base;
	nullstr = NULL;
	_tmp0_ = ((GXmlXNode*) self)->_node;
	if (_tmp0_ == NULL) {
		result = nullstr;
		return result;
	}
	_tmp1_ = self->priv->_attr;
	_tmp2_ = _tmp1_->ns;
	if (_tmp2_ == NULL) {
		xmlNode* _tmp3_;
		xmlAttr* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp3_ = ((GXmlXNode*) self)->_node;
		_tmp4_ = self->priv->_attr;
		_tmp5_ = _tmp4_->name;
		_tmp6_ = (gchar*) xmlGetNoNsProp (_tmp3_, (xmlChar*) _tmp5_);
		result = _tmp6_;
		_g_free0 (nullstr);
		return result;
	} else {
		xmlNode* _tmp7_;
		xmlAttr* _tmp8_;
		const gchar* _tmp9_;
		xmlAttr* _tmp10_;
		xmlNs* _tmp11_;
		const gchar* _tmp12_;
		gchar* _tmp13_;
		_tmp7_ = ((GXmlXNode*) self)->_node;
		_tmp8_ = self->priv->_attr;
		_tmp9_ = _tmp8_->name;
		_tmp10_ = self->priv->_attr;
		_tmp11_ = _tmp10_->ns;
		_tmp12_ = _tmp11_->href;
		_tmp13_ = (gchar*) xmlGetNsProp (_tmp7_, (xmlChar*) _tmp9_, (xmlChar*) _tmp12_);
		result = _tmp13_;
		_g_free0 (nullstr);
		return result;
	}
}

static void
gxml_xattribute_real_set_value (GXmlXNode* base,
                                const gchar* value)
{
	GXmlXAttribute* self;
	xmlNode* _tmp0_;
	xmlAttr* _tmp1_;
	xmlNs* _tmp2_;
	self = (GXmlXAttribute*) base;
	_tmp0_ = ((GXmlXNode*) self)->_node;
	if (_tmp0_ == NULL) {
		return;
	}
	_tmp1_ = self->priv->_attr;
	_tmp2_ = _tmp1_->ns;
	if (_tmp2_ == NULL) {
		xmlNode* _tmp3_;
		xmlAttr* _tmp4_;
		const gchar* _tmp5_;
		_tmp3_ = ((GXmlXNode*) self)->_node;
		_tmp4_ = self->priv->_attr;
		_tmp5_ = _tmp4_->name;
		xmlSetProp (_tmp3_, (xmlChar*) _tmp5_, (xmlChar*) value);
	} else {
		xmlNode* _tmp6_;
		xmlAttr* _tmp7_;
		xmlNs* _tmp8_;
		xmlAttr* _tmp9_;
		const gchar* _tmp10_;
		_tmp6_ = ((GXmlXNode*) self)->_node;
		_tmp7_ = self->priv->_attr;
		_tmp8_ = _tmp7_->ns;
		_tmp9_ = self->priv->_attr;
		_tmp10_ = _tmp9_->name;
		xmlSetNsProp (_tmp6_, _tmp8_, (xmlChar*) _tmp10_, (xmlChar*) value);
	}
	g_object_notify_by_pspec ((GObject *) self, gxml_xattribute_properties[GXML_XATTRIBUTE_VALUE_PROPERTY]);
}

static gchar*
gxml_xattribute_real_get_prefix (GXmlDomAttr* base)
{
	gchar* result;
	GXmlXAttribute* self;
	xmlAttr* _tmp0_;
	xmlAttr* _tmp2_;
	xmlNs* _tmp3_;
	xmlAttr* _tmp5_;
	xmlNs* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	self = (GXmlXAttribute*) base;
	_tmp0_ = self->priv->_attr;
	if (_tmp0_ == NULL) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("");
		result = _tmp1_;
		return result;
	}
	_tmp2_ = self->priv->_attr;
	_tmp3_ = _tmp2_->ns;
	if (_tmp3_ == NULL) {
		gchar* _tmp4_;
		_tmp4_ = g_strdup ("");
		result = _tmp4_;
		return result;
	}
	_tmp5_ = self->priv->_attr;
	_tmp6_ = _tmp5_->ns;
	_tmp7_ = _tmp6_->prefix;
	_tmp8_ = g_strdup (_tmp7_);
	result = _tmp8_;
	return result;
}

static GXmlDomNode*
gxml_xattribute_real_get_parent (GXmlXNode* base)
{
	GXmlDomNode* result;
	GXmlXAttribute* self;
	GXmlDomNode* nullnode = NULL;
	xmlAttr* _tmp0_;
	GXmlDomDocument* _tmp1_;
	GXmlDomDocument* _tmp2_;
	xmlNode* _tmp3_;
	GXmlDomNode* _tmp4_;
	self = (GXmlXAttribute*) base;
	nullnode = NULL;
	_tmp0_ = self->priv->_attr;
	if (_tmp0_ == NULL) {
		result = nullnode;
		return result;
	}
	_tmp1_ = gxml_xnode_get_document ((GXmlXNode*) self);
	_tmp2_ = _tmp1_;
	_tmp3_ = ((GXmlXNode*) self)->_node;
	_tmp4_ = gxml_xnode_to_gnode (GXML_IS_XDOCUMENT (_tmp2_) ? ((GXmlXDocument*) _tmp2_) : NULL, _tmp3_, FALSE);
	result = _tmp4_;
	_g_object_unref0 (nullnode);
	return result;
}

static gchar*
gxml_xattribute_real_get_namespace_uri (GXmlDomAttr* base)
{
	gchar* result;
	GXmlXAttribute* self;
	xmlAttr* _tmp0_;
	xmlAttr* _tmp1_;
	xmlNs* _tmp2_;
	xmlAttr* _tmp3_;
	xmlNs* _tmp4_;
	const gchar* _tmp5_;
	gchar* _tmp6_;
	self = (GXmlXAttribute*) base;
	_tmp0_ = self->priv->_attr;
	if (_tmp0_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp1_ = self->priv->_attr;
	_tmp2_ = _tmp1_->ns;
	if (_tmp2_ == NULL) {
		result = NULL;
		return result;
	}
	_tmp3_ = self->priv->_attr;
	_tmp4_ = _tmp3_->ns;
	_tmp5_ = _tmp4_->href;
	_tmp6_ = g_strdup (_tmp5_);
	result = _tmp6_;
	return result;
}

static gchar*
gxml_xattribute_real_get_local_name (GXmlDomAttr* base)
{
	gchar* result;
	GXmlXAttribute* self;
	gchar* _tmp0_;
	gchar* _tmp1_;
	self = (GXmlXAttribute*) base;
	_tmp0_ = gxml_xnode_get_name (G_TYPE_CHECK_INSTANCE_CAST (self, GXML_TYPE_XNODE, GXmlXNode));
	_tmp1_ = _tmp0_;
	result = _tmp1_;
	return result;
}

static void
gxml_xattribute_class_init (GXmlXAttributeClass * klass,
                            gpointer klass_data)
{
	gxml_xattribute_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GXmlXAttribute_private_offset);
	GXML_XNODE_CLASS (klass)->get_name = (gchar* (*) (GXmlXNode*)) gxml_xattribute_real_get_name;
	GXML_XNODE_CLASS (klass)->get_value = (gchar* (*) (GXmlXNode*)) gxml_xattribute_real_get_value;
	GXML_XNODE_CLASS (klass)->set_value = (void (*) (GXmlXNode*, const gchar*)) gxml_xattribute_real_set_value;
	GXML_XNODE_CLASS (klass)->get_parent = (GXmlDomNode* (*) (GXmlXNode*)) gxml_xattribute_real_get_parent;
	G_OBJECT_CLASS (klass)->get_property = _vala_gxml_xattribute_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gxml_xattribute_set_property;
	G_OBJECT_CLASS (klass)->finalize = gxml_xattribute_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_XATTRIBUTE_NAME_PROPERTY, gxml_xattribute_properties[GXML_XATTRIBUTE_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_XATTRIBUTE_VALUE_PROPERTY, gxml_xattribute_properties[GXML_XATTRIBUTE_VALUE_PROPERTY] = g_param_spec_string ("value", "value", "value", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_XATTRIBUTE_PREFIX_PROPERTY, gxml_xattribute_properties[GXML_XATTRIBUTE_PREFIX_PROPERTY] = g_param_spec_string ("prefix", "prefix", "prefix", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_XATTRIBUTE_PARENT_PROPERTY, gxml_xattribute_properties[GXML_XATTRIBUTE_PARENT_PROPERTY] = g_param_spec_object ("parent", "parent", "parent", GXML_TYPE_DOM_NODE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_XATTRIBUTE_NAMESPACE_URI_PROPERTY, gxml_xattribute_properties[GXML_XATTRIBUTE_NAMESPACE_URI_PROPERTY] = g_param_spec_string ("namespace-uri", "namespace-uri", "namespace-uri", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GXML_XATTRIBUTE_LOCAL_NAME_PROPERTY, gxml_xattribute_properties[GXML_XATTRIBUTE_LOCAL_NAME_PROPERTY] = g_param_spec_string ("local-name", "local-name", "local-name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
gxml_xattribute_gxml_dom_attr_interface_init (GXmlDomAttrIface * iface,
                                              gpointer iface_data)
{
	gxml_xattribute_gxml_dom_attr_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_name = gxml_xattribute_real_get_name;
	iface->get_value = gxml_xattribute_real_get_value;
	iface->set_value = gxml_xattribute_real_set_value;
	iface->get_prefix = gxml_xattribute_real_get_prefix;
	iface->get_namespace_uri = gxml_xattribute_real_get_namespace_uri;
	iface->get_local_name = gxml_xattribute_real_get_local_name;
}

static void
gxml_xattribute_instance_init (GXmlXAttribute * self,
                               gpointer klass)
{
	self->priv = gxml_xattribute_get_instance_private (self);
}

static void
gxml_xattribute_finalize (GObject * obj)
{
	GXmlXAttribute * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GXML_TYPE_XATTRIBUTE, GXmlXAttribute);
	G_OBJECT_CLASS (gxml_xattribute_parent_class)->finalize (obj);
}

/**
 * Class implementing {@link GXml.DomAttr} interface, not tied to libxml-2.0 library.
 */
static GType
gxml_xattribute_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GXmlXAttributeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gxml_xattribute_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GXmlXAttribute), 0, (GInstanceInitFunc) gxml_xattribute_instance_init, NULL };
	static const GInterfaceInfo gxml_dom_attr_info = { (GInterfaceInitFunc) gxml_xattribute_gxml_dom_attr_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gxml_xattribute_type_id;
	gxml_xattribute_type_id = g_type_register_static (GXML_TYPE_XNODE, "GXmlXAttribute", &g_define_type_info, 0);
	g_type_add_interface_static (gxml_xattribute_type_id, GXML_TYPE_DOM_ATTR, &gxml_dom_attr_info);
	GXmlXAttribute_private_offset = g_type_add_instance_private (gxml_xattribute_type_id, sizeof (GXmlXAttributePrivate));
	return gxml_xattribute_type_id;
}

GType
gxml_xattribute_get_type (void)
{
	static volatile gsize gxml_xattribute_type_id__once = 0;
	if (g_once_init_enter (&gxml_xattribute_type_id__once)) {
		GType gxml_xattribute_type_id;
		gxml_xattribute_type_id = gxml_xattribute_get_type_once ();
		g_once_init_leave (&gxml_xattribute_type_id__once, gxml_xattribute_type_id);
	}
	return gxml_xattribute_type_id__once;
}

static void
_vala_gxml_xattribute_get_property (GObject * object,
                                    guint property_id,
                                    GValue * value,
                                    GParamSpec * pspec)
{
	GXmlXAttribute * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GXML_TYPE_XATTRIBUTE, GXmlXAttribute);
	switch (property_id) {
		case GXML_XATTRIBUTE_NAME_PROPERTY:
		g_value_take_string (value, gxml_xnode_get_name ((GXmlXNode*) self));
		break;
		case GXML_XATTRIBUTE_VALUE_PROPERTY:
		g_value_take_string (value, gxml_xnode_get_value ((GXmlXNode*) self));
		break;
		case GXML_XATTRIBUTE_PREFIX_PROPERTY:
		g_value_take_string (value, gxml_dom_attr_get_prefix ((GXmlDomAttr*) self));
		break;
		case GXML_XATTRIBUTE_PARENT_PROPERTY:
		g_value_take_object (value, gxml_xnode_get_parent ((GXmlXNode*) self));
		break;
		case GXML_XATTRIBUTE_NAMESPACE_URI_PROPERTY:
		g_value_take_string (value, gxml_dom_attr_get_namespace_uri ((GXmlDomAttr*) self));
		break;
		case GXML_XATTRIBUTE_LOCAL_NAME_PROPERTY:
		g_value_take_string (value, gxml_dom_attr_get_local_name ((GXmlDomAttr*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gxml_xattribute_set_property (GObject * object,
                                    guint property_id,
                                    const GValue * value,
                                    GParamSpec * pspec)
{
	GXmlXAttribute * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GXML_TYPE_XATTRIBUTE, GXmlXAttribute);
	switch (property_id) {
		case GXML_XATTRIBUTE_VALUE_PROPERTY:
		gxml_xnode_set_value ((GXmlXNode*) self, g_value_get_string (value));
		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;
}

