/* gcalc-term.c generated by valac 0.56.0, the Vala compiler
 * generated from gcalc-term.vala, do not modify */

/* gcalc-term.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 "gcalc.h"

enum  {
	GCALC_TERM_0_PROPERTY,
	GCALC_TERM_NUM_PROPERTIES
};
static GParamSpec* gcalc_term_properties[GCALC_TERM_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))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

static gpointer gcalc_term_parent_class = NULL;
static GCalcMathTermIface * gcalc_term_gcalc_math_term_parent_iface = NULL;

VALA_EXTERN GCalcMathResult* gcalc_expression_solve (GCalcExpression* self);
static GCalcMathResult* gcalc_term_real_solve (GCalcExpression* base);
static GType gcalc_term_get_type_once (void);

static GCalcMathResult*
gcalc_term_real_solve (GCalcExpression* base)
{
	GCalcTerm * self;
	GCalcMathResult* res = NULL;
	GError* _inner_error0_ = NULL;
	GCalcMathResult* result;
	self = (GCalcTerm*) base;
	res = NULL;
	{
		GCalcMathExpression* e = NULL;
		GCalcMathExpression* _tmp0_;
		GCalcResult* _tmp1_;
		GCalcMathResult* _tmp2_;
		_tmp0_ = gcalc_math_term_evaluate ((GCalcMathTerm*) self, &_inner_error0_);
		e = _tmp0_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp1_ = gcalc_result_new (e);
		_tmp2_ = GCALC_IS_MATH_RESULT (_tmp1_) ? ((GCalcMathResult*) _tmp1_) : NULL;
		if (_tmp2_ == NULL) {
			_g_object_unref0 (_tmp1_);
		}
		_g_object_unref0 (res);
		res = _tmp2_;
		_g_object_unref0 (e);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* err = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		gchar* _tmp5_;
		gchar* _tmp6_;
		GCalcErrorResult* _tmp7_;
		err = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = err;
		_tmp4_ = _tmp3_->message;
		_tmp5_ = g_strdup_printf ("Term evaluation fails: %s", _tmp4_);
		_tmp6_ = _tmp5_;
		_tmp7_ = gcalc_error_result_new (_tmp6_);
		_g_object_unref0 (res);
		res = (GCalcMathResult*) _tmp7_;
		_g_free0 (_tmp6_);
		_g_error_free0 (err);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (res);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return NULL;
	}
	result = res;
	return result;
}

GCalcTerm*
gcalc_term_construct (GType object_type)
{
	GCalcTerm * self = NULL;
	self = (GCalcTerm*) gcalc_expression_construct (object_type);
	return self;
}

GCalcTerm*
gcalc_term_new (void)
{
	return gcalc_term_construct (GCALC_TYPE_TERM);
}

static void
gcalc_term_class_init (GCalcTermClass * klass,
                       gpointer klass_data)
{
	gcalc_term_parent_class = g_type_class_peek_parent (klass);
	((GCalcExpressionClass *) klass)->solve = (GCalcMathResult* (*) (GCalcExpression*)) gcalc_term_real_solve;
}

static void
gcalc_term_gcalc_math_term_interface_init (GCalcMathTermIface * iface,
                                           gpointer iface_data)
{
	gcalc_term_gcalc_math_term_parent_iface = g_type_interface_peek_parent (iface);
}

static void
gcalc_term_instance_init (GCalcTerm * self,
                          gpointer klass)
{
}

/**
 * An implementation of {@link MathTerm}
 */
static GType
gcalc_term_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcTermClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_term_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcTerm), 0, (GInstanceInitFunc) gcalc_term_instance_init, NULL };
	static const GInterfaceInfo gcalc_math_term_info = { (GInterfaceInitFunc) gcalc_term_gcalc_math_term_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gcalc_term_type_id;
	gcalc_term_type_id = g_type_register_static (GCALC_TYPE_EXPRESSION, "GCalcTerm", &g_define_type_info, 0);
	g_type_add_interface_static (gcalc_term_type_id, GCALC_TYPE_MATH_TERM, &gcalc_math_term_info);
	return gcalc_term_type_id;
}

GType
gcalc_term_get_type (void)
{
	static volatile gsize gcalc_term_type_id__once = 0;
	if (g_once_init_enter (&gcalc_term_type_id__once)) {
		GType gcalc_term_type_id;
		gcalc_term_type_id = gcalc_term_get_type_once ();
		g_once_init_leave (&gcalc_term_type_id__once, gcalc_term_type_id);
	}
	return gcalc_term_type_id__once;
}

