/* FeatureList.c generated by valac 0.56.17, the Vala compiler
 * generated from FeatureList.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_FEATURE_LIST_0_PROPERTY,
	BIRD_FONT_FEATURE_LIST_NUM_PROPERTIES
};
static GParamSpec* bird_font_feature_list_properties[BIRD_FONT_FEATURE_LIST_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_feature_list_parent_class = NULL;

static gint __lambda67_ (BirdFontFeatureList* self,
                  BirdFontFeature* fa,
                  BirdFontFeature* fb);
static gint ___lambda67__gcompare_data_func (gconstpointer a,
                                      gconstpointer b,
                                      gpointer self);
static void bird_font_feature_list_finalize (GObject * obj);
static GType bird_font_feature_list_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

BirdFontFeatureList*
bird_font_feature_list_construct (GType object_type)
{
	BirdFontFeatureList * self = NULL;
	self = (BirdFontFeatureList*) g_object_new (object_type, NULL);
	return self;
}

BirdFontFeatureList*
bird_font_feature_list_new (void)
{
	return bird_font_feature_list_construct (BIRD_FONT_TYPE_FEATURE_LIST);
}

void
bird_font_feature_list_add (BirdFontFeatureList* self,
                            BirdFontFeature* f)
{
	GeeArrayList* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (f != NULL);
	_tmp0_ = self->features;
	gee_abstract_collection_add ((GeeAbstractCollection*) _tmp0_, f);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gint
__lambda67_ (BirdFontFeatureList* self,
             BirdFontFeature* fa,
             BirdFontFeature* fb)
{
	BirdFontFeature* a = NULL;
	BirdFontFeature* _tmp0_;
	BirdFontFeature* b = NULL;
	BirdFontFeature* _tmp1_;
	GCompareFunc _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp4_;
	gint result;
	g_return_val_if_fail (fa != NULL, 0);
	g_return_val_if_fail (fb != NULL, 0);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (fa, BIRD_FONT_TYPE_FEATURE, BirdFontFeature));
	a = _tmp0_;
	_tmp1_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (fb, BIRD_FONT_TYPE_FEATURE, BirdFontFeature));
	b = _tmp1_;
	_tmp2_ = ((GCompareFunc) g_strcmp0);
	_tmp3_ = a->tag;
	_tmp4_ = b->tag;
	result = _tmp2_ (_tmp3_, _tmp4_);
	_g_object_unref0 (b);
	_g_object_unref0 (a);
	return result;
}

static gint
___lambda67__gcompare_data_func (gconstpointer a,
                                 gconstpointer b,
                                 gpointer self)
{
	gint result;
	result = __lambda67_ ((BirdFontFeatureList*) self, (BirdFontFeature*) a, (BirdFontFeature*) b);
	return result;
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

BirdFontFontData*
bird_font_feature_list_generate_feature_tags (BirdFontFeatureList* self,
                                              GError** error)
{
	BirdFontFontData* fd = NULL;
	BirdFontFontData* _tmp0_;
	GeeArrayList* _tmp1_;
	BirdFontFontData* _tmp2_;
	GeeArrayList* _tmp3_;
	gint _tmp4_;
	gint _tmp5_;
	guint offset = 0U;
	GeeArrayList* _tmp6_;
	gint _tmp7_;
	gint _tmp8_;
	GError* _inner_error0_ = NULL;
	BirdFontFontData* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = bird_font_font_data_new ((guint32) 1024);
	fd = _tmp0_;
	_tmp1_ = self->features;
	gee_list_sort ((GeeList*) _tmp1_, ___lambda67__gcompare_data_func, g_object_ref (self), g_object_unref);
	_tmp2_ = fd;
	_tmp3_ = self->features;
	_tmp4_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp3_);
	_tmp5_ = _tmp4_;
	bird_font_font_data_add_ushort (_tmp2_, (guint16) _tmp5_, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_g_object_unref0 (fd);
		return NULL;
	}
	_tmp6_ = self->features;
	_tmp7_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp6_);
	_tmp8_ = _tmp7_;
	offset = (guint) (2 + (6 * _tmp8_));
	{
		GeeArrayList* _feature_list = NULL;
		GeeArrayList* _tmp9_;
		gint _feature_size = 0;
		GeeArrayList* _tmp10_;
		gint _tmp11_;
		gint _tmp12_;
		gint _feature_index = 0;
		_tmp9_ = self->features;
		_feature_list = _tmp9_;
		_tmp10_ = _feature_list;
		_tmp11_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp10_);
		_tmp12_ = _tmp11_;
		_feature_size = _tmp12_;
		_feature_index = -1;
		while (TRUE) {
			gint _tmp13_;
			gint _tmp14_;
			BirdFontFeature* feature = NULL;
			GeeArrayList* _tmp15_;
			gpointer _tmp16_;
			BirdFontFontData* _tmp17_;
			BirdFontFeature* _tmp18_;
			const gchar* _tmp19_;
			BirdFontFontData* _tmp20_;
			BirdFontFeature* _tmp21_;
			BirdFontFeature* _tmp22_;
			_feature_index = _feature_index + 1;
			_tmp13_ = _feature_index;
			_tmp14_ = _feature_size;
			if (!(_tmp13_ < _tmp14_)) {
				break;
			}
			_tmp15_ = _feature_list;
			_tmp16_ = gee_abstract_list_get ((GeeAbstractList*) _tmp15_, _feature_index);
			feature = (BirdFontFeature*) _tmp16_;
			_tmp17_ = fd;
			_tmp18_ = feature;
			_tmp19_ = _tmp18_->tag;
			bird_font_font_data_add_tag (_tmp17_, _tmp19_);
			_tmp20_ = fd;
			bird_font_font_data_add_ushort (_tmp20_, (guint16) offset, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (feature);
				_g_object_unref0 (fd);
				return NULL;
			}
			_tmp21_ = feature;
			offset += (guint) (4 + (2 * bird_font_feature_get_public_lookups (_tmp21_)));
			_tmp22_ = feature;
			if (bird_font_feature_get_public_lookups (_tmp22_) == 0) {
				BirdFontFeature* _tmp23_;
				const gchar* _tmp24_;
				const gchar* _tmp25_;
				gchar* _tmp26_;
				gchar* _tmp27_;
				_tmp23_ = feature;
				_tmp24_ = _tmp23_->tag;
				_tmp25_ = string_to_string (_tmp24_);
				_tmp26_ = g_strconcat ("No lookups for ", _tmp25_, NULL);
				_tmp27_ = _tmp26_;
				g_warning ("FeatureList.vala:50: %s", _tmp27_);
				_g_free0 (_tmp27_);
			}
			_g_object_unref0 (feature);
		}
	}
	{
		GeeArrayList* _feature_list = NULL;
		GeeArrayList* _tmp28_;
		gint _feature_size = 0;
		GeeArrayList* _tmp29_;
		gint _tmp30_;
		gint _tmp31_;
		gint _feature_index = 0;
		_tmp28_ = self->features;
		_feature_list = _tmp28_;
		_tmp29_ = _feature_list;
		_tmp30_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp29_);
		_tmp31_ = _tmp30_;
		_feature_size = _tmp31_;
		_feature_index = -1;
		while (TRUE) {
			gint _tmp32_;
			gint _tmp33_;
			BirdFontFeature* feature = NULL;
			GeeArrayList* _tmp34_;
			gpointer _tmp35_;
			BirdFontFontData* _tmp36_;
			BirdFontFontData* _tmp37_;
			BirdFontFeature* _tmp38_;
			GeeArrayList* _tmp39_;
			gint _tmp40_;
			gint _tmp41_;
			_feature_index = _feature_index + 1;
			_tmp32_ = _feature_index;
			_tmp33_ = _feature_size;
			if (!(_tmp32_ < _tmp33_)) {
				break;
			}
			_tmp34_ = _feature_list;
			_tmp35_ = gee_abstract_list_get ((GeeAbstractList*) _tmp34_, _feature_index);
			feature = (BirdFontFeature*) _tmp35_;
			_tmp36_ = fd;
			bird_font_font_data_add_ushort (_tmp36_, (guint16) 0, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (feature);
				_g_object_unref0 (fd);
				return NULL;
			}
			_tmp37_ = fd;
			_tmp38_ = feature;
			_tmp39_ = _tmp38_->public_lookups;
			_tmp40_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp39_);
			_tmp41_ = _tmp40_;
			bird_font_font_data_add_ushort (_tmp37_, (guint16) _tmp41_, &_inner_error0_);
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				g_propagate_error (error, _inner_error0_);
				_g_object_unref0 (feature);
				_g_object_unref0 (fd);
				return NULL;
			}
			{
				GeeArrayList* _p_list = NULL;
				BirdFontFeature* _tmp42_;
				GeeArrayList* _tmp43_;
				gint _p_size = 0;
				GeeArrayList* _tmp44_;
				gint _tmp45_;
				gint _tmp46_;
				gint _p_index = 0;
				_tmp42_ = feature;
				_tmp43_ = _tmp42_->public_lookups;
				_p_list = _tmp43_;
				_tmp44_ = _p_list;
				_tmp45_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp44_);
				_tmp46_ = _tmp45_;
				_p_size = _tmp46_;
				_p_index = -1;
				while (TRUE) {
					gint _tmp47_;
					gint _tmp48_;
					gchar* p = NULL;
					GeeArrayList* _tmp49_;
					gpointer _tmp50_;
					BirdFontFontData* _tmp51_;
					BirdFontFeature* _tmp52_;
					BirdFontLookups* _tmp53_;
					const gchar* _tmp54_;
					_p_index = _p_index + 1;
					_tmp47_ = _p_index;
					_tmp48_ = _p_size;
					if (!(_tmp47_ < _tmp48_)) {
						break;
					}
					_tmp49_ = _p_list;
					_tmp50_ = gee_abstract_list_get ((GeeAbstractList*) _tmp49_, _p_index);
					p = (gchar*) _tmp50_;
					_tmp51_ = fd;
					_tmp52_ = feature;
					_tmp53_ = _tmp52_->lookups;
					_tmp54_ = p;
					bird_font_font_data_add_ushort (_tmp51_, bird_font_lookups_find (_tmp53_, _tmp54_), &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						g_propagate_error (error, _inner_error0_);
						_g_free0 (p);
						_g_object_unref0 (feature);
						_g_object_unref0 (fd);
						return NULL;
					}
					_g_free0 (p);
				}
			}
			_g_object_unref0 (feature);
		}
	}
	result = fd;
	return result;
}

static void
bird_font_feature_list_class_init (BirdFontFeatureListClass * klass,
                                   gpointer klass_data)
{
	bird_font_feature_list_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_feature_list_finalize;
}

static void
bird_font_feature_list_instance_init (BirdFontFeatureList * self,
                                      gpointer klass)
{
	GeeArrayList* _tmp0_;
	_tmp0_ = gee_array_list_new (BIRD_FONT_TYPE_FEATURE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	self->features = _tmp0_;
}

static void
bird_font_feature_list_finalize (GObject * obj)
{
	BirdFontFeatureList * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_FEATURE_LIST, BirdFontFeatureList);
	_g_object_unref0 (self->features);
	G_OBJECT_CLASS (bird_font_feature_list_parent_class)->finalize (obj);
}

static GType
bird_font_feature_list_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontFeatureListClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_feature_list_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontFeatureList), 0, (GInstanceInitFunc) bird_font_feature_list_instance_init, NULL };
	GType bird_font_feature_list_type_id;
	bird_font_feature_list_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontFeatureList", &g_define_type_info, 0);
	return bird_font_feature_list_type_id;
}

GType
bird_font_feature_list_get_type (void)
{
	static volatile gsize bird_font_feature_list_type_id__once = 0;
	if (g_once_init_enter (&bird_font_feature_list_type_id__once)) {
		GType bird_font_feature_list_type_id;
		bird_font_feature_list_type_id = bird_font_feature_list_get_type_once ();
		g_once_init_leave (&bird_font_feature_list_type_id__once, bird_font_feature_list_type_id);
	}
	return bird_font_feature_list_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;
}

