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

/* gcalc-expresion.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 <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.h>
#include <glib-object.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_0_PROPERTY,
	GCALC_EXPRESSION_PARENT_PROPERTY,
	GCALC_EXPRESSION_EXPRESSIONS_PROPERTY,
	GCALC_EXPRESSION_NUM_PROPERTIES
};
static GParamSpec* gcalc_expression_properties[GCALC_EXPRESSION_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))
enum  {
	GCALC_ERROR_EXPRESSION_0_PROPERTY,
	GCALC_ERROR_EXPRESSION_NUM_PROPERTIES
};
static GParamSpec* gcalc_error_expression_properties[GCALC_ERROR_EXPRESSION_NUM_PROPERTIES];

struct _GCalcExpressionPrivate {
	GCalcExpressionContainer* exps;
	GCalcMathExpression* _parent;
};

static gint GCalcExpression_private_offset;
static gpointer gcalc_expression_parent_class = NULL;
static GCalcMathExpressionIface * gcalc_expression_gcalc_math_expression_parent_iface = NULL;
static gpointer gcalc_error_expression_parent_class = NULL;

VALA_EXTERN gchar* gcalc_expression_to_string (GCalcExpression* self);
VALA_EXTERN GCalcMathResult* gcalc_expression_solve (GCalcExpression* self);
static gchar* gcalc_expression_real_to_string (GCalcExpression* self);
static GCalcMathResult* gcalc_expression_real_solve (GCalcExpression* self);
static GObject * gcalc_expression_constructor (GType type,
                                        guint n_construct_properties,
                                        GObjectConstructParam * construct_properties);
static void gcalc_expression_finalize (GObject * obj);
static GType gcalc_expression_get_type_once (void);
static void _vala_gcalc_expression_get_property (GObject * object,
                                          guint property_id,
                                          GValue * value,
                                          GParamSpec * pspec);
static void _vala_gcalc_expression_set_property (GObject * object,
                                          guint property_id,
                                          const GValue * value,
                                          GParamSpec * pspec);
static GType gcalc_error_expression_get_type_once (void);

static inline gpointer
gcalc_expression_get_instance_private (GCalcExpression* self)
{
	return G_STRUCT_MEMBER_P (self, GCalcExpression_private_offset);
}

static gchar*
gcalc_expression_real_to_string (GCalcExpression* self)
{
	gchar* s = NULL;
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = g_strdup ("");
	s = _tmp0_;
	{
		GCalcExpressionContainer* _e_list = NULL;
		GCalcExpressionContainer* _tmp1_;
		GCalcExpressionContainer* _tmp2_;
		gint _e_size = 0;
		GCalcExpressionContainer* _tmp3_;
		gint _tmp4_;
		gint _tmp5_;
		gint _e_index = 0;
		_tmp1_ = gcalc_math_expression_get_expressions ((GCalcMathExpression*) self);
		_tmp2_ = _tmp1_;
		_e_list = _tmp2_;
		_tmp3_ = _e_list;
		_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
		_tmp5_ = _tmp4_;
		_e_size = _tmp5_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp6_;
			gint _tmp7_;
			GCalcMathExpression* e = NULL;
			GCalcExpressionContainer* _tmp8_;
			gpointer _tmp9_;
			const gchar* _tmp10_;
			GCalcMathExpression* _tmp11_;
			gchar* _tmp12_;
			gchar* _tmp13_;
			gchar* _tmp14_;
			_e_index = _e_index + 1;
			_tmp6_ = _e_index;
			_tmp7_ = _e_size;
			if (!(_tmp6_ < _tmp7_)) {
				break;
			}
			_tmp8_ = _e_list;
			_tmp9_ = gee_abstract_list_get ((GeeAbstractList*) _tmp8_, _e_index);
			e = (GCalcMathExpression*) _tmp9_;
			_tmp10_ = s;
			_tmp11_ = e;
			_tmp12_ = gcalc_math_expression_to_string (_tmp11_);
			_tmp13_ = _tmp12_;
			_tmp14_ = g_strconcat (_tmp10_, _tmp13_, NULL);
			_g_free0 (s);
			s = _tmp14_;
			_g_free0 (_tmp13_);
			_g_object_unref0 (e);
		}
	}
	result = s;
	return result;
}

gchar*
gcalc_expression_to_string (GCalcExpression* self)
{
	GCalcExpressionClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = GCALC_EXPRESSION_GET_CLASS (self);
	if (_klass_->to_string) {
		return _klass_->to_string (self);
	}
	return NULL;
}

static GCalcMathResult*
gcalc_expression_real_solve (GCalcExpression* self)
{
	GCalcErrorResult* _tmp0_;
	GCalcMathResult* result;
	_tmp0_ = gcalc_error_result_new ("Invalid expression");
	result = (GCalcMathResult*) _tmp0_;
	return result;
}

GCalcMathResult*
gcalc_expression_solve (GCalcExpression* self)
{
	GCalcExpressionClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = GCALC_EXPRESSION_GET_CLASS (self);
	if (_klass_->solve) {
		return _klass_->solve (self);
	}
	return NULL;
}

GCalcExpression*
gcalc_expression_construct (GType object_type)
{
	GCalcExpression * self = NULL;
	self = (GCalcExpression*) g_object_new (object_type, NULL);
	return self;
}

GCalcExpression*
gcalc_expression_new (void)
{
	return gcalc_expression_construct (GCALC_TYPE_EXPRESSION);
}

static GCalcMathExpression*
gcalc_expression_real_get_parent (GCalcMathExpression* base)
{
	GCalcMathExpression* result;
	GCalcExpression* self;
	GCalcMathExpression* _tmp0_;
	self = (GCalcExpression*) base;
	_tmp0_ = self->priv->_parent;
	result = _tmp0_;
	return result;
}

static void
gcalc_expression_real_set_parent (GCalcMathExpression* base,
                                  GCalcMathExpression* value)
{
	GCalcExpression* self;
	GCalcMathExpression* old_value;
	self = (GCalcExpression*) base;
	old_value = gcalc_expression_real_get_parent (base);
	if (old_value != value) {
		self->priv->_parent = value;
		g_object_notify_by_pspec ((GObject *) self, gcalc_expression_properties[GCALC_EXPRESSION_PARENT_PROPERTY]);
	}
}

static GCalcExpressionContainer*
gcalc_expression_real_get_expressions (GCalcMathExpression* base)
{
	GCalcExpressionContainer* result;
	GCalcExpression* self;
	GCalcExpressionContainer* _tmp0_;
	self = (GCalcExpression*) base;
	_tmp0_ = self->priv->exps;
	result = _tmp0_;
	return result;
}

static GObject *
gcalc_expression_constructor (GType type,
                              guint n_construct_properties,
                              GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GCalcExpression * self;
	GCalcExpressionContainer* _tmp0_;
	parent_class = G_OBJECT_CLASS (gcalc_expression_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_EXPRESSION, GCalcExpression);
	_tmp0_ = self->priv->exps;
	gcalc_expression_container_set_parent (_tmp0_, (GCalcMathExpression*) self);
	return obj;
}

static void
gcalc_expression_class_init (GCalcExpressionClass * klass,
                             gpointer klass_data)
{
	gcalc_expression_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GCalcExpression_private_offset);
	((GCalcExpressionClass *) klass)->to_string = (gchar* (*) (GCalcExpression*)) gcalc_expression_real_to_string;
	((GCalcExpressionClass *) klass)->solve = (GCalcMathResult* (*) (GCalcExpression*)) gcalc_expression_real_solve;
	G_OBJECT_CLASS (klass)->get_property = _vala_gcalc_expression_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gcalc_expression_set_property;
	G_OBJECT_CLASS (klass)->constructor = gcalc_expression_constructor;
	G_OBJECT_CLASS (klass)->finalize = gcalc_expression_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_EXPRESSION_PARENT_PROPERTY, gcalc_expression_properties[GCALC_EXPRESSION_PARENT_PROPERTY] = g_param_spec_object ("parent", "parent", "parent", GCALC_TYPE_MATH_EXPRESSION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_EXPRESSION_EXPRESSIONS_PROPERTY, gcalc_expression_properties[GCALC_EXPRESSION_EXPRESSIONS_PROPERTY] = g_param_spec_object ("expressions", "expressions", "expressions", GCALC_TYPE_EXPRESSION_CONTAINER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
gcalc_expression_gcalc_math_expression_interface_init (GCalcMathExpressionIface * iface,
                                                       gpointer iface_data)
{
	gcalc_expression_gcalc_math_expression_parent_iface = g_type_interface_peek_parent (iface);
	iface->to_string = (gchar* (*) (GCalcMathExpression*)) gcalc_expression_to_string;
	iface->solve = (GCalcMathResult* (*) (GCalcMathExpression*)) gcalc_expression_solve;
	iface->get_parent = gcalc_expression_real_get_parent;
	iface->set_parent = gcalc_expression_real_set_parent;
	iface->get_expressions = gcalc_expression_real_get_expressions;
}

static void
gcalc_expression_instance_init (GCalcExpression * self,
                                gpointer klass)
{
	GCalcExpressionContainer* _tmp0_;
	self->priv = gcalc_expression_get_instance_private (self);
	_tmp0_ = gcalc_expression_container_new ();
	self->priv->exps = _tmp0_;
}

static void
gcalc_expression_finalize (GObject * obj)
{
	GCalcExpression * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_EXPRESSION, GCalcExpression);
	_g_object_unref0 (self->priv->exps);
	G_OBJECT_CLASS (gcalc_expression_parent_class)->finalize (obj);
}

/**
 * An implementation of {@link MathExpression}
 */
