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

/* gcalc-expression-hash-table.vala
 *
 * Copyright (C) 2019  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 <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "gcalc.h"

enum  {
	GCALC_EXPRESSION_HASH_MAP_0_PROPERTY,
	GCALC_EXPRESSION_HASH_MAP_PARENT_PROPERTY,
	GCALC_EXPRESSION_HASH_MAP_NUM_PROPERTIES
};
static GParamSpec* gcalc_expression_hash_map_properties[GCALC_EXPRESSION_HASH_MAP_NUM_PROPERTIES];
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _GCalcExpressionHashMapPrivate {
	GCalcMathExpression* _parent;
};

static gint GCalcExpressionHashMap_private_offset;
static gpointer gcalc_expression_hash_map_parent_class = NULL;

static void gcalc_expression_hash_map_finalize (GObject * obj);
static GType gcalc_expression_hash_map_get_type_once (void);
static void _vala_gcalc_expression_hash_map_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);
static void _vala_gcalc_expression_hash_map_set_property (GObject * object,
                                                   guint property_id,
                                                   const GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
gcalc_expression_hash_map_get_instance_private (GCalcExpressionHashMap* self)
{
	return G_STRUCT_MEMBER_P (self, GCalcExpressionHashMap_private_offset);
}

void
gcalc_expression_hash_map_add (GCalcExpressionHashMap* self,
                               GCalcMathExpression* exp)
{
	GCalcMathExpression* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (exp != NULL);
	_vala_return_if_fail (GCALC_IS_HASHABLE (exp), "exp is Hashable");
	gee_abstract_map_set ((GeeAbstractMap*) self, (gpointer) ((guintptr) gcalc_hashable_hash (G_TYPE_CHECK_INSTANCE_CAST (exp, GCALC_TYPE_HASHABLE, GCalcHashable))), exp);
	_tmp0_ = self->priv->_parent;
	gcalc_math_expression_set_parent (exp, _tmp0_);
}

void
gcalc_expression_hash_map_remove (GCalcExpressionHashMap* self,
                                  GCalcMathExpression* exp)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (exp != NULL);
	gee_abstract_map_unset ((GeeAbstractMap*) self, (gpointer) ((guintptr) gcalc_hashable_hash (G_TYPE_CHECK_INSTANCE_CAST (exp, GCALC_TYPE_HASHABLE, GCalcHashable))), NULL);
}

GCalcMathExpression*
gcalc_expression_hash_map_find_named (GCalcExpressionHashMap* self,
                                      const gchar* name)
{
	gpointer _tmp0_;
	GCalcMathExpression* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = gee_abstract_map_get ((GeeAbstractMap*) self, (gpointer) ((guintptr) g_str_hash (name)));
	result = (GCalcMathExpression*) _tmp0_;
	return result;
}

GCalcExpressionHashMap*
gcalc_expression_hash_map_construct (GType object_type)
{
	GCalcExpressionHashMap * self = NULL;
	self = (GCalcExpressionHashMap*) gee_hash_map_construct (object_type, G_TYPE_UINT, NULL, NULL, GCALC_TYPE_MATH_EXPRESSION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	return self;
}

GCalcExpressionHashMap*
gcalc_expression_hash_map_new (void)
{
	return gcalc_expression_hash_map_construct (GCALC_TYPE_EXPRESSION_HASH_MAP);
}

GCalcMathExpression*
gcalc_expression_hash_map_get_parent (GCalcExpressionHashMap* self)
{
	GCalcMathExpression* result;
	GCalcMathExpression* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_parent;
	result = _tmp0_;
	return result;
}

void
gcalc_expression_hash_map_set_parent (GCalcExpressionHashMap* self,
                                      GCalcMathExpression* value)
{
	GCalcMathExpression* old_value;
	g_return_if_fail (self != NULL);
	old_value = gcalc_expression_hash_map_get_parent (self);
	if (old_value != value) {
		self->priv->_parent = value;
		g_object_notify_by_pspec ((GObject *) self, gcalc_expression_hash_map_properties[GCALC_EXPRESSION_HASH_MAP_PARENT_PROPERTY]);
	}
}

static void
gcalc_expression_hash_map_class_init (GCalcExpressionHashMapClass * klass,
                                      gpointer klass_data)
{
	gcalc_expression_hash_map_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GCalcExpressionHashMap_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_gcalc_expression_hash_map_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_gcalc_expression_hash_map_set_property;
	G_OBJECT_CLASS (klass)->finalize = gcalc_expression_hash_map_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GCALC_EXPRESSION_HASH_MAP_PARENT_PROPERTY, gcalc_expression_hash_map_properties[GCALC_EXPRESSION_HASH_MAP_PARENT_PROPERTY] = g_param_spec_object ("parent", "parent", "parent", GCALC_TYPE_MATH_EXPRESSION, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
gcalc_expression_hash_map_instance_init (GCalcExpressionHashMap * self,
                                         gpointer klass)
{
	self->priv = gcalc_expression_hash_map_get_instance_private (self);
}

static void
gcalc_expression_hash_map_finalize (GObject * obj)
{
	GCalcExpressionHashMap * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GCALC_TYPE_EXPRESSION_HASH_MAP, GCalcExpressionHashMap);
	G_OBJECT_CLASS (gcalc_expression_hash_map_parent_class)->finalize (obj);
}

/**
 * A hash table using {@link Hashable} objects
 */
static GType
gcalc_expression_hash_map_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GCalcExpressionHashMapClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gcalc_expression_hash_map_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GCalcExpressionHashMap), 0, (GInstanceInitFunc) gcalc_expression_hash_map_instance_init, NULL };
	GType gcalc_expression_hash_map_type_id;
	gcalc_expression_hash_map_type_id = g_type_register_static (GEE_TYPE_HASH_MAP, "GCalcExpressionHashMap", &g_define_type_info, 0);
	GCalcExpressionHashMap_private_offset = g_type_add_instance_private (gcalc_expression_hash_map_type_id, sizeof (GCalcExpressionHashMapPrivate));
	return gcalc_expression_hash_map_type_id;
}

GType
gcalc_expression_hash_map_get_type (void)
{
	static volatile gsize gcalc_expression_hash_map_type_id__once = 0;
	if (g_once_init_enter (&gcalc_expression_hash_map_type_id__once)) {
		GType gcalc_expression_hash_map_type_id;
		gcalc_expression_hash_map_type_id = gcalc_expression_hash_map_get_type_once ();
		g_once_init_leave (&gcalc_expression_hash_map_type_id__once, gcalc_expression_hash_map_type_id);
	}
	return gcalc_expression_hash_map_type_id__once;
}

static void
_vala_gcalc_expression_hash_map_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GCalcExpressionHashMap * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_EXPRESSION_HASH_MAP, GCalcExpressionHashMap);
	switch (property_id) {
		case GCALC_EXPRESSION_HASH_MAP_PARENT_PROPERTY:
		g_value_set_object (value, gcalc_expression_hash_map_get_parent (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_gcalc_expression_hash_map_set_property (GObject * object,
                                              guint property_id,
                                              const GValue * value,
                                              GParamSpec * pspec)
{
	GCalcExpressionHashMap * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GCALC_TYPE_EXPRESSION_HASH_MAP, GCalcExpressionHashMap);
	switch (property_id) {
		case GCALC_EXPRESSION_HASH_MAP_PARENT_PROPERTY:
		gcalc_expression_hash_map_set_parent (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

