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

/* gcalc-polynomial.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 "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_POLYNOMIAL_0_PROPERTY,
	GCALC_POLYNOMIAL_NUM_PROPERTIES
};
static GParamSpec* gcalc_polynomial_properties[GCALC_POLYNOMIAL_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_polynomial_parent_class = NULL;
static GCalcMathPolynomialIface * gcalc_polynomial_gcalc_math_polynomial_parent_iface = NULL;

VALA_EXTERN GCalcMathResult* gcalc_expression_solve (GCalcExpression* self);
static GCalcMathResult* gcalc_polynomial_real_solve (GCalcExpression* base);
static GType gcalc_polynomial_get_type_once (void);

static GCalcMathResult*
gcalc_polynomial_real_solve (GCalcExpression* base)
{
	GCalcPolynomial * self;
	GCalcMathResult* res = NULL;
	GError* _inner_error0_ = NULL;
	GCalcMathResult* result;
	self = (GCalcPolynomial*) base;
	res = NULL;
	{
		GCalcMathExpression* e = NULL;
		GCalcMathExpression* _tmp0_;
		GCalcResult* _tmp1_;
		GCalcMathResult* _tmp2_;
		_tmp0_ = gcalc_math_polynomial_evaluate ((GCalcMathPolynomial*) 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 ("Polynomial solving 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;
}

GCalcPolynomial*
gcalc_polynomial_construct (GType object_type)
{
	GCalcPolynomial * self = NULL;
	self = (GCalcPolynomial*) gcalc_expression_construct (object_type);
	return self;
}

GCalcPolynomial*
gcalc_polynomial_new (void)
{
	return gcalc_polynomial_construct (GCALC_TYPE_POLYNOMIAL);
}

static void
gcalc_polynomial_class_init (GCalcPolynomialClass * klass,
                             gpointer klass_data)
{
	gcalc_polynomial_parent_class = g_type_class_peek_parent (klass);
	((GCalcExpressionClass *) klass)->solve = (GCalcMathResult* (*) (GCalcExpression*)) gcalc_polynomial_real_solve;
}

static void
gcalc_polynomial_gcalc_math_polynomial_interface_init (GCalcMathPolynomialIface * iface,
                                                       gpointer iface_data)
{
	gcalc_polynomial_gcalc_math_polynomial_parent_iface = g_type_interface_peek_parent (iface);
}

static void
gcalc_polynomial_instance_init (GCalcPolynomial * self,
                                gpointer klass)
{
}

/**
 * An implementation of {@link MathPolynomial}
 */
static GType
gcalc_polynomial_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcPolynomialClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_polynomial_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcPolynomial), 0, (GInstanceInitFunc) gcalc_polynomial_instance_init, NULL };
	static const GInterfaceInfo gcalc_math_polynomial_info = { (GInterfaceInitFunc) gcalc_polynomial_gcalc_math_polynomial_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gcalc_polynomial_type_id;
	gcalc_polynomial_type_id = g_type_register_static (GCALC_TYPE_EXPRESSION, "GCalcPolynomial", &g_define_type_info, 0);
	g_type_add_interface_static (gcalc_polynomial_type_id, GCALC_TYPE_MATH_POLYNOMIAL, &gcalc_math_polynomial_info);
	return gcalc_polynomial_type_id;
}

GType
gcalc_polynomial_get_type (void)
{
	static volatile gsize gcalc_polynomial_type_id__once = 0;
	if (g_once_init_enter (&gcalc_polynomial_type_id__once)) {
		GType gcalc_polynomial_type_id;
		gcalc_polynomial_type_id = gcalc_polynomial_get_type_once ();
		g_once_init_leave (&gcalc_polynomial_type_id__once, gcalc_polynomial_type_id);
	}
	return gcalc_polynomial_type_id__once;
}

