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

/*
Copyright (C) 2015 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 <glib.h>
#include <gee.h>
#include <glib-object.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  {
	BIRD_FONT_GLYPH_MASTER_0_PROPERTY,
	BIRD_FONT_GLYPH_MASTER_NUM_PROPERTIES
};
static GParamSpec* bird_font_glyph_master_properties[BIRD_FONT_GLYPH_MASTER_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))

static gpointer bird_font_glyph_master_parent_class = NULL;

static void bird_font_glyph_master_finalize (GObject * obj);
static GType bird_font_glyph_master_get_type_once (void);

BirdFontGlyphMaster*
bird_font_glyph_master_construct (GType object_type)
{
	BirdFontGlyphMaster * self = NULL;
	self = (BirdFontGlyphMaster*) g_object_new (object_type, NULL);
	return self;
}

BirdFontGlyphMaster*
bird_font_glyph_master_new (void)
{
	return bird_font_glyph_master_construct (BIRD_FONT_TYPE_GLYPH_MASTER);
}

BirdFontGlyphMaster*
bird_font_glyph_master_construct_for_id (GType object_type,
                                         const gchar* id)
{
	BirdFontGlyphMaster * self = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (id != NULL, NULL);
	self = (BirdFontGlyphMaster*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (id);
	_g_free0 (self->id);
	self->id = _tmp0_;
	return self;
}

BirdFontGlyphMaster*
bird_font_glyph_master_new_for_id (const gchar* id)
{
	return bird_font_glyph_master_construct_for_id (BIRD_FONT_TYPE_GLYPH_MASTER, id);
}

gchar*
bird_font_glyph_master_get_id (BirdFontGlyphMaster* self)
{
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->id;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

void
bird_font_glyph_master_remove (BirdFontGlyphMaster* self,
                               gint index)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	GeeArrayList* _tmp5_;
	gpointer _tmp6_;
	BirdFontGlyph* _tmp7_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->glyphs;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = index;
	g_return_if_fail ((0 <= _tmp3_) && (_tmp3_ < _tmp2_));
	if (self->selected >= index) {
		gint _tmp4_;
		_tmp4_ = self->selected;
		self->selected = _tmp4_ - 1;
	}
	_tmp5_ = self->glyphs;
	_tmp6_ = gee_abstract_list_remove_at ((GeeAbstractList*) _tmp5_, index);
	_tmp7_ = (BirdFontGlyph*) _tmp6_;
	_g_object_unref0 (_tmp7_);
}

void
bird_font_glyph_master_set_selected (BirdFontGlyphMaster* self,
                                     BirdFontGlyph* g)
{
	gint i = 0;
	g_return_if_fail (self != NULL);
	g_return_if_fail (g != NULL);
	i = 0;
	{
		GeeArrayList* _gl_list = NULL;
		GeeArrayList* _tmp0_;
		gint _gl_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _gl_index = 0;
		_tmp0_ = self->glyphs;
		_gl_list = _tmp0_;
		_tmp1_ = _gl_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_gl_size = _tmp3_;
		_gl_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontGlyph* gl = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			BirdFontGlyph* _tmp8_;
			gint _tmp9_;
			_gl_index = _gl_index + 1;
			_tmp4_ = _gl_index;
			_tmp5_ = _gl_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _gl_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _gl_index);
			gl = (BirdFontGlyph*) _tmp7_;
			_tmp8_ = gl;
			if (_tmp8_ == g) {
				self->selected = i;
				_g_object_unref0 (gl);
				return;
			}
			_tmp9_ = i;
			i = _tmp9_ + 1;
			_g_object_unref0 (gl);
		}
	}
	self->selected = 0;
	g_warning ("GlyphMaster.vala:59: Glyph is not a part of the collection.");
}

void
bird_font_glyph_master_add_glyph (BirdFontGlyphMaster* self,
                                  BirdFontGlyph* g)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (g != NULL);
	_tmp0_ = self->glyphs;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, g);
}

BirdFontGlyph*
bird_font_glyph_master_get_current (BirdFontGlyphMaster* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	GeeArrayList* _tmp8_;
	gint _tmp9_;
	gint _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	gchar* _tmp14_;
	BirdFontGlyph* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->glyphs;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = self->selected;
	if (G_LIKELY ((0 <= _tmp3_) && (_tmp3_ < _tmp2_))) {
		GeeArrayList* _tmp4_;
		gpointer _tmp5_;
		_tmp4_ = self->glyphs;
		_tmp5_ = gee_abstract_list_get ((GeeAbstractList*) _tmp4_, self->selected);
		result = (BirdFontGlyph*) _tmp5_;
		return result;
	}
	_tmp6_ = g_strdup_printf ("%i", self->selected);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->glyphs;
	_tmp9_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp8_);
	_tmp10_ = _tmp9_;
	_tmp11_ = g_strdup_printf ("%i", _tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = g_strconcat ("No glyph ", _tmp7_, " glyphs.size: ", _tmp12_, NULL);
	_tmp14_ = _tmp13_;
	g_warning ("GlyphMaster.vala:71: %s", _tmp14_);
	_g_free0 (_tmp14_);
	_g_free0 (_tmp12_);
	_g_free0 (_tmp7_);
	result = NULL;
	return result;
}

void
bird_font_glyph_master_insert_glyph (BirdFontGlyphMaster* self,
                                     BirdFontGlyph* g,
                                     gboolean selected_glyph)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (g != NULL);
	_tmp0_ = self->glyphs;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, g);
	if (selected_glyph) {
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		_tmp1_ = self->glyphs;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		self->selected = _tmp3_ - 1;
	}
}

void
bird_font_glyph_master_set_selected_version (BirdFontGlyphMaster* self,
                                             gint version_id)
{
	gint i = 0;
	g_return_if_fail (self != NULL);
	i = 0;
	{
		GeeArrayList* _g_list = NULL;
		GeeArrayList* _tmp0_;
		gint _g_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _g_index = 0;
		_tmp0_ = self->glyphs;
		_g_list = _tmp0_;
		_tmp1_ = _g_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_g_size = _tmp3_;
		_g_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			BirdFontGlyph* g = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			BirdFontGlyph* _tmp8_;
			gint _tmp9_;
			_g_index = _g_index + 1;
			_tmp4_ = _g_index;
			_tmp5_ = _g_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _g_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _g_index);
			g = (BirdFontGlyph*) _tmp7_;
			_tmp8_ = g;
			if (_tmp8_->version_id == version_id) {
				self->selected = i;
				_g_object_unref0 (g);
				break;
			}
			_tmp9_ = i;
			i = _tmp9_ + 1;
			_g_object_unref0 (g);
		}
	}
}

gint
bird_font_glyph_master_get_last_id (BirdFontGlyphMaster* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	GeeArrayList* _tmp3_;
	GeeArrayList* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gpointer _tmp7_;
	BirdFontGlyph* _tmp8_;
	gint _tmp9_;
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->glyphs;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	g_return_val_if_fail (_tmp2_ > 0, 0);
	_tmp3_ = self->glyphs;
	_tmp4_ = self->glyphs;
	_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp3_, _tmp6_ - 1);
	_tmp8_ = (BirdFontGlyph*) _tmp7_;
	_tmp9_ = _tmp8_->version_id;
	_g_object_unref0 (_tmp8_);
	result = _tmp9_;
	return result;
}

BirdFontGlyphMaster*
bird_font_glyph_master_copy_deep (BirdFontGlyphMaster* self)
{
	BirdFontGlyphMaster* n = NULL;
	BirdFontGlyphMaster* _tmp0_;
	BirdFontGlyphMaster* _tmp14_;
	BirdFontGlyphMaster* _tmp15_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	BirdFontGlyphMaster* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = bird_font_glyph_master_new ();
	n = _tmp0_;
	{
		GeeArrayList* _g_list = NULL;
		GeeArrayList* _tmp1_;
		gint _g_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _g_index = 0;
		_tmp1_ = self->glyphs;
		_g_list = _tmp1_;
		_tmp2_ = _g_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_g_size = _tmp4_;
		_g_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontGlyph* g = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			BirdFontGlyphMaster* _tmp9_;
			GeeArrayList* _tmp10_;
			BirdFontGlyph* _tmp11_;
			BirdFontGlyph* _tmp12_;
			BirdFontGlyph* _tmp13_;
			_g_index = _g_index + 1;
			_tmp5_ = _g_index;
			_tmp6_ = _g_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _g_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _g_index);
			g = (BirdFontGlyph*) _tmp8_;
			_tmp9_ = n;
			_tmp10_ = _tmp9_->glyphs;
			_tmp11_ = g;
			_tmp12_ = bird_font_glyph_copy (_tmp11_);
			_tmp13_ = _tmp12_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp10_, _tmp13_);
			_g_object_unref0 (_tmp13_);
			_g_object_unref0 (g);
		}
	}
	_tmp14_ = n;
	_tmp14_->selected = self->selected;
	_tmp15_ = n;
	_tmp16_ = self->id;
	_tmp17_ = g_strdup (_tmp16_);
	_g_free0 (_tmp15_->id);
	_tmp15_->id = _tmp17_;
	result = n;
	return result;
}

BirdFontGlyphMaster*
bird_font_glyph_master_copy (BirdFontGlyphMaster* self)
{
	BirdFontGlyphMaster* n = NULL;
	BirdFontGlyphMaster* _tmp0_;
	BirdFontGlyphMaster* _tmp12_;
	BirdFontGlyphMaster* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	BirdFontGlyphMaster* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = bird_font_glyph_master_new ();
	n = _tmp0_;
	{
		GeeArrayList* _g_list = NULL;
		GeeArrayList* _tmp1_;
		gint _g_size = 0;
		GeeArrayList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _g_index = 0;
		_tmp1_ = self->glyphs;
		_g_list = _tmp1_;
		_tmp2_ = _g_list;
		_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_g_size = _tmp4_;
		_g_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			BirdFontGlyph* g = NULL;
			GeeArrayList* _tmp7_;
			gpointer _tmp8_;
			BirdFontGlyphMaster* _tmp9_;
			GeeArrayList* _tmp10_;
			BirdFontGlyph* _tmp11_;
			_g_index = _g_index + 1;
			_tmp5_ = _g_index;
			_tmp6_ = _g_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _g_list;
			_tmp8_ = gee_abstract_list_get ((GeeAbstractList*) _tmp7_, _g_index);
			g = (BirdFontGlyph*) _tmp8_;
			_tmp9_ = n;
			_tmp10_ = _tmp9_->glyphs;
			_tmp11_ = g;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp10_, _tmp11_);
			_g_object_unref0 (g);
		}
	}
	_tmp12_ = n;
	_tmp12_->selected = self->selected;
	_tmp13_ = n;
	_tmp14_ = self->id;
	_tmp15_ = g_strdup (_tmp14_);
	_g_free0 (_tmp13_->id);
	_tmp13_->id = _tmp15_;
	result = n;
	return result;
}

static void
bird_font_glyph_master_class_init (BirdFontGlyphMasterClass * klass,
                                   gpointer klass_data)
{
	bird_font_glyph_master_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_glyph_master_finalize;
}

static void
bird_font_glyph_master_instance_init (BirdFontGlyphMaster * self,
                                      gpointer klass)
{
	GeeArrayList* _tmp0_;
	gchar* _tmp1_;
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_GLYPH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->glyphs = _tmp0_;
	self->selected = 0;
	_tmp1_ = g_strdup ("Master 1");
	self->id = _tmp1_;
}

static void
bird_font_glyph_master_finalize (GObject * obj)
{
	BirdFontGlyphMaster * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_GLYPH_MASTER, BirdFontGlyphMaster);
	_g_object_unref0 (self->glyphs);
	_g_free0 (self->id);
	G_OBJECT_CLASS (bird_font_glyph_master_parent_class)->finalize (obj);
}

static GType
bird_font_glyph_master_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontGlyphMasterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_glyph_master_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontGlyphMaster), 0, (GInstanceInitFunc) bird_font_glyph_master_instance_init, NULL };
	GType bird_font_glyph_master_type_id;
	bird_font_glyph_master_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontGlyphMaster", &g_define_type_info, 0);
	return bird_font_glyph_master_type_id;
}

GType
bird_font_glyph_master_get_type (void)
{
	static volatile gsize bird_font_glyph_master_type_id__once = 0;
	if (g_once_init_enter (&bird_font_glyph_master_type_id__once)) {
		GType bird_font_glyph_master_type_id;
		bird_font_glyph_master_type_id = bird_font_glyph_master_get_type_once ();
		g_once_init_leave (&bird_font_glyph_master_type_id__once, bird_font_glyph_master_type_id);
	}
	return bird_font_glyph_master_type_id__once;
}

