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

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

enum  {
	GCALC_VARIABLE_0_PROPERTY,
	GCALC_VARIABLE_NAME_PROPERTY,
	GCALC_VARIABLE_VALUE_PROPERTY,
	GCALC_VARIABLE_BIND_PROPERTY,
	GCALC_VARIABLE_NUM_PROPERTIES
};
static GParamSpec* gcalc_variable_properties[GCALC_VARIABLE_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 _GCalcVariablePrivate {
	gchar* _name;
	GCalcMathConstant* _value;
	GCalcMathVariable* _bind;
};

static gint GCalcVariable_private_offset;
static gpointer gcalc_variable_parent_class = NULL;
static GCalcMathVariableIface * gcalc_variable_gcalc_math_variable_parent_iface = NULL;
static GCalcHashableIface * gcalc_variable_gcalc_hashable_parent_iface = NULL;

VALA_EXTERN gchar* gcalc_expression_to_string (GCalcExpression* self);
VALA_EXTERN GCalcVariable* gcalc_variable_new (const gchar* name);
VALA_EXTERN GCalcVariable* gcalc_variable_construct (GType object_type,
                                         const gchar* name);
static gchar* gcalc_variable_real_to_string (GCalcExpression* base);
static guint gcalc_variable_real_hash (GCalcHashable* base);
static GObject * gcalc_variable_constructor (GType type,
                                      guint n_construct_properties,
                                      GObjectConstructParam * construct_properties);
static void gcalc_variable_finalize (GObject * obj);
static GType gcalc_variable_get_type_once (void);
static void _vala_gcalc_variable_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec);
static void _vala_gcalc_variable_set_property (GObject * object,
                                        guint property_id,
                                        const GValue * value,
                                        GParamSpec * pspec);

static inline gpointer
gcalc_variable_get_instance_private (GCalcVariable* self)
{
	return G_STRUCT_MEMBER_P (self, GCalcVariable_private_offset);
}

GCalcVariable*
gcalc_variable_construct (GType object_type,
                          const gchar* name)
{
	GCalcVariable * self = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	self = (GCalcVariable*) gcalc_expression_construct (object_type);
	gcalc_math_variable_set_name ((GCalcMathVariable*) self, name);
	return self;
}

GCalcVariable*
gcalc_variable_new (const gchar* name)
{
	return gcalc_variable_construct (GCALC_TYPE_VARIABLE, name);
}

static gchar*
gcalc_variable_real_to_string (GCalcExpression* base)
{
	GCalcVariable * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	gchar* result;
	self = (GCalcVariable*) base;
	_tmp0_ = gcalc_math_variable_get_name ((GCalcMathVariable*) self);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup (_tmp1_);
	result = _tmp2_;
	return result;
}

static guint
gcalc_variable_real_hash (GCalcHashable* base)
{
	GCalcVariable * self;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	guint result;
	self = (GCalcVariable*) base;
	_tmp0_ = gcalc_math_variable_get_name ((GCalcMathVariable*) self);
	_tmp1_ = _tmp0_;
	result = g_str_hash (_tmp1_);
	return result;
}

static const gchar*
gcalc_variable_real_get_name (GCalcMathVariable* base)
{
	const gchar* result;
	GCalcVariable* self;
	const gchar* _tmp0_;
	self = (GCalcVariable*) base;
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}

static void
gcalc_variable_real_set_name (GCalcMathVariable* base,
                              const gchar* value)
{
	GCalcVariable* self;
	gchar* old_value;
	self = (GCalcVariable*) base;
	old_value = gcalc_variable_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_variable_properties[GCALC_VARIABLE_NAME_PROPERTY]);
	}
}

static GCalcMathConstant*
gcalc_variable_real_get_value (GCalcMathVariable* base)
{
	GCalcMathConstant* result;
	GCalcVariable* self;
	GCalcMathConstant* _tmp0_;
	self = (GCalcVariable*) base;
	_tmp0_ = self->priv->_value;
	result = _tmp0_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
gcalc_variable_real_set_value (GCalcMathVariable* base,
                               GCalcMathConstant* value)
{
	GCalcVariable* self;
	GCalcMathConstant* old_value;
	self = (GCalcVariable*) base;
	old_value = gcalc_variable_real_get_value (base);
	if (old_value != value) {
		GCalcMathConstant* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_value);
		self->priv->_value = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gcalc_variable_properties[GCALC_VARIABLE_VALUE_PROPERTY]);
	}
}

static GCalcMathVariable*
gcalc_variable_real_get_bind (GCalcMathVariable* base)
{
	GCalcMathVariable* result;
	GCalcVariable* self;
	GCalcMathVariable* _tmp0_;
	self = (GCalcVariable*) base;
	_tmp0_ = self->priv->_bind;
	result = _tmp0_;
	return result;
}

static void
gcalc_variable_real_set_bind (GCalcMathVariable* base,
                              GCalcMathVariable* value)
{
	GCalcVariable* self;
	GCalcMathVariable* old_value;
	self = (GCalcVariable*) base;
	old_value = gcalc_variable_real_get_bind (base);
	if (old_value != value) {
		GCalcMathVariable* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_bind);
		self->priv->_bind = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, gcalc_variable_properties[GCALC_VARIABLE_BIND_PROPERTY]);
	}
}

static GObject *
gcalc_variable_constructor (GType type,
                            guint n_construct_properties,
                            GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GCalcVariable * self;
	parent_class = G_OBJECT_CLASS (gcalc_variable_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_VARIABLE, GCalcVariable);
	_g_object_unref0 (self->priv->_value);
	self->priv->_value = NULL;
	return obj;
}

