/* dictionary-list.c generated by valac 0.56.19, the Vala compiler
 * generated from dictionary-list.vala, do not modify */

/*
 * Copyright (C) 2011-2014 Daiki Ueno <ueno@gnu.org>
 * Copyright (C) 2011-2014 Red Hat, Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "libkkc/libkkc.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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  {
	KKC_DICTIONARY_LIST_0_PROPERTY,
	KKC_DICTIONARY_LIST_SIZE_PROPERTY,
	KKC_DICTIONARY_LIST_NUM_PROPERTIES
};
static GParamSpec* kkc_dictionary_list_properties[KKC_DICTIONARY_LIST_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _KkcDictionaryListPrivate {
	GeeList* dictionaries;
};

static gint KkcDictionaryList_private_offset;
static gpointer kkc_dictionary_list_parent_class = NULL;

static KkcDictionaryCallbackReturn __lambda9_ (KkcDictionaryList* self,
                                        KkcDictionary* dictionary);
static KkcDictionaryCallbackReturn ___lambda9__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                                                 gpointer self);
static void kkc_dictionary_list_finalize (GObject * obj);
static GType kkc_dictionary_list_get_type_once (void);
static void _vala_kkc_dictionary_list_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

/**
     * Type to specify how a dictionary callback is handled.
     */
static GType
kkc_dictionary_callback_return_get_type_once (void)
{
	static const GEnumValue values[] = {{KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE, "KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE", "continue"}, {KKC_DICTIONARY_CALLBACK_RETURN_REMOVE, "KKC_DICTIONARY_CALLBACK_RETURN_REMOVE", "remove"}, {0, NULL, NULL}};
	GType kkc_dictionary_callback_return_type_id;
	kkc_dictionary_callback_return_type_id = g_enum_register_static ("KkcDictionaryCallbackReturn", values);
	return kkc_dictionary_callback_return_type_id;
}

GType
kkc_dictionary_callback_return_get_type (void)
{
	static volatile gsize kkc_dictionary_callback_return_type_id__once = 0;
	if (g_once_init_enter (&kkc_dictionary_callback_return_type_id__once)) {
		GType kkc_dictionary_callback_return_type_id;
		kkc_dictionary_callback_return_type_id = kkc_dictionary_callback_return_get_type_once ();
		g_once_init_leave (&kkc_dictionary_callback_return_type_id__once, kkc_dictionary_callback_return_type_id);
	}
	return kkc_dictionary_callback_return_type_id__once;
}

static inline gpointer
kkc_dictionary_list_get_instance_private (KkcDictionaryList* self)
{
	return G_STRUCT_MEMBER_P (self, KkcDictionaryList_private_offset);
}

/**
         * Register dictionary.
         *
         * @param dictionary a dictionary
         */
void
kkc_dictionary_list_add (KkcDictionaryList* self,
                         KkcDictionary* dictionary)
{
	GeeList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dictionary != NULL);
	_tmp0_ = self->priv->dictionaries;
	gee_collection_add ((GeeCollection*) _tmp0_, dictionary);
}

/**
         * Unregister dictionary.
         *
         * @param dictionary a dictionary
         */
void
kkc_dictionary_list_remove (KkcDictionaryList* self,
                            KkcDictionary* dictionary)
{
	GeeList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (dictionary != NULL);
	_tmp0_ = self->priv->dictionaries;
	gee_collection_remove ((GeeCollection*) _tmp0_, dictionary);
}

/**
         * Remove all dictionaries.
         */
void
kkc_dictionary_list_clear (KkcDictionaryList* self)
{
	GeeList* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->dictionaries;
	gee_collection_clear ((GeeCollection*) _tmp0_);
}

/**
         * Call function with dictionaries.
         *
         * @param type type of dictionary
         * @param callback callback
         */
void
kkc_dictionary_list_call (KkcDictionaryList* self,
                          GType* type,
                          KkcDictionaryListDictionaryCallback callback,
                          gpointer callback_target)
{
	g_return_if_fail (self != NULL);
	{
		GeeList* _dictionary_list = NULL;
		GeeList* _tmp0_;
		gint _dictionary_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _dictionary_index = 0;
		_tmp0_ = self->priv->dictionaries;
		_dictionary_list = _tmp0_;
		_tmp1_ = _dictionary_list;
		_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_dictionary_size = _tmp3_;
		_dictionary_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			KkcDictionary* dictionary = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			gboolean _tmp8_ = FALSE;
			gboolean _tmp9_ = FALSE;
			_dictionary_index = _dictionary_index + 1;
			_tmp4_ = _dictionary_index;
			_tmp5_ = _dictionary_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _dictionary_list;
			_tmp7_ = gee_list_get (_tmp6_, _dictionary_index);
			dictionary = (KkcDictionary*) _tmp7_;
			if (type == NULL) {
				_tmp9_ = TRUE;
			} else {
				KkcDictionary* _tmp10_;
				_tmp10_ = dictionary;
				_tmp9_ = g_type_is_a (G_TYPE_FROM_INSTANCE ((GObject*) _tmp10_), *type);
			}
			if (_tmp9_) {
				KkcDictionary* _tmp11_;
				_tmp11_ = dictionary;
				_tmp8_ = callback (_tmp11_, callback_target) == KKC_DICTIONARY_CALLBACK_RETURN_REMOVE;
			} else {
				_tmp8_ = FALSE;
			}
			if (_tmp8_) {
				_g_object_unref0 (dictionary);
				return;
			}
			_g_object_unref0 (dictionary);
		}
	}
}

