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

/*
Copyright (C) 2016 Johan Mattsson

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 3 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.
*/

#include "xmlbird.h"
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.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  {
	B_XML_TREE_0_PROPERTY,
	B_XML_TREE_NUM_PROPERTIES
};
static GParamSpec* b_xml_tree_properties[B_XML_TREE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _BXmlTreePrivate {
	BXmlElement* root_element;
	gboolean valid;
};

static gint BXmlTree_private_offset;
static gpointer b_xml_tree_parent_class = NULL;

VALA_EXTERN void b_xml_parser_warning (const gchar* message);
VALA_EXTERN BXmlElement* b_xml_element_new (BXmlElement* parent,
                                BTag* tag);
VALA_EXTERN BXmlElement* b_xml_element_construct (GType object_type,
                                      BXmlElement* parent,
                                      BTag* tag);
static void b_xml_tree_finalize (GObject * obj);
static GType b_xml_tree_get_type_once (void);

static inline gpointer
b_xml_tree_get_instance_private (BXmlTree* self)
{
	return G_STRUCT_MEMBER_P (self, BXmlTree_private_offset);
}

BXmlTree*
b_xml_tree_construct (GType object_type,
                      const gchar* xml)
{
	BXmlTree * self = NULL;
	BXmlParser* parser = NULL;
	BXmlParser* _tmp0_;
	BXmlParser* _tmp1_;
	BXmlParser* _tmp2_;
	BTag* _tmp3_;
	BTag* _tmp4_;
	BXmlElement* _tmp5_;
	g_return_val_if_fail (xml != NULL, NULL);
	self = (BXmlTree*) g_object_new (object_type, NULL);
	_tmp0_ = b_xml_parser_new (xml);
	parser = _tmp0_;
	_tmp1_ = parser;
	if (!b_xml_parser_validate (_tmp1_)) {
		self->priv->valid = FALSE;
		b_xml_parser_warning ("Invalid XML.");
		_g_object_unref0 (parser);
		return self;
	}
	_tmp2_ = parser;
	_tmp3_ = b_xml_parser_get_root_tag (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = b_xml_element_new (NULL, _tmp4_);
	_g_object_unref0 (self->priv->root_element);
	self->priv->root_element = _tmp5_;
	_g_object_unref0 (_tmp4_);
	_g_object_unref0 (parser);
	return self;
}

BXmlTree*
b_xml_tree_new (const gchar* xml)
{
	return b_xml_tree_construct (B_TYPE_XML_TREE, xml);
}

BXmlTree*
b_xml_tree_construct_for_tag (GType object_type,
                              BTag* root)
{
	BXmlTree * self = NULL;
	BXmlElement* _tmp0_;
	g_return_val_if_fail (root != NULL, NULL);
	self = (BXmlTree*) g_object_new (object_type, NULL);
	_tmp0_ = b_xml_element_new (NULL, root);
	_g_object_unref0 (self->priv->root_element);
	self->priv->root_element = _tmp0_;
	return self;
}

BXmlTree*
b_xml_tree_new_for_tag (BTag* root)
{
	return b_xml_tree_construct_for_tag (B_TYPE_XML_TREE, root);
}

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

BXmlElement*
b_xml_tree_get_root (BXmlTree* self)
{
	BXmlElement* _tmp0_;
	BXmlElement* _tmp1_;
	BXmlElement* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->root_element;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

gboolean
b_xml_tree_validate (BXmlTree* self)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = self->priv->valid;
	return result;
}

static void
b_xml_tree_class_init (BXmlTreeClass * klass,
                       gpointer klass_data)
{
	b_xml_tree_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BXmlTree_private_offset);
	G_OBJECT_CLASS (klass)->finalize = b_xml_tree_finalize;
}

static void
b_xml_tree_instance_init (BXmlTree * self,
                          gpointer klass)
{
	BXmlElement* _tmp0_;
	self->priv = b_xml_tree_get_instance_private (self);
	_tmp0_ = b_xml_element_new_empty ();
	self->priv->root_element = _tmp0_;
	self->priv->valid = TRUE;
}

static void
b_xml_tree_finalize (GObject * obj)
{
	BXmlTree * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, B_TYPE_XML_TREE, BXmlTree);
	_g_object_unref0 (self->priv->root_element);
	G_OBJECT_CLASS (b_xml_tree_parent_class)->finalize (obj);
}

/**
 * A representation of a XML tree.
 * 
 * All XML elements are owned by the tree and will be deleted when the 
 * tree is deleted.
 */
static GType
b_xml_tree_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BXmlTreeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) b_xml_tree_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BXmlTree), 0, (GInstanceInitFunc) b_xml_tree_instance_init, NULL };
	GType b_xml_tree_type_id;
	b_xml_tree_type_id = g_type_register_static (G_TYPE_OBJECT, "BXmlTree", &g_define_type_info, 0);
	BXmlTree_private_offset = g_type_add_instance_private (b_xml_tree_type_id, sizeof (BXmlTreePrivate));
	return b_xml_tree_type_id;
}

GType
b_xml_tree_get_type (void)
{
	static volatile gsize b_xml_tree_type_id__once = 0;
	if (g_once_init_enter (&b_xml_tree_type_id__once)) {
		GType b_xml_tree_type_id;
		b_xml_tree_type_id = b_xml_tree_get_type_once ();
		g_once_init_leave (&b_xml_tree_type_id__once, b_xml_tree_type_id);
	}
	return b_xml_tree_type_id__once;
}

