/* GlyphTable.c generated by valac 0.56.17, the Vala compiler
 * generated from GlyphTable.vala, do not modify */

/*
Copyright (C) 2012 Johan Mattsson

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 3 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.
*/

#include "birdfont.h"
#include <gee.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.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  {
	BIRD_FONT_GLYPH_TABLE_0_PROPERTY,
	BIRD_FONT_GLYPH_TABLE_NUM_PROPERTIES
};
static GParamSpec* bird_font_glyph_table_properties[BIRD_FONT_GLYPH_TABLE_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))

struct _BirdFontGlyphTablePrivate {
	GeeTreeMap* map;
};

static gint BirdFontGlyphTable_private_offset;
static gpointer bird_font_glyph_table_parent_class = NULL;

static void bird_font_glyph_table_finalize (GObject * obj);
static GType bird_font_glyph_table_get_type_once (void);

static inline gpointer
bird_font_glyph_table_get_instance_private (BirdFontGlyphTable* self)
{
	return G_STRUCT_MEMBER_P (self, BirdFontGlyphTable_private_offset);
}

BirdFontGlyphTable*
bird_font_glyph_table_construct (GType object_type)
{
	BirdFontGlyphTable * self = NULL;
	GeeTreeMap* _tmp0_;
	self = (BirdFontGlyphTable*) g_object_new (object_type, NULL);
	_tmp0_ = gee_tree_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, BIRD_FONT_TYPE_GLYPH_COLLECTION, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->map);
	self->priv->map = _tmp0_;
	return self;
}

BirdFontGlyphTable*
bird_font_glyph_table_new (void)
{
	return bird_font_glyph_table_construct (BIRD_FONT_TYPE_GLYPH_TABLE);
}

void
bird_font_glyph_table_remove_all (BirdFontGlyphTable* self)
{
	GeeTreeMap* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->map;
	gee_abstract_map_clear ((GeeAbstractMap*) _tmp0_);
}

void
bird_font_glyph_table_for_each (BirdFontGlyphTable* self,
                                GFunc func,
                                gpointer func_target)
{
	GeeTreeMap* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->map;
	if (G_UNLIKELY (bird_font_is_null (_tmp0_))) {
		g_warning ("GlyphTable.vala:34: No data in table");
		return;
	}
	{
		GeeIterator* _entry_it = NULL;
		GeeTreeMap* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeSet* _tmp4_;
		GeeIterator* _tmp5_;
		GeeIterator* _tmp6_;
		_tmp1_ = self->priv->map;
		_tmp2_ = gee_abstract_map_get_entries ((GeeAbstractMap*) _tmp1_);
		_tmp3_ = _tmp2_;
		_tmp4_ = _tmp3_;
		_tmp5_ = gee_iterable_iterator ((GeeIterable*) _tmp4_);
		_tmp6_ = _tmp5_;
		_g_object_unref0 (_tmp4_);
		_entry_it = _tmp6_;
		while (TRUE) {
			GeeIterator* _tmp7_;
			GeeMapEntry* entry = NULL;
			GeeIterator* _tmp8_;
			gpointer _tmp9_;
			GeeMapEntry* _tmp10_;
			gconstpointer _tmp11_;
			gconstpointer _tmp12_;
			_tmp7_ = _entry_it;
			if (!gee_iterator_next (_tmp7_)) {
				break;
			}
			_tmp8_ = _entry_it;
			_tmp9_ = gee_iterator_get (_tmp8_);
			entry = (GeeMapEntry*) _tmp9_;
			_tmp10_ = entry;
			_tmp11_ = gee_map_entry_get_value (_tmp10_);
			_tmp12_ = _tmp11_;
			func ((BirdFontGlyphCollection*) _tmp12_, func_target);
			_g_object_unref0 (entry);
		}
		_g_object_unref0 (_entry_it);
	}
}

gboolean
bird_font_glyph_table_has_key (BirdFontGlyphTable* self,
                               const gchar* n)
{
	GeeTreeMap* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (n != NULL, FALSE);
	_tmp0_ = self->priv->map;
	result = gee_abstract_map_has_key ((GeeAbstractMap*) _tmp0_, n);
	return result;
}

void
bird_font_glyph_table_remove (BirdFontGlyphTable* self,
                              const gchar* name)
{
	GeeTreeMap* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (name != NULL);
	_tmp0_ = self->priv->map;
	gee_abstract_map_unset ((GeeAbstractMap*) _tmp0_, name, NULL);
}

