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

/*
Copyright (C) 2016 2023 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 <glib-object.h>
#include <glib.h>
#include "xmlbird.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;
typedef struct _BElementsPrivate BElementsPrivate;
enum  {
	B_ELEMENTS_0_PROPERTY,
	B_ELEMENTS_NUM_PROPERTIES
};
static GParamSpec* b_elements_properties[B_ELEMENTS_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))

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

struct _BElementsClass {
	GObjectClass parent_class;
};

struct _BElementsPrivate {
	BXmlElement** data;
	gint capacity;
};

static gint BElements_private_offset;
static gpointer b_elements_parent_class = NULL;

VALA_EXTERN GType b_elements_get_type (void) G_GNUC_CONST ;
VALA_EXTERN BElements* b_elements_new (void);
VALA_EXTERN BElements* b_elements_construct (GType object_type);
VALA_EXTERN BXmlElement* b_elements_get_element (BElements* self,
                                     gint index);
VALA_EXTERN void b_xml_parser_warning (const gchar* message);
VALA_EXTERN void b_elements_add (BElements* self,
                     BXmlElement* element);
static void b_elements_finalize (GObject * obj);
static GType b_elements_get_type_once (void);

static inline gpointer
b_elements_get_instance_private (BElements* self)
{
	return G_STRUCT_MEMBER_P (self, BElements_private_offset);
}

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

BElements*
b_elements_construct (GType object_type)
{
	BElements * self = NULL;
	BXmlElement** _tmp0_;
	self = (BElements*) g_object_new (object_type, NULL);
	_tmp0_ = g_new0 (BXmlElement*, self->priv->capacity);
	self->priv->data = _tmp0_;
	return self;
}

BElements*
b_elements_new (void)
{
	return b_elements_construct (B_TYPE_ELEMENTS);
}

BXmlElement*
b_elements_get_element (BElements* self,
                        gint index)
{
	gboolean _tmp0_ = FALSE;
	BXmlElement** _tmp2_;
	BXmlElement* _tmp3_;
	BXmlElement* _tmp4_;
	BXmlElement* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (index < 0) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = index >= self->size;
	}
	if (G_UNLIKELY (_tmp0_)) {
		BXmlElement* _tmp1_;
		b_xml_parser_warning ("Index out of bounds in Elements.");
		_tmp1_ = b_xml_element_new_empty ();
		result = _tmp1_;
		return result;
	}
	_tmp2_ = self->priv->data;
	_tmp3_ = _tmp2_[index];
	_tmp4_ = _g_object_ref0 (_tmp3_);
	result = _tmp4_;
	return result;
}

void
b_elements_add (BElements* self,
                BXmlElement* element)
{
	BXmlElement** _tmp5_;
	gint _tmp6_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (element != NULL);
	if (self->size >= self->priv->capacity) {
		gint new_capacity = 0;
		BXmlElement** new_data = NULL;
		BXmlElement** _tmp0_;
		BXmlElement** _tmp1_;
		BXmlElement** _tmp2_;
		BXmlElement** _tmp3_;
		BXmlElement** _tmp4_;
		new_capacity = 2 * self->priv->capacity;
		_tmp0_ = g_new0 (BXmlElement*, new_capacity);
		new_data = _tmp0_;
		_tmp1_ = new_data;
		_tmp2_ = self->priv->data;
		memcpy (_tmp1_, _tmp2_, (gsize) (sizeof (BXmlElement*) * self->size));
		_tmp3_ = self->priv->data;
		_g_free0 (_tmp3_);
		_tmp4_ = new_data;
		self->priv->data = _tmp4_;
		self->priv->capacity = new_capacity;
	}
	_tmp5_ = self->priv->data;
	_tmp5_[self->size] = element;
	g_object_ref ((GObject*) element);
	_tmp6_ = self->size;
	self->size = _tmp6_ + 1;
}

static void
b_elements_class_init (BElementsClass * klass,
                       gpointer klass_data)
{
	b_elements_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BElements_private_offset);
	G_OBJECT_CLASS (klass)->finalize = b_elements_finalize;
}

static void
b_elements_instance_init (BElements * self,
                          gpointer klass)
{
	self->priv = b_elements_get_instance_private (self);
	self->size = 0;
	self->priv->capacity = 10;
}

static void
b_elements_finalize (GObject * obj)
{
	BElements * self;
	BXmlElement** _tmp6_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, B_TYPE_ELEMENTS, BElements);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				BXmlElement* e = NULL;
				BXmlElement** _tmp2_;
				BXmlElement* _tmp3_;
				BXmlElement* _tmp4_;
				BXmlElement* _tmp5_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				if (!(i < self->size)) {
					break;
				}
				_tmp2_ = self->priv->data;
				_tmp3_ = _tmp2_[i];
				_tmp4_ = _g_object_ref0 (_tmp3_);
				e = _tmp4_;
				_tmp5_ = e;
				g_object_unref ((GObject*) _tmp5_);
				_g_object_unref0 (e);
			}
		}
	}
	_tmp6_ = self->priv->data;
	_g_free0 (_tmp6_);
	self->priv->data = NULL;
	G_OBJECT_CLASS (b_elements_parent_class)->finalize (obj);
}

static GType
b_elements_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BElementsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) b_elements_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BElements), 0, (GInstanceInitFunc) b_elements_instance_init, NULL };
	GType b_elements_type_id;
	b_elements_type_id = g_type_register_static (G_TYPE_OBJECT, "BElements", &g_define_type_info, 0);
	BElements_private_offset = g_type_add_instance_private (b_elements_type_id, sizeof (BElementsPrivate));
	return b_elements_type_id;
}

GType
b_elements_get_type (void)
{
	static volatile gsize b_elements_type_id__once = 0;
	if (g_once_init_enter (&b_elements_type_id__once)) {
		GType b_elements_type_id;
		b_elements_type_id = b_elements_get_type_once ();
		g_once_init_leave (&b_elements_type_id__once, b_elements_type_id);
	}
	return b_elements_type_id__once;
}

