/* gcalc-expression-container.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from gcalc-expression-container.vala, do not modify */

/* gcalc-expression-container.vala
 *
 * Copyright (C) 2018  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 "gcalc/gcalc.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>
#include "gcalc.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  {
	GCALC_EXPRESSION_CONTAINER_0_PROPERTY,
	GCALC_EXPRESSION_CONTAINER_PARENT_PROPERTY,
	GCALC_EXPRESSION_CONTAINER_NUM_PROPERTIES
};
static GParamSpec* gcalc_expression_container_properties[GCALC_EXPRESSION_CONTAINER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GCalcExpressionContainerPrivate {
	GCalcMathExpression* _parent;
};

static gint GCalcExpressionContainer_private_offset;
static gpointer gcalc_expression_container_parent_class = NULL;
static GListModelInterface * gcalc_expression_container_g_list_model_parent_iface = NULL;

static gboolean gcalc_expression_container_real_add (GeeAbstractCollection* base,
                                              GCalcMathExpression* exp);
static GCalcMathExpression* gcalc_expression_container_real_remove_at (GeeAbstractList* base,
                                                                gint index);
static gboolean gcalc_expression_container_real_remove (GeeAbstractCollection* base,
                                                 GCalcMathExpression* exp);
static GObject* gcalc_expression_container_real_get_item (GListModel* base,
                                                   guint position);
static GType gcalc_expression_container_real_get_item_type (GListModel* base);
static guint gcalc_expression_container_real_get_n_items (GListModel* base);
static void gcalc_expression_container_finalize (GObject * obj);
static GType gcalc_expression_container_get_type_once (void);
static void _vala_gcalc_expression_container_get_property (GObject * object,
                                                    guint property_id,
                                                    GValue * value,
                                                    GParamSpec * pspec);
static void _vala_gcalc_expression_container_set_property (GObject * object,
                                                    guint property_id,
                                                    const GValue * value,
                                                    GParamSpec * pspec);

static inline gpointer
gcalc_expression_container_get_instance_private (GCalcExpressionContainer* self)
{
	return G_STRUCT_MEMBER_P (self, GCalcExpressionContainer_private_offset);
}

static gboolean
gcalc_expression_container_real_add (GeeAbstractCollection* base,
                                     GCalcMathExpression* exp)
{
	GCalcExpressionContainer * self;
	gboolean r = FALSE;
	GCalcMathExpression* _tmp0_;
	gboolean result;
	self = (GCalcExpressionContainer*) base;
	g_return_val_if_fail (exp != NULL, FALSE);
	r = GEE_ABSTRACT_COLLECTION_CLASS (gcalc_expression_container_parent_class)->add ((GeeAbstractCollection*) G_TYPE_CHECK_INSTANCE_CAST (self, GEE_TYPE_ARRAY_LIST, GeeArrayList), exp);
	_tmp0_ = self->priv->_parent;
	gcalc_math_expression_set_parent (exp, _tmp0_);
	result = r;
	return result;
}

static GCalcMathExpression*
gcalc_expression_container_real_remove_at (GeeAbstractList* base,
                                           gint index)
{
	GCalcExpressionContainer * self;
	GCalcMathExpression* r = NULL;
	gpointer _tmp0_;
	GCalcMathExpression* _tmp1_;
	GCalcMathExpression* result;
	self = (GCalcExpressionContainer*) base;
	_tmp0_ = GEE_ABSTRACT_LIST_CLASS (gcalc_expression_container_parent_class)->remove_at ((GeeAbstractList*) G_TYPE_CHECK_INSTANCE_CAST (self, GEE_TYPE_ARRAY_LIST, GeeArrayList), index);
	r = (GCalcMathExpression*) _tmp0_;
	_tmp1_ = r;
	if (_tmp1_ != NULL) {
		GCalcMathExpression* _tmp2_;
		_tmp2_ = r;
		gcalc_math_expression_set_parent (_tmp2_, NULL);
	}
	result = r;
	return result;
}

static gboolean
gcalc_expression_container_real_remove (GeeAbstractCollection* base,
                                        GCalcMathExpression* exp)
{
	GCalcExpressionContainer * self;
	gboolean r = FALSE;
	gboolean result;
	self = (GCalcExpressionContainer*) base;
	g_return_val_if_fail (exp != NULL, FALSE);
	r = GEE_ABSTRACT_COLLECTION_CLASS (gcalc_expression_container_parent_class)->remove ((GeeAbstractCollection*) G_TYPE_CHECK_INSTANCE_CAST (self, GEE_TYPE_ARRAY_LIST, GeeArrayList), exp);
	if (r) {
		gcalc_math_expression_set_parent (exp, NULL);
	}
	result = r;
	return result;
}

static GObject*
gcalc_expression_container_real_get_item (GListModel* base,
                                          guint position)
{
	GCalcExpressionContainer * self;
	gpointer _tmp0_;
	GCalcMathExpression* _tmp1_;
	GObject* _tmp2_;
	GObject* result;
	self = (GCalcExpressionContainer*) base;
	_tmp0_ = GEE_ABSTRACT_LIST_CLASS (gcalc_expression_container_parent_class)->get ((GeeAbstractList*) G_TYPE_CHECK_INSTANCE_CAST (self, GEE_TYPE_ARRAY_LIST, GeeArrayList), (gint) position);
	_tmp1_ = (GCalcMathExpression*) _tmp0_;
	_tmp2_ = G_TYPE_CHECK_INSTANCE_TYPE (_tmp1_, G_TYPE_OBJECT) ? ((GObject*) _tmp1_) : NULL;
	if (_tmp2_ == NULL) {
		_g_object_unref0 (_tmp1_);
	}
	result = _tmp2_;
	return result;
}

static GType
gcalc_expression_container_real_get_item_type (GListModel* base)
{
	GCalcExpressionContainer * self;
	GType result;
	self = (GCalcExpressionContainer*) base;
	result = GCALC_TYPE_MATH_EXPRESSION;
	return result;
}

static guint
gcalc_expression_container_real_get_n_items (GListModel* base)
{
	GCalcExpressionContainer * self;
	gint _tmp0_;
	gint _tmp1_;
	guint result;
	self = (GCalcExpressionContainer*) base;
	_tmp0_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) self);
	_tmp1_ = _tmp0_;
	result = (guint) _tmp1_;
	return result;
}

GObject*
gcalc_expression_container_get_object (GCalcExpressionContainer* self,
                                       guint position)
{
	GObject* _tmp0_;
	GObject* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_list_model_get_item ((GListModel*) self, position);
	result = _tmp0_;
	return result;
}

GCalcMathExpression*
gcalc_expression_container_find (GCalcExpressionContainer* self,
                                 GCalcMathExpression* exp)
{
	GCalcMathVariable* variable = NULL;
	GCalcMathVariable* _tmp0_;
	GCalcMathExpression* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (exp != NULL, NULL);
	variable = GCALC_IS_MATH_VARIABLE (exp) ? ((GCalcMathVariable*) exp) : NULL;
	_tmp0_ = variable;
	if (_tmp0_ == NULL) {
		result = NULL;
		return result;
	}
	{
		GCalcExpressionContainer* _e_list = NULL;
		gint _e_size = 0;
		GCalcExpressionContainer* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _e_index = 0;
		_e_list = self;
		_tmp1_ = _e_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_e_size = _tmp3_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			GCalcMathExpression* e = NULL;
			GCalcExpressionContainer* _tmp6_;
			gpointer _tmp7_;
			gboolean _tmp8_ = FALSE;
			GCalcMathExpression* _tmp9_;
			_e_index = _e_index + 1;
			_tmp4_ = _e_index;
			_tmp5_ = _e_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _e_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _e_index);
			e = (GCalcMathExpression*) _tmp7_;
			_tmp9_ = e;
			if (GCALC_IS_MATH_VARIABLE (_tmp9_)) {
				GCalcMathExpression* _tmp10_;
				const gchar* _tmp11_;
				const gchar* _tmp12_;
				GCalcMathVariable* _tmp13_;
				const gchar* _tmp14_;
				const gchar* _tmp15_;
				_tmp10_ = e;
				_tmp11_ = gcalc_math_variable_get_name (G_TYPE_CHECK_INSTANCE_CAST (_tmp10_, GCALC_TYPE_MATH_VARIABLE, GCalcMathVariable));
				_tmp12_ = _tmp11_;
				_tmp13_ = variable;
				_tmp14_ = gcalc_math_variable_get_name (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp8_ = g_strcmp0 (_tmp12_, _tmp15_) == 0;
			} else {
				_tmp8_ = FALSE;
			}
			if (_tmp8_) {
				result = e;
				return result;
			}
			_g_object_unref0 (e);
		}
	}
	result = NULL;
	return result;
}

GCalcMathExpression*
gcalc_expression_container_find_named (GCalcExpressionContainer* self,
                                       const gchar* name)
{
	GCalcMathExpression* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	{
		GCalcExpressionContainer* _e_list = NULL;
		gint _e_size = 0;
		GCalcExpressionContainer* _tmp0_;
		gint _tmp1_;
		gint _tmp2_;
		gint _e_index = 0;
		_e_list = self;
		_tmp0_ = _e_list;
		_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
		_tmp2_ = _tmp1_;
		_e_size = _tmp2_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp3_;
			gint _tmp4_;
			GCalcMathExpression* e = NULL;
			GCalcExpressionContainer* _tmp5_;
			gpointer _tmp6_;
			gboolean _tmp7_ = FALSE;
			GCalcMathExpression* _tmp8_;
			gboolean _tmp12_ = FALSE;
			GCalcMathExpression* _tmp13_;
			_e_index = _e_index + 1;
			_tmp3_ = _e_index;
			_tmp4_ = _e_size;
			if (!(_tmp3_ < _tmp4_)) {
				break;
			}
			_tmp5_ = _e_list;
			_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) _tmp5_, _e_index);
			e = (GCalcMathExpression*) _tmp6_;
			_tmp8_ = e;
			if (GCALC_IS_MATH_VARIABLE (_tmp8_)) {
				GCalcMathExpression* _tmp9_;
				const gchar* _tmp10_;
				const gchar* _tmp11_;
				_tmp9_ = e;
				_tmp10_ = gcalc_math_variable_get_name (G_TYPE_CHECK_INSTANCE_CAST (_tmp9_, GCALC_TYPE_MATH_VARIABLE, GCalcMathVariable));
				_tmp11_ = _tmp10_;
				_tmp7_ = g_strcmp0 (_tmp11_, name) == 0;
			} else {
				_tmp7_ = FALSE;
			}
			if (_tmp7_) {
				result = e;
				return result;
			}
			_tmp13_ = e;
			if (GCALC_IS_MATH_FUNCTION (_tmp13_)) {
				GCalcMathExpression* _tmp14_;
				const gchar* _tmp15_;
				const gchar* _tmp16_;
				_tmp14_ = e;
				_tmp15_ = gcalc_math_function_get_name (G_TYPE_CHECK_INSTANCE_CAST (_tmp14_, GCALC_TYPE_MATH_FUNCTION, GCalcMathFunction));
				_tmp16_ = _tmp15_;
				_tmp12_ = g_strcmp0 (_tmp16_, name) == 0;
			} else {
				_tmp12_ = FALSE;
			}
			if (_tmp12_) {
				result = e;
				return result;
			}
			_g_object_unref0 (e);
		}
	}
	result = NULL;
	return result;
}

GCalcExpressionContainer*
gcalc_expression_container_construct (GType object_type)
{
	GCalcExpressionContainer * self = NULL;
	self = (GCalcExpressionContainer*) gee_array_list_construct (object_type, GCALC_TYPE_MATH_EXPRESSION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	return self;
}

GCalcExpressionContainer*
gcalc_expression_container_new (void)
{
	return gcalc_expression_container_construct (GCALC_TYPE_EXPRESSION_CONTAINER);
}

GCalcMathExpression*
gcalc_expression_container_get_parent (GCalcExpressionContainer* self)
{
	GCalcMathExpression* result;
	GCalcMathExpression* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_parent;
	result = _tmp0_;
	return result;
}

void
gcalc_expression_container_set_parent (GCalcExpressionContainer* self,
                                       GCalcMathExpression* value)
{
	GCalcMathExpression* old_value;
	g_return_if_fail (self != NULL);
	old_value = gcalc_expression_container_get_parent (self);
	if (old_value != value) {
		self->priv->_parent = value;
		g_object_notify_by_pspec ((GObject *) self, gcalc_expression_container_properties[GCALC_EXPRESSION_CONTAINER_PARENT_PROPERTY]);
	}
}

static void
gcalc_expression_container_class_init (GCalcExpressionContainerClass * klass,
                                       gpointer klass_data)
{
	gcalc_expression_container_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GCalcExpressionContainer_private_offset);
	((GeeAbstractCollectionClass *) klass)->add = (gboolean (*) (GeeAbstractCollection*, gconstpointer)) gcalc_expression_container_real_add;
	((GeeAbstractListClass *) klass)->remove_at = (gpointer (*) (GeeAbstractList*, gint)) gcalc_expression_container_real_remove_at;
	((GeeAbstractCollectionClass *) klass)->remove = (gboolean (*) (GeeAbstractCollection*, gconstpointer)) gcalc_expression_container_real_remove;
	G_OBJECT_CLASS (klass)->get_property = _vala_gcalc_expression_container_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gcalc_expression_container_set_property;
	G_OBJECT_CLASS (klass)->finalize = gcalc_expression_container_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_EXPRESSION_CONTAINER_PARENT_PROPERTY, gcalc_expression_container_properties[GCALC_EXPRESSION_CONTAINER_PARENT_PROPERTY] = g_param_spec_object ("parent", "parent", "parent", GCALC_TYPE_MATH_EXPRESSION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gcalc_expression_container_g_list_model_interface_init (GListModelInterface * iface,
                                                        gpointer iface_data)
{
	gcalc_expression_container_g_list_model_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_item = (GObject* (*) (GListModel*, guint)) gcalc_expression_container_real_get_item;
	iface->get_item_type = (GType (*) (GListModel*)) gcalc_expression_container_real_get_item_type;
	iface->get_n_items = (guint (*) (GListModel*)) gcalc_expression_container_real_get_n_items;
}

static void
gcalc_expression_container_instance_init (GCalcExpressionContainer * self,
                                          gpointer klass)
{
	self->priv = gcalc_expression_container_get_instance_private (self);
}

static void
gcalc_expression_container_finalize (GObject * obj)
{
	GCalcExpressionContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_EXPRESSION_CONTAINER, GCalcExpressionContainer);
	G_OBJECT_CLASS (gcalc_expression_container_parent_class)->finalize (obj);
}

/**
 * An expression container implementing {@link GLib.ListModel}
 */
