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

/*
    Copyright (C) 2014 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-object.h>
#include <glib.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

#define B_TYPE_ELEMENTS (b_elements_get_type ())
#define B_ELEMENTS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), B_TYPE_ELEMENTS, BElements))
#define B_ELEMENTS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), B_TYPE_ELEMENTS, BElementsClass))
#define B_IS_ELEMENTS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), B_TYPE_ELEMENTS))
#define B_IS_ELEMENTS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), B_TYPE_ELEMENTS))
#define B_ELEMENTS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), B_TYPE_ELEMENTS, BElementsClass))

typedef struct _BElements BElements;
typedef struct _BElementsClass BElementsClass;
enum  {
	B_ATTRIBUTES_0_PROPERTY,
	B_ATTRIBUTES_NUM_PROPERTIES
};
static GParamSpec* b_attributes_properties[B_ATTRIBUTES_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	B_ATTRIBUTES_ITERATOR_0_PROPERTY,
	B_ATTRIBUTES_ITERATOR_NUM_PROPERTIES
};
static GParamSpec* b_attributes_iterator_properties[B_ATTRIBUTES_ITERATOR_NUM_PROPERTIES];
typedef struct _BElementsPrivate BElementsPrivate;

struct _BAttributesPrivate {
	BTag* tag;
	BElements* elements;
};

struct _BAttributesIteratorPrivate {
	BTag* tag;
	BAttribute* next_attribute;
	BElements* elements;
	gint index;
};

struct _BElements {
	GObject parent_instance;
	BElementsPrivate * priv;
	gint size;
};

struct _BElementsClass {
	GObjectClass parent_class;
};

static gint BAttributes_private_offset;
static gpointer b_attributes_parent_class = NULL;
static gint BAttributesIterator_private_offset;
static gpointer b_attributes_iterator_parent_class = NULL;

VALA_EXTERN GType b_elements_get_type (void) G_GNUC_CONST ;
VALA_EXTERN BAttributes* b_attributes_new (BTag* t);
VALA_EXTERN BAttributes* b_attributes_construct (GType object_type,
                                     BTag* t);
VALA_EXTERN BAttributes* b_attributes_new_for_element (BElements* elements);
VALA_EXTERN BAttributes* b_attributes_construct_for_element (GType object_type,
                                                 BElements* elements);
VALA_EXTERN BAttributesIterator* b_attributes_iterator_new (BTag* t);
VALA_EXTERN BAttributesIterator* b_attributes_iterator_construct (GType object_type,
                                                      BTag* t);
VALA_EXTERN BAttributesIterator* b_attributes_iterator_new_for_elements (BElements* elements);
VALA_EXTERN BAttributesIterator* b_attributes_iterator_construct_for_elements (GType object_type,
                                                                   BElements* elements);
VALA_EXTERN BElements* b_elements_new (void);
VALA_EXTERN BElements* b_elements_construct (GType object_type);
VALA_EXTERN void b_tag_reparse_attributes (BTag* self);
VALA_EXTERN gboolean b_attributes_iterator_next_tag (BAttributesIterator* self,
                                         BTag* tag);
VALA_EXTERN gboolean b_attributes_iterator_next_element (BAttributesIterator* self,
                                             BElements* elements);
VALA_EXTERN gboolean b_tag_has_more_attributes (BTag* self);
VALA_EXTERN BAttribute* b_tag_get_next_attribute (BTag* self);
VALA_EXTERN BXmlElement* b_elements_get_element (BElements* self,
                                     gint index);
VALA_EXTERN BAttribute* b_attribute_new_element (BXmlElement* element);
VALA_EXTERN BAttribute* b_attribute_construct_element (GType object_type,
                                           BXmlElement* element);
VALA_EXTERN void b_xml_parser_warning (const gchar* message);
VALA_EXTERN BAttribute* b_attribute_new_empty (void);
VALA_EXTERN BAttribute* b_attribute_construct_empty (GType object_type);
static void b_attributes_iterator_finalize (GObject * obj);
static GType b_attributes_iterator_get_type_once (void);
static void b_attributes_finalize (GObject * obj);
static GType b_attributes_get_type_once (void);

static inline gpointer
b_attributes_get_instance_private (BAttributes* self)
{
	return G_STRUCT_MEMBER_P (self, BAttributes_private_offset);
}

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

BAttributes*
b_attributes_construct (GType object_type,
                        BTag* t)
{
	BAttributes * self = NULL;
	BTag* _tmp0_;
	g_return_val_if_fail (t != NULL, NULL);
	self = (BAttributes*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (t);
	_g_object_unref0 (self->priv->tag);
	self->priv->tag = _tmp0_;
	return self;
}

BAttributes*
b_attributes_new (BTag* t)
{
	return b_attributes_construct (B_TYPE_ATTRIBUTES, t);
}

BAttributes*
b_attributes_construct_for_element (GType object_type,
                                    BElements* elements)
{
	BAttributes * self = NULL;
	BElements* _tmp0_;
	g_return_val_if_fail (elements != NULL, NULL);
	self = (BAttributes*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (elements);
	_g_object_unref0 (self->priv->elements);
	self->priv->elements = _tmp0_;
	return self;
}

BAttributes*
b_attributes_new_for_element (BElements* elements)
{
	return b_attributes_construct_for_element (B_TYPE_ATTRIBUTES, elements);
}

BAttributesIterator*
b_attributes_iterator (BAttributes* self)
{
	BTag* _tmp0_;
	BElements* _tmp3_;
	BElements* _tmp6_;
	BElements* _tmp7_;
	BAttributesIterator* _tmp8_;
	BAttributesIterator* _tmp9_;
	BAttributesIterator* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->tag;
	if (_tmp0_ != NULL) {
		BTag* _tmp1_;
		BAttributesIterator* _tmp2_;
		_tmp1_ = self->priv->tag;
		_tmp2_ = b_attributes_iterator_new (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, B_TYPE_TAG, BTag));
		result = _tmp2_;
		return result;
	}
	_tmp3_ = self->priv->elements;
	if (_tmp3_ != NULL) {
		BElements* _tmp4_;
		BAttributesIterator* _tmp5_;
		_tmp4_ = self->priv->elements;
		_tmp5_ = b_attributes_iterator_new_for_elements (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, B_TYPE_ELEMENTS, BElements));
		result = _tmp5_;
		return result;
	}
	_tmp6_ = b_elements_new ();
	_tmp7_ = _tmp6_;
	_tmp8_ = b_attributes_iterator_new_for_elements (_tmp7_);
	_tmp9_ = _tmp8_;
	_g_object_unref0 (_tmp7_);
	result = _tmp9_;
	return result;
}

static inline gpointer
b_attributes_iterator_get_instance_private (BAttributesIterator* self)
{
	return G_STRUCT_MEMBER_P (self, BAttributesIterator_private_offset);
}

BAttributesIterator*
b_attributes_iterator_construct (GType object_type,
                                 BTag* t)
{
	BAttributesIterator * self = NULL;
	BTag* _tmp0_;
	g_return_val_if_fail (t != NULL, NULL);
	self = (BAttributesIterator*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (t);
	_g_object_unref0 (self->priv->tag);
	self->priv->tag = _tmp0_;
	b_tag_reparse_attributes (t);
	return self;
}

BAttributesIterator*
b_attributes_iterator_new (BTag* t)
{
	return b_attributes_iterator_construct (B_ATTRIBUTES_TYPE_ITERATOR, t);
}

BAttributesIterator*
b_attributes_iterator_construct_for_elements (GType object_type,
                                              BElements* elements)
{
	BAttributesIterator * self = NULL;
	BElements* _tmp0_;
	g_return_val_if_fail (elements != NULL, NULL);
	self = (BAttributesIterator*) g_object_new (object_type, NULL);
	_tmp0_ = _g_object_ref0 (elements);
	_g_object_unref0 (self->priv->elements);
	self->priv->elements = _tmp0_;
	return self;
}

BAttributesIterator*
b_attributes_iterator_new_for_elements (BElements* elements)
{
	return b_attributes_iterator_construct_for_elements (B_ATTRIBUTES_TYPE_ITERATOR, elements);
}

gboolean
b_attributes_iterator_next (BAttributesIterator* self)
{
	BTag* _tmp0_;
	BElements* _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->tag;
	if (_tmp0_ != NULL) {
		BTag* _tmp1_;
		_tmp1_ = self->priv->tag;
		result = b_attributes_iterator_next_tag (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, B_TYPE_TAG, BTag));
		return result;
	}
	_tmp2_ = self->priv->elements;
	if (_tmp2_ != NULL) {
		BElements* _tmp3_;
		_tmp3_ = self->priv->elements;
		result = b_attributes_iterator_next_element (self, G_TYPE_CHECK_INSTANCE_CAST (_tmp3_, B_TYPE_ELEMENTS, BElements));
		return result;
	}
	result = FALSE;
	return result;
}

gboolean
b_attributes_iterator_next_tag (BAttributesIterator* self,
                                BTag* tag)
{
	BAttribute* _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (tag != NULL, FALSE);
	if (b_tag_has_more_attributes (tag)) {
		BAttribute* _tmp0_;
		_tmp0_ = b_tag_get_next_attribute (tag);
		_g_object_unref0 (self->priv->next_attribute);
		self->priv->next_attribute = _tmp0_;
	} else {
		_g_object_unref0 (self->priv->next_attribute);
		self->priv->next_attribute = NULL;
	}
	_tmp1_ = self->priv->next_attribute;
	result = _tmp1_ != NULL;
	return result;
}

gboolean
b_attributes_iterator_next_element (BAttributesIterator* self,
                                    BElements* elements)
{
	BAttribute* _tmp4_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (elements != NULL, FALSE);
	if (self->priv->index < elements->size) {
		BXmlElement* e = NULL;
		BXmlElement* _tmp0_;
		BXmlElement* _tmp1_;
		BAttribute* _tmp2_;
		gint _tmp3_;
		_tmp0_ = b_elements_get_element (elements, self->priv->index);
		e = _tmp0_;
		_tmp1_ = e;
		_tmp2_ = b_attribute_new_element (_tmp1_);
		_g_object_unref0 (self->priv->next_attribute);
		self->priv->next_attribute = _tmp2_;
		_tmp3_ = self->priv->index;
		self->priv->index = _tmp3_ + 1;
		_g_object_unref0 (e);
	} else {
		_g_object_unref0 (self->priv->next_attribute);
		self->priv->next_attribute = NULL;
	}
	_tmp4_ = self->priv->next_attribute;
	result = _tmp4_ != NULL;
	return result;
}

BAttribute*
b_attributes_iterator_get (BAttributesIterator* self)
{
	BAttribute* _tmp0_;
	BAttribute* _tmp2_;
	BAttribute* _tmp3_;
	BAttribute* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->next_attribute;
	if (_tmp0_ == NULL) {
		BAttribute* _tmp1_;
		b_xml_parser_warning ("No attribute available.");
		_tmp1_ = b_attribute_new_empty ();
		result = _tmp1_;
		return result;
	}
	_tmp2_ = self->priv->next_attribute;
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, B_TYPE_ATTRIBUTE, BAttribute));
	result = _tmp3_;
	return result;
}

static void
b_attributes_iterator_class_init (BAttributesIteratorClass * klass,
                                  gpointer klass_data)
{
	b_attributes_iterator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BAttributesIterator_private_offset);
	G_OBJECT_CLASS (klass)->finalize = b_attributes_iterator_finalize;
}

static void
b_attributes_iterator_instance_init (BAttributesIterator * self,
                                     gpointer klass)
{
	self->priv = b_attributes_iterator_get_instance_private (self);
	self->priv->tag = NULL;
	self->priv->next_attribute = NULL;
	self->priv->elements = NULL;
	self->priv->index = 0;
}

static void
b_attributes_iterator_finalize (GObject * obj)
{
	BAttributesIterator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, B_ATTRIBUTES_TYPE_ITERATOR, BAttributesIterator);
	_g_object_unref0 (self->priv->tag);
	_g_object_unref0 (self->priv->next_attribute);
	_g_object_unref0 (self->priv->elements);
	G_OBJECT_CLASS (b_attributes_iterator_parent_class)->finalize (obj);
}

static GType
b_attributes_iterator_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BAttributesIteratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) b_attributes_iterator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BAttributesIterator), 0, (GInstanceInitFunc) b_attributes_iterator_instance_init, NULL };
	GType b_attributes_iterator_type_id;
	b_attributes_iterator_type_id = g_type_register_static (G_TYPE_OBJECT, "BAttributesIterator", &g_define_type_info, 0);
	BAttributesIterator_private_offset = g_type_add_instance_private (b_attributes_iterator_type_id, sizeof (BAttributesIteratorPrivate));
	return b_attributes_iterator_type_id;
}

GType
b_attributes_iterator_get_type (void)
{
	static volatile gsize b_attributes_iterator_type_id__once = 0;
	if (g_once_init_enter (&b_attributes_iterator_type_id__once)) {
		GType b_attributes_iterator_type_id;
		b_attributes_iterator_type_id = b_attributes_iterator_get_type_once ();
		g_once_init_leave (&b_attributes_iterator_type_id__once, b_attributes_iterator_type_id);
	}
	return b_attributes_iterator_type_id__once;
}

static void
b_attributes_class_init (BAttributesClass * klass,
                         gpointer klass_data)
{
	b_attributes_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BAttributes_private_offset);
	G_OBJECT_CLASS (klass)->finalize = b_attributes_finalize;
}

static void
b_attributes_instance_init (BAttributes * self,
                            gpointer klass)
{
	self->priv = b_attributes_get_instance_private (self);
	self->priv->tag = NULL;
	self->priv->elements = NULL;
}

static void
b_attributes_finalize (GObject * obj)
{
	BAttributes * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, B_TYPE_ATTRIBUTES, BAttributes);
	_g_object_unref0 (self->priv->tag);
	_g_object_unref0 (self->priv->elements);
	G_OBJECT_CLASS (b_attributes_parent_class)->finalize (obj);
}

/** 
 * Iterator for XML attributes. 
 */
static GType
b_attributes_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BAttributesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) b_attributes_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BAttributes), 0, (GInstanceInitFunc) b_attributes_instance_init, NULL };
	GType b_attributes_type_id;
	b_attributes_type_id = g_type_register_static (G_TYPE_OBJECT, "BAttributes", &g_define_type_info, 0);
	BAttributes_private_offset = g_type_add_instance_private (b_attributes_type_id, sizeof (BAttributesPrivate));
	return b_attributes_type_id;
}

GType
b_attributes_get_type (void)
{
	static volatile gsize b_attributes_type_id__once = 0;
	if (g_once_init_enter (&b_attributes_type_id__once)) {
		GType b_attributes_type_id;
		b_attributes_type_id = b_attributes_get_type_once ();
		g_once_init_leave (&b_attributes_type_id__once, b_attributes_type_id);
	}
	return b_attributes_type_id__once;
}

