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

/* gcalc-function.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 <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include <gio/gio.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_FUNCTION_0_PROPERTY,
	GCALC_FUNCTION_PARAM_TYPES_PROPERTY,
	GCALC_FUNCTION_N_PARAMS_PROPERTY,
	GCALC_FUNCTION_NAME_PROPERTY,
	GCALC_FUNCTION_CLOSED_PROPERTY,
	GCALC_FUNCTION_NUM_PROPERTIES
};
static GParamSpec* gcalc_function_properties[GCALC_FUNCTION_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 _GCalcFunctionPrivate {
	GCalcExpressionContainer* _param_types;
	guint _n_params;
	gchar* _name;
	gboolean _closed;
};

static gint GCalcFunction_private_offset;
static gpointer gcalc_function_parent_class = NULL;
static GCalcMathFunctionIface * gcalc_function_gcalc_math_function_parent_iface = NULL;
static GCalcHashableIface * gcalc_function_gcalc_hashable_parent_iface = NULL;

VALA_EXTERN gchar* gcalc_expression_to_string (GCalcExpression* self);
VALA_EXTERN GCalcMathExpression* gcalc_function_evaluate (GCalcFunction* self,
                                              GError** error);
static gchar* gcalc_function_real_to_string (GCalcExpression* base);
static GCalcMathExpression* gcalc_function_real_evaluate (GCalcFunction* self,
                                                   GError** error);
static guint gcalc_function_real_hash (GCalcHashable* base);
static GObject * gcalc_function_constructor (GType type,
                                      guint n_construct_properties,
                                      GObjectConstructParam * construct_properties);
static void gcalc_function_finalize (GObject * obj);
static GType gcalc_function_get_type_once (void);
static void _vala_gcalc_function_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec);
static void _vala_gcalc_function_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec);

static inline gpointer
gcalc_function_get_instance_private (GCalcFunction* self)
{
	return G_STRUCT_MEMBER_P (self, GCalcFunction_private_offset);
}

GCalcFunction*
gcalc_function_construct_with_name (GType object_type,
                                    const gchar* name,
                                    gint nparams)
{
	GCalcFunction * self = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	self = (GCalcFunction*) gcalc_expression_construct (object_type);
	gcalc_math_function_set_name ((GCalcMathFunction*) self, name);
	gcalc_math_function_set_n_params ((GCalcMathFunction*) self, (guint) nparams);
	return self;
}

GCalcFunction*
gcalc_function_new_with_name (const gchar* name,
                              gint nparams)
{
	return gcalc_function_construct_with_name (GCALC_TYPE_FUNCTION, name, nparams);
}

static gchar*
gcalc_function_real_to_string (GCalcExpression* base)
{
	GCalcFunction * self;
	gchar* s = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	const gchar* _tmp21_;
	gchar* _tmp22_;
	gchar* result;
	self = (GCalcFunction*) base;
	_tmp0_ = gcalc_math_function_get_name ((GCalcMathFunction*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strconcat (_tmp1_, "(", NULL);
	s = _tmp2_;
	{
		guint i = 0U;
		i = (guint) 0;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				GCalcExpressionContainer* _tmp5_;
				GCalcExpressionContainer* _tmp6_;
				GCalcMathExpression* e = NULL;
				GCalcExpressionContainer* _tmp7_;
				GCalcExpressionContainer* _tmp8_;
				GObject* _tmp9_;
				GCalcMathExpression* _tmp10_;
				GCalcMathExpression* _tmp11_;
				const gchar* _tmp12_;
				GCalcMathExpression* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				gchar* _tmp16_;
				GCalcExpressionContainer* _tmp17_;
				GCalcExpressionContainer* _tmp18_;
				if (!_tmp3_) {
					guint _tmp4_;
					_tmp4_ = i;
					i = _tmp4_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp5_ = gcalc_math_expression_get_expressions ((GCalcMathExpression*) self);
				_tmp6_ = _tmp5_;
				if (!(i < g_list_model_get_n_items ((GListModel*) _tmp6_))) {
					break;
				}
				_tmp7_ = gcalc_math_expression_get_expressions ((GCalcMathExpression*) self);
				_tmp8_ = _tmp7_;
				_tmp9_ = g_list_model_get_item ((GListModel*) _tmp8_, i);
				_tmp10_ = GCALC_IS_MATH_EXPRESSION (_tmp9_) ? ((GCalcMathExpression*) _tmp9_) : NULL;
				if (_tmp10_ == NULL) {
					_g_object_unref0 (_tmp9_);
				}
				e = _tmp10_;
				_tmp11_ = e;
				if (_tmp11_ == NULL) {
					_g_object_unref0 (e);
					continue;
				}
				_tmp12_ = s;
				_tmp13_ = e;
				_tmp14_ = gcalc_math_expression_to_string (_tmp13_);
				_tmp15_ = _tmp14_;
				_tmp16_ = g_strconcat (_tmp12_, _tmp15_, NULL);
				_g_free0 (s);
				s = _tmp16_;
				_g_free0 (_tmp15_);
				_tmp17_ = gcalc_math_expression_get_expressions ((GCalcMathExpression*) self);
				_tmp18_ = _tmp17_;
				if ((i + 1) < g_list_model_get_n_items ((GListModel*) _tmp18_)) {
					const gchar* _tmp19_;
					gchar* _tmp20_;
					_tmp19_ = s;
					_tmp20_ = g_strconcat (_tmp19_, ",", NULL);
					_g_free0 (s);
					s = _tmp20_;
				}
				_g_object_unref0 (e);
			}
		}
	}
	_tmp21_ = s;
	_tmp22_ = g_strconcat (_tmp21_, ")", NULL);
	_g_free0 (s);
	s = _tmp22_;
	result = s;
	return result;
}

static GCalcMathExpression*
gcalc_function_real_evaluate (GCalcFunction* self,
                              GError** error)
{
	GCalcErrorExpression* _tmp0_;
	GCalcMathExpression* result;
	_tmp0_ = gcalc_error_expression_new ();
	result = (GCalcMathExpression*) _tmp0_;
	return result;
}

GCalcMathExpression*
gcalc_function_evaluate (GCalcFunction* self,
                         GError** error)
{
	GCalcFunctionClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = GCALC_FUNCTION_GET_CLASS (self);
	if (_klass_->evaluate) {
		return _klass_->evaluate (self, error);
	}
	return NULL;
}

static guint
gcalc_function_real_hash (GCalcHashable* base)
{
	GCalcFunction * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	guint result;
	self = (GCalcFunction*) base;
	_tmp0_ = gcalc_math_function_get_name ((GCalcMathFunction*) self);
	_tmp1_ = _tmp0_;
	result = g_str_hash (_tmp1_);
	return result;
}

GCalcFunction*
gcalc_function_construct (GType object_type)
{
	GCalcFunction * self = NULL;
	self = (GCalcFunction*) gcalc_expression_construct (object_type);
	return self;
}

GCalcFunction*
gcalc_function_new (void)
{
	return gcalc_function_construct (GCALC_TYPE_FUNCTION);
}

static GCalcExpressionContainer*
gcalc_function_real_get_param_types (GCalcMathFunction* base)
{
	GCalcExpressionContainer* result;
	GCalcFunction* self;
	GCalcExpressionContainer* _tmp0_;
	self = (GCalcFunction*) base;
	_tmp0_ = self->priv->_param_types;
	result = _tmp0_;
	return result;
}

static guint
gcalc_function_real_get_n_params (GCalcMathFunction* base)
{
	guint result;
	GCalcFunction* self;
	self = (GCalcFunction*) base;
	result = self->priv->_n_params;
	return result;
}

static void
gcalc_function_real_set_n_params (GCalcMathFunction* base,
                                  guint value)
{
	GCalcFunction* self;
	guint old_value;
	self = (GCalcFunction*) base;
	old_value = gcalc_function_real_get_n_params (base);
	if (old_value != value) {
		self->priv->_n_params = value;
		g_object_notify_by_pspec ((GObject *) self, gcalc_function_properties[GCALC_FUNCTION_N_PARAMS_PROPERTY]);
	}
}

static const gchar*
gcalc_function_real_get_name (GCalcMathFunction* base)
{
	const gchar* result;
	GCalcFunction* self;
	const gchar* _tmp0_;
	self = (GCalcFunction*) base;
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}

static void
gcalc_function_real_set_name (GCalcMathFunction* base,
                              const gchar* value)
{
	GCalcFunction* self;
	gchar* old_value;
	self = (GCalcFunction*) base;
	old_value = gcalc_function_real_get_name (base);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_name);
		self->priv->_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gcalc_function_properties[GCALC_FUNCTION_NAME_PROPERTY]);
	}
}

static gboolean
gcalc_function_real_get_closed (GCalcMathFunction* base)
{
	gboolean result;
	GCalcFunction* self;
	self = (GCalcFunction*) base;
	result = self->priv->_closed;
	return result;
}

static void
gcalc_function_real_set_closed (GCalcMathFunction* base,
                                gboolean value)
{
	GCalcFunction* self;
	gboolean old_value;
	self = (GCalcFunction*) base;
	old_value = gcalc_function_real_get_closed (base);
	if (old_value != value) {
		self->priv->_closed = value;
		g_object_notify_by_pspec ((GObject *) self, gcalc_function_properties[GCALC_FUNCTION_CLOSED_PROPERTY]);
	}
}

static GObject *
gcalc_function_constructor (GType type,
                            guint n_construct_properties,
                            GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GCalcFunction * self;
	parent_class = G_OBJECT_CLASS (gcalc_function_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_FUNCTION, GCalcFunction);
	gcalc_math_function_set_name ((GCalcMathFunction*) self, "NoName");
	return obj;
}

static void
gcalc_function_class_init (GCalcFunctionClass * klass,
                           gpointer klass_data)
{
	gcalc_function_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GCalcFunction_private_offset);
	((GCalcExpressionClass *) klass)->to_string = (gchar* (*) (GCalcExpression*)) gcalc_function_real_to_string;
	((GCalcFunctionClass *) klass)->evaluate = (GCalcMathExpression* (*) (GCalcFunction*, GError**)) gcalc_function_real_evaluate;
	G_OBJECT_CLASS (klass)->get_property = _vala_gcalc_function_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gcalc_function_set_property;
	G_OBJECT_CLASS (klass)->constructor = gcalc_function_constructor;
	G_OBJECT_CLASS (klass)->finalize = gcalc_function_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_FUNCTION_PARAM_TYPES_PROPERTY, gcalc_function_properties[GCALC_FUNCTION_PARAM_TYPES_PROPERTY] = g_param_spec_object ("param-types", "param-types", "param-types", GCALC_TYPE_EXPRESSION_CONTAINER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_FUNCTION_N_PARAMS_PROPERTY, gcalc_function_properties[GCALC_FUNCTION_N_PARAMS_PROPERTY] = g_param_spec_uint ("n-params", "n-params", "n-params", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_FUNCTION_NAME_PROPERTY, gcalc_function_properties[GCALC_FUNCTION_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_FUNCTION_CLOSED_PROPERTY, gcalc_function_properties[GCALC_FUNCTION_CLOSED_PROPERTY] = g_param_spec_boolean ("closed", "closed", "closed", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gcalc_function_gcalc_math_function_interface_init (GCalcMathFunctionIface * iface,
                                                   gpointer iface_data)
{
	gcalc_function_gcalc_math_function_parent_iface = g_type_interface_peek_parent (iface);
	iface->evaluate = (GCalcMathExpression* (*) (GCalcMathFunction*, GError**)) gcalc_function_evaluate;
	iface->get_param_types = gcalc_function_real_get_param_types;
	iface->get_n_params = gcalc_function_real_get_n_params;
	iface->set_n_params = gcalc_function_real_set_n_params;
	iface->get_name = gcalc_function_real_get_name;
	iface->set_name = gcalc_function_real_set_name;
	iface->get_closed = gcalc_function_real_get_closed;
	iface->set_closed = gcalc_function_real_set_closed;
}

static void
gcalc_function_gcalc_hashable_interface_init (GCalcHashableIface * iface,
                                              gpointer iface_data)
{
	gcalc_function_gcalc_hashable_parent_iface = g_type_interface_peek_parent (iface);
	iface->hash = (guint (*) (GCalcHashable*)) gcalc_function_real_hash;
}

static void
gcalc_function_instance_init (GCalcFunction * self,
                              gpointer klass)
{
	GCalcExpressionContainer* _tmp0_;
	self->priv = gcalc_function_get_instance_private (self);
	_tmp0_ = gcalc_expression_container_new ();
	self->priv->_param_types = _tmp0_;
}

static void
gcalc_function_finalize (GObject * obj)
{
	GCalcFunction * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_FUNCTION, GCalcFunction);
	_g_object_unref0 (self->priv->_param_types);
	_g_free0 (self->priv->_name);
	G_OBJECT_CLASS (gcalc_function_parent_class)->finalize (obj);
}

/**
 * An implementation of {@link MathFunction}
 */
