/* Alternate.c generated by valac 0.56.17, the Vala compiler
 * generated from Alternate.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-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <gee.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_ALTERNATE_0_PROPERTY,
	BIRD_FONT_ALTERNATE_NUM_PROPERTIES
};
static GParamSpec* bird_font_alternate_properties[BIRD_FONT_ALTERNATE_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)))

static gpointer bird_font_alternate_parent_class = NULL;

static void bird_font_alternate_finalize (GObject * obj);
static GType bird_font_alternate_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

BirdFontAlternate*
bird_font_alternate_construct (GType object_type,
                               const gchar* glyph_name,
                               const gchar* tag)
{
	BirdFontAlternate * self = NULL;
	gchar* _tmp0_;
	GeeArrayList* _tmp1_;
	gchar* _tmp2_;
	g_return_val_if_fail (glyph_name != NULL, NULL);
	g_return_val_if_fail (tag != NULL, NULL);
	self = (BirdFontAlternate*) g_object_new (object_type, NULL);
	_tmp0_ = g_strdup (glyph_name);
	_g_free0 (self->glyph_name);
	self->glyph_name = _tmp0_;
	_tmp1_ = gee_array_list_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, NULL, NULL, NULL);
	_g_object_unref0 (self->alternates);
	self->alternates = _tmp1_;
	_tmp2_ = g_strdup (tag);
	_g_free0 (self->tag);
	self->tag = _tmp2_;
	return self;
}

BirdFontAlternate*
bird_font_alternate_new (const gchar* glyph_name,
                         const gchar* tag)
{
	return bird_font_alternate_construct (BIRD_FONT_TYPE_ALTERNATE, glyph_name, tag);
}

gboolean
bird_font_alternate_is_empty (BirdFontAlternate* self)
{
	GeeArrayList* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->alternates;
	_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_ == 0;
	return result;
}

void
bird_font_alternate_add (BirdFontAlternate* self,
                         const gchar* alternate_name)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (alternate_name != NULL);
	_tmp0_ = self->alternates;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, alternate_name);
}

void
bird_font_alternate_remove_alternate (BirdFontAlternate* self,
                                      const gchar* alt)
{
	gint i = 0;
	GeeArrayList* _tmp10_;
	gint _tmp11_;
	gint _tmp12_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (alt != NULL);
	i = 0;
	{
		GeeArrayList* _a_list = NULL;
		GeeArrayList* _tmp0_;
		gint _a_size = 0;
		GeeArrayList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _a_index = 0;
		_tmp0_ = self->alternates;
		_a_list = _tmp0_;
		_tmp1_ = _a_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_a_size = _tmp3_;
		_a_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			gchar* a = NULL;
			GeeArrayList* _tmp6_;
			gpointer _tmp7_;
			const gchar* _tmp8_;
			gint _tmp9_;
			_a_index = _a_index + 1;
			_tmp4_ = _a_index;
			_tmp5_ = _a_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _a_list;
			_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) _tmp6_, _a_index);
			a = (gchar*) _tmp7_;
			_tmp8_ = a;
			if (g_strcmp0 (_tmp8_, alt) == 0) {
				_g_free0 (a);
				break;
			}
			_tmp9_ = i;
			i = _tmp9_ + 1;
			_g_free0 (a);
		}
	}
	_tmp10_ = self->alternates;
	_tmp11_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp10_);
	_tmp12_ = _tmp11_;
	if (i < _tmp12_) {
		GeeArrayList* _tmp13_;
		gpointer _tmp14_;
		gchar* _tmp15_;
		_tmp13_ = self->alternates;
		_tmp14_ = gee_abstract_list_remove_at ((GeeAbstractList*) _tmp13_, i);
		_tmp15_ = (gchar*) _tmp14_;
		_g_free0 (_tmp15_);
	}
}

void
bird_font_alternate_remove (BirdFontAlternate* self,
                            BirdFontGlyphCollection* g)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (g != NULL);
	_tmp0_ = bird_font_glyph_collection_get_name (g);
	_tmp1_ = _tmp0_;
	bird_font_alternate_remove_alternate (self, _tmp1_);
	_g_free0 (_tmp1_);
}

BirdFontAlternate*
bird_font_alternate_copy (BirdFontAlternate* self)
{
	BirdFontAlternate* n = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	BirdFontAlternate* _tmp2_;
	BirdFontAlternate* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->glyph_name;
	_tmp1_ = self->tag;
	_tmp2_ = bird_font_alternate_new (_tmp0_, _tmp1_);
	n = _tmp2_;
	{
		GeeArrayList* _s_list = NULL;
		GeeArrayList* _tmp3_;
		gint _s_size = 0;
		GeeArrayList* _tmp4_;
		gint _tmp5_;
		gint _tmp6_;
		gint _s_index = 0;
		_tmp3_ = self->alternates;
		_s_list = _tmp3_;
		_tmp4_ = _s_list;
		_tmp5_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp4_);
		_tmp6_ = _tmp5_;
		_s_size = _tmp6_;
		_s_index = -1;
		while (TRUE) {
			gint _tmp7_;
			gint _tmp8_;
			gchar* s = NULL;
			GeeArrayList* _tmp9_;
			gpointer _tmp10_;
			BirdFontAlternate* _tmp11_;
			const gchar* _tmp12_;
			_s_index = _s_index + 1;
			_tmp7_ = _s_index;
			_tmp8_ = _s_size;
			if (!(_tmp7_ < _tmp8_)) {
				break;
			}
			_tmp9_ = _s_list;
			_tmp10_ = gee_abstract_list_get ((GeeAbstractList*) _tmp9_, _s_index);
			s = (gchar*) _tmp10_;
			_tmp11_ = n;
			_tmp12_ = s;
			bird_font_alternate_add (_tmp11_, _tmp12_);
			_g_free0 (s);
		}
	}
	result = n;
	return result;
}

static void
bird_font_alternate_class_init (BirdFontAlternateClass * klass,
                                gpointer klass_data)
{
	bird_font_alternate_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_alternate_finalize;
}

static void
bird_font_alternate_instance_init (BirdFontAlternate * self,
                                   gpointer klass)
{
}

static void
bird_font_alternate_finalize (GObject * obj)
{
	BirdFontAlternate * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_ALTERNATE, BirdFontAlternate);
	_g_free0 (self->glyph_name);
	_g_object_unref0 (self->alternates);
	_g_free0 (self->tag);
	G_OBJECT_CLASS (bird_font_alternate_parent_class)->finalize (obj);
}

static GType
bird_font_alternate_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontAlternateClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_alternate_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontAlternate), 0, (GInstanceInitFunc) bird_font_alternate_instance_init, NULL };
	GType bird_font_alternate_type_id;
	bird_font_alternate_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontAlternate", &g_define_type_info, 0);
	return bird_font_alternate_type_id;
}

GType
bird_font_alternate_get_type (void)
{
	static volatile gsize bird_font_alternate_type_id__once = 0;
	if (g_once_init_enter (&bird_font_alternate_type_id__once)) {
		GType bird_font_alternate_type_id;
		bird_font_alternate_type_id = bird_font_alternate_get_type_once ();
		g_once_init_leave (&bird_font_alternate_type_id__once, bird_font_alternate_type_id);
	}
	return bird_font_alternate_type_id__once;
}

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;
}

