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

/* gcalc-ggroup.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 <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_GROUP_0_PROPERTY,
	GCALC_GROUP_LEVEL_PROPERTY,
	GCALC_GROUP_CLOSED_PROPERTY,
	GCALC_GROUP_NUM_PROPERTIES
};
static GParamSpec* gcalc_group_properties[GCALC_GROUP_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _GCalcGroupPrivate {
	GCalcMathGroupLevel _level;
	gboolean _closed;
};

static gint GCalcGroup_private_offset;
static gpointer gcalc_group_parent_class = NULL;
static GCalcMathGroupIface * gcalc_group_gcalc_math_group_parent_iface = NULL;

VALA_EXTERN gchar* gcalc_expression_to_string (GCalcExpression* self);
static gchar* gcalc_group_real_to_string (GCalcExpression* base);
static void gcalc_group_finalize (GObject * obj);
static GType gcalc_group_get_type_once (void);
static void _vala_gcalc_group_get_property (GObject * object,
                                     guint property_id,
                                     GValue * value,
                                     GParamSpec * pspec);
static void _vala_gcalc_group_set_property (GObject * object,
                                     guint property_id,
                                     const GValue * value,
                                     GParamSpec * pspec);

static inline gpointer
gcalc_group_get_instance_private (GCalcGroup* self)
{
	return G_STRUCT_MEMBER_P (self, GCalcGroup_private_offset);
}

static gchar*
gcalc_group_real_to_string (GCalcExpression* base)
{
	GCalcGroup * self;
	gchar* s = NULL;
	gchar* _tmp0_;
	GCalcMathGroupLevel _tmp1_;
	GCalcMathGroupLevel _tmp2_;
	GCalcMathGroupLevel _tmp20_;
	GCalcMathGroupLevel _tmp21_;
	gchar* result;
	self = (GCalcGroup*) base;
	_tmp0_ = g_strdup ("");
	s = _tmp0_;
	_tmp1_ = gcalc_math_group_get_level ((GCalcMathGroup*) self);
	_tmp2_ = _tmp1_;
	switch (_tmp2_) {
		case GCALC_MATH_GROUP_LEVEL_ONE:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("(");
			_g_free0 (s);
			s = _tmp3_;
			break;
		}
		case GCALC_MATH_GROUP_LEVEL_TWO:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("[");
			_g_free0 (s);
			s = _tmp4_;
			break;
		}
		case GCALC_MATH_GROUP_LEVEL_THREE:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup ("{");
			_g_free0 (s);
			s = _tmp5_;
			break;
		}
		default:
		break;
	}
	{
		GCalcExpressionContainer* _e_list = NULL;
		GCalcExpressionContainer* _tmp6_;
		GCalcExpressionContainer* _tmp7_;
		gint _e_size = 0;
		GCalcExpressionContainer* _tmp8_;
		gint _tmp9_;
		gint _tmp10_;
		gint _e_index = 0;
		_tmp6_ = gcalc_math_expression_get_expressions ((GCalcMathExpression*) self);
		_tmp7_ = _tmp6_;
		_e_list = _tmp7_;
		_tmp8_ = _e_list;
		_tmp9_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp8_);
		_tmp10_ = _tmp9_;
		_e_size = _tmp10_;
		_e_index = -1;
		while (TRUE) {
			gint _tmp11_;
			gint _tmp12_;
			GCalcMathExpression* e = NULL;
			GCalcExpressionContainer* _tmp13_;
			gpointer _tmp14_;
			const gchar* _tmp15_;
			GCalcMathExpression* _tmp16_;
			gchar* _tmp17_;
			gchar* _tmp18_;
			gchar* _tmp19_;
			_e_index = _e_index + 1;
			_tmp11_ = _e_index;
			_tmp12_ = _e_size;
			if (!(_tmp11_ < _tmp12_)) {
				break;
			}
			_tmp13_ = _e_list;
			_tmp14_ = gee_abstract_list_get ((GeeAbstractList*) _tmp13_, _e_index);
			e = (GCalcMathExpression*) _tmp14_;
			_tmp15_ = s;
			_tmp16_ = e;
			_tmp17_ = gcalc_math_expression_to_string (_tmp16_);
			_tmp18_ = _tmp17_;
			_tmp19_ = g_strconcat (_tmp15_, _tmp18_, NULL);
			_g_free0 (s);
			s = _tmp19_;
			_g_free0 (_tmp18_);
			_g_object_unref0 (e);
		}
	}
	_tmp20_ = gcalc_math_group_get_level ((GCalcMathGroup*) self);
	_tmp21_ = _tmp20_;
	switch (_tmp21_) {
		case GCALC_MATH_GROUP_LEVEL_ONE:
		{
			const gchar* _tmp22_;
			gchar* _tmp23_;
			_tmp22_ = s;
			_tmp23_ = g_strconcat (_tmp22_, ")", NULL);
			_g_free0 (s);
			s = _tmp23_;
			break;
		}
		case GCALC_MATH_GROUP_LEVEL_TWO:
		{
			const gchar* _tmp24_;
			gchar* _tmp25_;
			_tmp24_ = s;
			_tmp25_ = g_strconcat (_tmp24_, "]", NULL);
			_g_free0 (s);
			s = _tmp25_;
			break;
		}
		case GCALC_MATH_GROUP_LEVEL_THREE:
		{
			const gchar* _tmp26_;
			gchar* _tmp27_;
			_tmp26_ = s;
			_tmp27_ = g_strconcat (_tmp26_, "}", NULL);
			_g_free0 (s);
			s = _tmp27_;
			break;
		}
		default:
		break;
	}
	result = s;
	return result;
}

GCalcGroup*
gcalc_group_construct (GType object_type)
{
	GCalcGroup * self = NULL;
	self = (GCalcGroup*) gcalc_expression_construct (object_type);
	return self;
}

GCalcGroup*
gcalc_group_new (void)
{
	return gcalc_group_construct (GCALC_TYPE_GROUP);
}

static GCalcMathGroupLevel
gcalc_group_real_get_level (GCalcMathGroup* base)
{
	GCalcMathGroupLevel result;
	GCalcGroup* self;
	self = (GCalcGroup*) base;
	result = self->priv->_level;
	return result;
}

static void
gcalc_group_real_set_level (GCalcMathGroup* base,
                            GCalcMathGroupLevel value)
{
	GCalcGroup* self;
	GCalcMathGroupLevel old_value;
	self = (GCalcGroup*) base;
	old_value = gcalc_group_real_get_level (base);
	if (old_value != value) {
		self->priv->_level = value;
		g_object_notify_by_pspec ((GObject *) self, gcalc_group_properties[GCALC_GROUP_LEVEL_PROPERTY]);
	}
}

static gboolean
gcalc_group_real_get_closed (GCalcMathGroup* base)
{
	gboolean result;
	GCalcGroup* self;
	self = (GCalcGroup*) base;
	result = self->priv->_closed;
	return result;
}

static void
gcalc_group_real_set_closed (GCalcMathGroup* base,
                             gboolean value)
{
	GCalcGroup* self;
	gboolean old_value;
	self = (GCalcGroup*) base;
	old_value = gcalc_group_real_get_closed (base);
	if (old_value != value) {
		self->priv->_closed = value;
		g_object_notify_by_pspec ((GObject *) self, gcalc_group_properties[GCALC_GROUP_CLOSED_PROPERTY]);
	}
}

static void
gcalc_group_class_init (GCalcGroupClass * klass,
                        gpointer klass_data)
{
	gcalc_group_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GCalcGroup_private_offset);
	((GCalcExpressionClass *) klass)->to_string = (gchar* (*) (GCalcExpression*)) gcalc_group_real_to_string;
	G_OBJECT_CLASS (klass)->get_property = _vala_gcalc_group_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gcalc_group_set_property;
	G_OBJECT_CLASS (klass)->finalize = gcalc_group_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_GROUP_LEVEL_PROPERTY, gcalc_group_properties[GCALC_GROUP_LEVEL_PROPERTY] = g_param_spec_enum ("level", "level", "level", GCALC_MATH_GROUP_TYPE_LEVEL, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_GROUP_CLOSED_PROPERTY, gcalc_group_properties[GCALC_GROUP_CLOSED_PROPERTY] = g_param_spec_boolean ("closed", "closed", "closed", FALSE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gcalc_group_gcalc_math_group_interface_init (GCalcMathGroupIface * iface,
                                             gpointer iface_data)
{
	gcalc_group_gcalc_math_group_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_level = gcalc_group_real_get_level;
	iface->set_level = gcalc_group_real_set_level;
	iface->get_closed = gcalc_group_real_get_closed;
	iface->set_closed = gcalc_group_real_set_closed;
}

static void
gcalc_group_instance_init (GCalcGroup * self,
                           gpointer klass)
{
	self->priv = gcalc_group_get_instance_private (self);
}

static void
gcalc_group_finalize (GObject * obj)
{
	GCalcGroup * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_GROUP, GCalcGroup);
	G_OBJECT_CLASS (gcalc_group_parent_class)->finalize (obj);
}

/**
 * An implementation of {@link MathGroup}
 */