guint
bird_font_glyph_table_length (BirdFontGlyphTable* self)
{
	GeeTreeMap* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	guint result;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = self->priv->map;
	_tmp1_ = gee_abstract_map_get_size ((GeeAbstractMap*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = (guint) _tmp2_;
	return result;
}

BirdFontGlyphCollection*
bird_font_glyph_table_get (BirdFontGlyphTable* self,
                           const gchar* name)
{
	GeeTreeMap* _tmp0_;
	gpointer _tmp1_;
	BirdFontGlyphCollection* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = self->priv->map;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, name);
	result = (BirdFontGlyphCollection*) _tmp1_;
	return result;
}

BirdFontGlyphCollection*
bird_font_glyph_table_nth (BirdFontGlyphTable* self,
                           guint index)
{
	guint i = 0U;
	BirdFontGlyphCollection* result;
	g_return_val_if_fail (self != NULL, NULL);
	i = (guint) 0;
	{
		GeeIterator* _k_it = NULL;
		GeeTreeMap* _tmp0_;
		GeeSet* _tmp1_;
		GeeSet* _tmp2_;
		GeeSet* _tmp3_;
		GeeIterator* _tmp4_;
		GeeIterator* _tmp5_;
		_tmp0_ = self->priv->map;
		_tmp1_ = gee_abstract_map_get_keys ((GeeAbstractMap*) _tmp0_);
		_tmp2_ = _tmp1_;
		_tmp3_ = _tmp2_;
		_tmp4_ = gee_iterable_iterator ((GeeIterable*) _tmp3_);
		_tmp5_ = _tmp4_;
		_g_object_unref0 (_tmp3_);
		_k_it = _tmp5_;
		while (TRUE) {
			GeeIterator* _tmp6_;
			gchar* k = NULL;
			GeeIterator* _tmp7_;
			gpointer _tmp8_;
			guint _tmp12_;
			_tmp6_ = _k_it;
			if (!gee_iterator_next (_tmp6_)) {
				break;
			}
			_tmp7_ = _k_it;
			_tmp8_ = gee_iterator_get (_tmp7_);
			k = (gchar*) _tmp8_;
			if (i == index) {
				GeeTreeMap* _tmp9_;
				const gchar* _tmp10_;
				gpointer _tmp11_;
				_tmp9_ = self->priv->map;
				_tmp10_ = k;
				_tmp11_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp9_, _tmp10_);
				result = (BirdFontGlyphCollection*) _tmp11_;
				_g_free0 (k);
				_g_object_unref0 (_k_it);
				return result;
			}
			_tmp12_ = i;
			i = _tmp12_ + 1;
			_g_free0 (k);
		}
		_g_object_unref0 (_k_it);
	}
	result = NULL;
	return result;
}

gboolean
bird_font_glyph_table_insert (BirdFontGlyphTable* self,
                              const gchar* key,
                              BirdFontGlyphCollection* g)
{
	GeeTreeMap* _tmp0_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (key != NULL, FALSE);
	g_return_val_if_fail (g != NULL, FALSE);
	_tmp0_ = self->priv->map;
	gee_abstract_map_set ((GeeAbstractMap*) _tmp0_, key, g);
	result = TRUE;
	return result;
}

static void
bird_font_glyph_table_class_init (BirdFontGlyphTableClass * klass,
                                  gpointer klass_data)
{
	bird_font_glyph_table_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &BirdFontGlyphTable_private_offset);
	G_OBJECT_CLASS (klass)->finalize = bird_font_glyph_table_finalize;
}

static void
bird_font_glyph_table_instance_init (BirdFontGlyphTable * self,
                                     gpointer klass)
{
	self->priv = bird_font_glyph_table_get_instance_private (self);
}

static void
bird_font_glyph_table_finalize (GObject * obj)
{
	BirdFontGlyphTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_GLYPH_TABLE, BirdFontGlyphTable);
	_g_object_unref0 (self->priv->map);
	G_OBJECT_CLASS (bird_font_glyph_table_parent_class)->finalize (obj);
}

/** A sorted table of glyphs with search index. */
static GType
bird_font_glyph_table_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontGlyphTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_glyph_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontGlyphTable), 0, (GInstanceInitFunc) bird_font_glyph_table_instance_init, NULL };
	GType bird_font_glyph_table_type_id;
	bird_font_glyph_table_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontGlyphTable", &g_define_type_info, 0);
	BirdFontGlyphTable_private_offset = g_type_add_instance_private (bird_font_glyph_table_type_id, sizeof (BirdFontGlyphTablePrivate));
	return bird_font_glyph_table_type_id;
}

GType
bird_font_glyph_table_get_type (void)
{
	static volatile gsize bird_font_glyph_table_type_id__once = 0;
	if (g_once_init_enter (&bird_font_glyph_table_type_id__once)) {
		GType bird_font_glyph_table_type_id;
		bird_font_glyph_table_type_id = bird_font_glyph_table_get_type_once ();
		g_once_init_leave (&bird_font_glyph_table_type_id__once, bird_font_glyph_table_type_id);
	}
	return bird_font_glyph_table_type_id__once;
}