static void
gcalc_variable_class_init (GCalcVariableClass * klass,
                           gpointer klass_data)
{
	gcalc_variable_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GCalcVariable_private_offset);
	((GCalcExpressionClass *) klass)->to_string = (gchar* (*) (GCalcExpression*)) gcalc_variable_real_to_string;
	G_OBJECT_CLASS (klass)->get_property = _vala_gcalc_variable_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gcalc_variable_set_property;
	G_OBJECT_CLASS (klass)->constructor = gcalc_variable_constructor;
	G_OBJECT_CLASS (klass)->finalize = gcalc_variable_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_VARIABLE_NAME_PROPERTY, gcalc_variable_properties[GCALC_VARIABLE_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_VARIABLE_VALUE_PROPERTY, gcalc_variable_properties[GCALC_VARIABLE_VALUE_PROPERTY] = g_param_spec_object ("value", "value", "value", GCALC_TYPE_MATH_CONSTANT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_VARIABLE_BIND_PROPERTY, gcalc_variable_properties[GCALC_VARIABLE_BIND_PROPERTY] = g_param_spec_object ("bind", "bind", "bind", GCALC_TYPE_MATH_VARIABLE, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gcalc_variable_gcalc_math_variable_interface_init (GCalcMathVariableIface * iface,
                                                   gpointer iface_data)
{
	gcalc_variable_gcalc_math_variable_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_name = gcalc_variable_real_get_name;
	iface->set_name = gcalc_variable_real_set_name;
	iface->get_value = gcalc_variable_real_get_value;
	iface->set_value = gcalc_variable_real_set_value;
	iface->get_bind = gcalc_variable_real_get_bind;
	iface->set_bind = gcalc_variable_real_set_bind;
}

static void
gcalc_variable_gcalc_hashable_interface_init (GCalcHashableIface * iface,
                                              gpointer iface_data)
{
	gcalc_variable_gcalc_hashable_parent_iface = g_type_interface_peek_parent (iface);
	iface->hash = (guint (*) (GCalcHashable*)) gcalc_variable_real_hash;
}

static void
gcalc_variable_instance_init (GCalcVariable * self,
                              gpointer klass)
{
	self->priv = gcalc_variable_get_instance_private (self);
}

static void
gcalc_variable_finalize (GObject * obj)
{
	GCalcVariable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_VARIABLE, GCalcVariable);
	_g_free0 (self->priv->_name);
	_g_object_unref0 (self->priv->_value);
	_g_object_unref0 (self->priv->_bind);
	G_OBJECT_CLASS (gcalc_variable_parent_class)->finalize (obj);
}

/**
 * An implementation of {@link MathVariable}
 */
static GType
gcalc_variable_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcVariableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_variable_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcVariable), 0, (GInstanceInitFunc) gcalc_variable_instance_init, NULL };
	static const GInterfaceInfo gcalc_math_variable_info = { (GInterfaceInitFunc) gcalc_variable_gcalc_math_variable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo gcalc_hashable_info = { (GInterfaceInitFunc) gcalc_variable_gcalc_hashable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType gcalc_variable_type_id;
	gcalc_variable_type_id = g_type_register_static (GCALC_TYPE_EXPRESSION, "GCalcVariable", &g_define_type_info, 0);
	g_type_add_interface_static (gcalc_variable_type_id, GCALC_TYPE_MATH_VARIABLE, &gcalc_math_variable_info);
	g_type_add_interface_static (gcalc_variable_type_id, GCALC_TYPE_HASHABLE, &gcalc_hashable_info);
	GCalcVariable_private_offset = g_type_add_instance_private (gcalc_variable_type_id, sizeof (GCalcVariablePrivate));
	return gcalc_variable_type_id;
}

GType
gcalc_variable_get_type (void)
{
	static volatile gsize gcalc_variable_type_id__once = 0;
	if (g_once_init_enter (&gcalc_variable_type_id__once)) {
		GType gcalc_variable_type_id;
		gcalc_variable_type_id = gcalc_variable_get_type_once ();
		g_once_init_leave (&gcalc_variable_type_id__once, gcalc_variable_type_id);
	}
	return gcalc_variable_type_id__once;
}

static void
_vala_gcalc_variable_get_property (GObject * object,
                                   guint property_id,
                                   GValue * value,
                                   GParamSpec * pspec)
{
	GCalcVariable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_VARIABLE, GCalcVariable);
	switch (property_id) {
		case GCALC_VARIABLE_NAME_PROPERTY:
		g_value_set_string (value, gcalc_math_variable_get_name ((GCalcMathVariable*) self));
		break;
		case GCALC_VARIABLE_VALUE_PROPERTY:
		g_value_set_object (value, gcalc_math_variable_get_value ((GCalcMathVariable*) self));
		break;
		case GCALC_VARIABLE_BIND_PROPERTY:
		g_value_set_object (value, gcalc_math_variable_get_bind ((GCalcMathVariable*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gcalc_variable_set_property (GObject * object,
                                   guint property_id,
                                   const GValue * value,
                                   GParamSpec * pspec)
{
	GCalcVariable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_VARIABLE, GCalcVariable);
	switch (property_id) {
		case GCALC_VARIABLE_NAME_PROPERTY:
		gcalc_math_variable_set_name ((GCalcMathVariable*) self, g_value_get_string (value));
		break;
		case GCALC_VARIABLE_VALUE_PROPERTY:
		gcalc_math_variable_set_value ((GCalcMathVariable*) self, g_value_get_object (value));
		break;
		case GCALC_VARIABLE_BIND_PROPERTY:
		gcalc_math_variable_set_bind ((GCalcMathVariable*) self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