/**
         * Save dictionaries on to disk.
         */
static KkcDictionaryCallbackReturn
__lambda9_ (KkcDictionaryList* self,
            KkcDictionary* dictionary)
{
	GError* _inner_error0_ = NULL;
	KkcDictionaryCallbackReturn result;
	g_return_val_if_fail (dictionary != NULL, 0);
	{
		kkc_dictionary_save (dictionary, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp0_;
		const gchar* _tmp1_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp0_ = e;
		_tmp1_ = _tmp0_->message;
		g_warning ("dictionary-list.vala:101: can't save dictionary: %s", _tmp1_);
		_g_error_free0 (e);
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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 0;
	}
	result = KKC_DICTIONARY_CALLBACK_RETURN_CONTINUE;
	return result;
}

static KkcDictionaryCallbackReturn
___lambda9__kkc_dictionary_list_dictionary_callback (KkcDictionary* dictionary,
                                                     gpointer self)
{
	KkcDictionaryCallbackReturn result;
	result = __lambda9_ ((KkcDictionaryList*) self, dictionary);
	return result;
}

void
kkc_dictionary_list_save (KkcDictionaryList* self)
{
	g_return_if_fail (self != NULL);
	kkc_dictionary_list_call (self, NULL, ___lambda9__kkc_dictionary_list_dictionary_callback, self);
}

KkcDictionaryList*
kkc_dictionary_list_construct (GType object_type)
{
	KkcDictionaryList * self = NULL;
	self = (KkcDictionaryList*) g_object_new (object_type, NULL);
	return self;
}

KkcDictionaryList*
kkc_dictionary_list_new (void)
{
	return kkc_dictionary_list_construct (KKC_TYPE_DICTIONARY_LIST);
}

gint
kkc_dictionary_list_get_size (KkcDictionaryList* self)
{
	gint result;
	GeeList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = self->priv->dictionaries;
	_tmp1_ = gee_collection_get_size ((GeeCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static void
kkc_dictionary_list_class_init (KkcDictionaryListClass * klass,
                                gpointer klass_data)
{
	kkc_dictionary_list_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &KkcDictionaryList_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_kkc_dictionary_list_get_property;
	G_OBJECT_CLASS (klass)->finalize = kkc_dictionary_list_finalize;
	/**
	         * The number of dictionaries registered.
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), KKC_DICTIONARY_LIST_SIZE_PROPERTY, kkc_dictionary_list_properties[KKC_DICTIONARY_LIST_SIZE_PROPERTY] = g_param_spec_int ("size", "size", "size", G_MININT, G_MAXINT, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
kkc_dictionary_list_instance_init (KkcDictionaryList * self,
                                   gpointer klass)
{
	GeeArrayList* _tmp0_;
	self->priv = kkc_dictionary_list_get_instance_private (self);
	_tmp0_ = gee_array_list_new (KKC_TYPE_DICTIONARY, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->priv->dictionaries = (GeeList*) _tmp0_;
}

static void
kkc_dictionary_list_finalize (GObject * obj)
{
	KkcDictionaryList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, KKC_TYPE_DICTIONARY_LIST, KkcDictionaryList);
	_g_object_unref0 (self->priv->dictionaries);
	G_OBJECT_CLASS (kkc_dictionary_list_parent_class)->finalize (obj);
}

static GType
kkc_dictionary_list_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (KkcDictionaryListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) kkc_dictionary_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (KkcDictionaryList), 0, (GInstanceInitFunc) kkc_dictionary_list_instance_init, NULL };
	GType kkc_dictionary_list_type_id;
	kkc_dictionary_list_type_id = g_type_register_static (G_TYPE_OBJECT, "KkcDictionaryList", &g_define_type_info, 0);
	KkcDictionaryList_private_offset = g_type_add_instance_private (kkc_dictionary_list_type_id, sizeof (KkcDictionaryListPrivate));
	return kkc_dictionary_list_type_id;
}

GType
kkc_dictionary_list_get_type (void)
{
	static volatile gsize kkc_dictionary_list_type_id__once = 0;
	if (g_once_init_enter (&kkc_dictionary_list_type_id__once)) {
		GType kkc_dictionary_list_type_id;
		kkc_dictionary_list_type_id = kkc_dictionary_list_get_type_once ();
		g_once_init_leave (&kkc_dictionary_list_type_id__once, kkc_dictionary_list_type_id);
	}
	return kkc_dictionary_list_type_id__once;
}

static void
_vala_kkc_dictionary_list_get_property (GObject * object,
                                        guint property_id,
                                        GValue * value,
                                        GParamSpec * pspec)
{
	KkcDictionaryList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, KKC_TYPE_DICTIONARY_LIST, KkcDictionaryList);
	switch (property_id) {
		case KKC_DICTIONARY_LIST_SIZE_PROPERTY:
		g_value_set_int (value, kkc_dictionary_list_get_size (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