static GType
gcalc_expression_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcExpressionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_expression_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcExpression), 0, (GInstanceInitFunc) gcalc_expression_instance_init, NULL };
	static const GInterfaceInfo gcalc_math_expression_info = { (GInterfaceInitFunc) gcalc_expression_gcalc_math_expression_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gcalc_expression_type_id;
	gcalc_expression_type_id = g_type_register_static (G_TYPE_OBJECT, "GCalcExpression", &g_define_type_info, 0);
	g_type_add_interface_static (gcalc_expression_type_id, GCALC_TYPE_MATH_EXPRESSION, &gcalc_math_expression_info);
	GCalcExpression_private_offset = g_type_add_instance_private (gcalc_expression_type_id, sizeof (GCalcExpressionPrivate));
	return gcalc_expression_type_id;
}

GType
gcalc_expression_get_type (void)
{
	static volatile gsize gcalc_expression_type_id__once = 0;
	if (g_once_init_enter (&gcalc_expression_type_id__once)) {
		GType gcalc_expression_type_id;
		gcalc_expression_type_id = gcalc_expression_get_type_once ();
		g_once_init_leave (&gcalc_expression_type_id__once, gcalc_expression_type_id);
	}
	return gcalc_expression_type_id__once;
}

static void
_vala_gcalc_expression_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec)
{
	GCalcExpression * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_EXPRESSION, GCalcExpression);
	switch (property_id) {
		case GCALC_EXPRESSION_PARENT_PROPERTY:
		g_value_set_object (value, gcalc_math_expression_get_parent ((GCalcMathExpression*) self));
		break;
		case GCALC_EXPRESSION_EXPRESSIONS_PROPERTY:
		g_value_set_object (value, gcalc_math_expression_get_expressions ((GCalcMathExpression*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gcalc_expression_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec)
{
	GCalcExpression * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_EXPRESSION, GCalcExpression);
	switch (property_id) {
		case GCALC_EXPRESSION_PARENT_PROPERTY:
		gcalc_math_expression_set_parent ((GCalcMathExpression*) self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

GCalcErrorExpression*
gcalc_error_expression_construct (GType object_type)
{
	GCalcErrorExpression * self = NULL;
	self = (GCalcErrorExpression*) gcalc_expression_construct (object_type);
	return self;
}

GCalcErrorExpression*
gcalc_error_expression_new (void)
{
	return gcalc_error_expression_construct (GCALC_TYPE_ERROR_EXPRESSION);
}

static void
gcalc_error_expression_class_init (GCalcErrorExpressionClass * klass,
                                   gpointer klass_data)
{
	gcalc_error_expression_parent_class = g_type_class_peek_parent (klass);
}

static void
gcalc_error_expression_instance_init (GCalcErrorExpression * self,
                                      gpointer klass)
{
}

/**
 * Represent an expression in error condition
 */
static GType
gcalc_error_expression_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcErrorExpressionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_error_expression_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcErrorExpression), 0, (GInstanceInitFunc) gcalc_error_expression_instance_init, NULL };
	GType gcalc_error_expression_type_id;
	gcalc_error_expression_type_id = g_type_register_static (GCALC_TYPE_EXPRESSION, "GCalcErrorExpression", &g_define_type_info, 0);
	return gcalc_error_expression_type_id;
}

GType
gcalc_error_expression_get_type (void)
{
	static volatile gsize gcalc_error_expression_type_id__once = 0;
	if (g_once_init_enter (&gcalc_error_expression_type_id__once)) {
		GType gcalc_error_expression_type_id;
		gcalc_error_expression_type_id = gcalc_error_expression_get_type_once ();
		g_once_init_leave (&gcalc_error_expression_type_id__once, gcalc_error_expression_type_id);
	}
	return gcalc_error_expression_type_id__once;
}