static GType
gcalc_group_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcGroupClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_group_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcGroup), 0, (GInstanceInitFunc) gcalc_group_instance_init, NULL };
	static const GInterfaceInfo gcalc_math_group_info = { (GInterfaceInitFunc) gcalc_group_gcalc_math_group_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gcalc_group_type_id;
	gcalc_group_type_id = g_type_register_static (GCALC_TYPE_EXPRESSION, "GCalcGroup", &g_define_type_info, 0);
	g_type_add_interface_static (gcalc_group_type_id, GCALC_TYPE_MATH_GROUP, &gcalc_math_group_info);
	GCalcGroup_private_offset = g_type_add_instance_private (gcalc_group_type_id, sizeof (GCalcGroupPrivate));
	return gcalc_group_type_id;
}

GType
gcalc_group_get_type (void)
{
	static volatile gsize gcalc_group_type_id__once = 0;
	if (g_once_init_enter (&gcalc_group_type_id__once)) {
		GType gcalc_group_type_id;
		gcalc_group_type_id = gcalc_group_get_type_once ();
		g_once_init_leave (&gcalc_group_type_id__once, gcalc_group_type_id);
	}
	return gcalc_group_type_id__once;
}

static void
_vala_gcalc_group_get_property (GObject * object,
                                guint property_id,
                                GValue * value,
                                GParamSpec * pspec)
{
	GCalcGroup * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_GROUP, GCalcGroup);
	switch (property_id) {
		case GCALC_GROUP_LEVEL_PROPERTY:
		g_value_set_enum (value, gcalc_math_group_get_level ((GCalcMathGroup*) self));
		break;
		case GCALC_GROUP_CLOSED_PROPERTY:
		g_value_set_boolean (value, gcalc_math_group_get_closed ((GCalcMathGroup*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gcalc_group_set_property (GObject * object,
                                guint property_id,
                                const GValue * value,
                                GParamSpec * pspec)
{
	GCalcGroup * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_GROUP, GCalcGroup);
	switch (property_id) {
		case GCALC_GROUP_LEVEL_PROPERTY:
		gcalc_math_group_set_level ((GCalcMathGroup*) self, g_value_get_enum (value));
		break;
		case GCALC_GROUP_CLOSED_PROPERTY:
		gcalc_math_group_set_closed ((GCalcMathGroup*) self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