static GType
gcalc_function_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcFunctionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_function_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcFunction), 0, (GInstanceInitFunc) gcalc_function_instance_init, NULL };
	static const GInterfaceInfo gcalc_math_function_info = { (GInterfaceInitFunc) gcalc_function_gcalc_math_function_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo gcalc_hashable_info = { (GInterfaceInitFunc) gcalc_function_gcalc_hashable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gcalc_function_type_id;
	gcalc_function_type_id = g_type_register_static (GCALC_TYPE_EXPRESSION, "GCalcFunction", &g_define_type_info, 0);
	g_type_add_interface_static (gcalc_function_type_id, GCALC_TYPE_MATH_FUNCTION, &gcalc_math_function_info);
	g_type_add_interface_static (gcalc_function_type_id, GCALC_TYPE_HASHABLE, &gcalc_hashable_info);
	GCalcFunction_private_offset = g_type_add_instance_private (gcalc_function_type_id, sizeof (GCalcFunctionPrivate));
	return gcalc_function_type_id;
}

GType
gcalc_function_get_type (void)
{
	static volatile gsize gcalc_function_type_id__once = 0;
	if (g_once_init_enter (&gcalc_function_type_id__once)) {
		GType gcalc_function_type_id;
		gcalc_function_type_id = gcalc_function_get_type_once ();
		g_once_init_leave (&gcalc_function_type_id__once, gcalc_function_type_id);
	}
	return gcalc_function_type_id__once;
}

static void
_vala_gcalc_function_get_property (GObject * object,
                                   guint property_id,
                                   GValue * value,
                                   GParamSpec * pspec)
{
	GCalcFunction * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_FUNCTION, GCalcFunction);
	switch (property_id) {
		case GCALC_FUNCTION_PARAM_TYPES_PROPERTY:
		g_value_set_object (value, gcalc_math_function_get_param_types ((GCalcMathFunction*) self));
		break;
		case GCALC_FUNCTION_N_PARAMS_PROPERTY:
		g_value_set_uint (value, gcalc_math_function_get_n_params ((GCalcMathFunction*) self));
		break;
		case GCALC_FUNCTION_NAME_PROPERTY:
		g_value_set_string (value, gcalc_math_function_get_name ((GCalcMathFunction*) self));
		break;
		case GCALC_FUNCTION_CLOSED_PROPERTY:
		g_value_set_boolean (value, gcalc_math_function_get_closed ((GCalcMathFunction*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gcalc_function_set_property (GObject * object,
                                   guint property_id,
                                   const GValue * value,
                                   GParamSpec * pspec)
{
	GCalcFunction * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_FUNCTION, GCalcFunction);
	switch (property_id) {
		case GCALC_FUNCTION_N_PARAMS_PROPERTY:
		gcalc_math_function_set_n_params ((GCalcMathFunction*) self, g_value_get_uint (value));
		break;
		case GCALC_FUNCTION_NAME_PROPERTY:
		gcalc_math_function_set_name ((GCalcMathFunction*) self, g_value_get_string (value));
		break;
		case GCALC_FUNCTION_CLOSED_PROPERTY:
		gcalc_math_function_set_closed ((GCalcMathFunction*) self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