static GType
gcalc_expression_container_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcExpressionContainerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_expression_container_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcExpressionContainer), 0, (GInstanceInitFunc) gcalc_expression_container_instance_init, NULL };
	static const GInterfaceInfo g_list_model_info = { (GInterfaceInitFunc) gcalc_expression_container_g_list_model_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gcalc_expression_container_type_id;
	gcalc_expression_container_type_id = g_type_register_static (GEE_TYPE_ARRAY_LIST, "GCalcExpressionContainer", &g_define_type_info, 0);
	g_type_add_interface_static (gcalc_expression_container_type_id, g_list_model_get_type (), &g_list_model_info);
	GCalcExpressionContainer_private_offset = g_type_add_instance_private (gcalc_expression_container_type_id, sizeof (GCalcExpressionContainerPrivate));
	return gcalc_expression_container_type_id;
}

GType
gcalc_expression_container_get_type (void)
{
	static volatile gsize gcalc_expression_container_type_id__once = 0;
	if (g_once_init_enter (&gcalc_expression_container_type_id__once)) {
		GType gcalc_expression_container_type_id;
		gcalc_expression_container_type_id = gcalc_expression_container_get_type_once ();
		g_once_init_leave (&gcalc_expression_container_type_id__once, gcalc_expression_container_type_id);
	}
	return gcalc_expression_container_type_id__once;
}

static void
_vala_gcalc_expression_container_get_property (GObject * object,
                                               guint property_id,
                                               GValue * value,
                                               GParamSpec * pspec)
{
	GCalcExpressionContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_EXPRESSION_CONTAINER, GCalcExpressionContainer);
	switch (property_id) {
		case GCALC_EXPRESSION_CONTAINER_PARENT_PROPERTY:
		g_value_set_object (value, gcalc_expression_container_get_parent (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gcalc_expression_container_set_property (GObject * object,
                                               guint property_id,
                                               const GValue * value,
                                               GParamSpec * pspec)
{
	GCalcExpressionContainer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_EXPRESSION_CONTAINER, GCalcExpressionContainer);
	switch (property_id) {
		case GCALC_EXPRESSION_CONTAINER_PARENT_PROPERTY:
		gcalc_expression_container_set_parent (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

