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

/*
Copyright (C) 2012, 2013 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 <gio/gio.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  {
	BIRD_FONT_OTF_INPUT_STREAM_0_PROPERTY,
	BIRD_FONT_OTF_INPUT_STREAM_NUM_PROPERTIES
};
static GParamSpec* bird_font_otf_input_stream_properties[BIRD_FONT_OTF_INPUT_STREAM_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)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

static gpointer bird_font_otf_input_stream_parent_class = NULL;

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

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

BirdFontOtfInputStream*
bird_font_otf_input_stream_construct (GType object_type,
                                      GFileInputStream* i,
                                      GError** error)
{
	BirdFontOtfInputStream * self = NULL;
	GDataInputStream* _tmp0_;
	GFileInputStream* _tmp1_;
	g_return_val_if_fail (i != NULL, NULL);
	self = (BirdFontOtfInputStream*) g_object_new (object_type, NULL);
	_tmp0_ = g_data_input_stream_new ((GInputStream*) i);
	_g_object_unref0 (self->din);
	self->din = _tmp0_;
	_tmp1_ = _g_object_ref0 (i);
	_g_object_unref0 (self->fin);
	self->fin = _tmp1_;
	return self;
}

BirdFontOtfInputStream*
bird_font_otf_input_stream_new (GFileInputStream* i,
                                GError** error)
{
	return bird_font_otf_input_stream_construct (BIRD_FONT_TYPE_OTF_INPUT_STREAM, i, error);
}

void
bird_font_otf_input_stream_seek (BirdFontOtfInputStream* self,
                                 gint64 pos,
                                 GError** error)
{
	GFileInputStream* _tmp0_;
	gint64 p = 0LL;
	GFileInputStream* _tmp1_;
	GFileInputStream* _tmp2_;
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->fin;
	_vala_return_if_fail (G_TYPE_INSTANCE_GET_CLASS (_tmp0_, g_file_input_stream_get_type (), GFileInputStreamClass)->can_seek (_tmp0_), "fin.can_seek ()");
	_tmp1_ = self->fin;
	p = G_TYPE_INSTANCE_GET_CLASS (_tmp1_, g_file_input_stream_get_type (), GFileInputStreamClass)->tell (_tmp1_);
	_tmp2_ = self->fin;
	G_TYPE_INSTANCE_GET_CLASS (_tmp2_, g_file_input_stream_get_type (), GFileInputStreamClass)->seek (_tmp2_, pos - p, G_SEEK_CUR, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return;
	}
}

guint8
bird_font_otf_input_stream_read_byte (BirdFontOtfInputStream* self,
                                      GError** error)
{
	guint8 _tmp0_ = 0U;
	GDataInputStream* _tmp1_;
	GError* _inner_error0_ = NULL;
	guint8 result;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp1_ = self->din;
	_tmp0_ = g_data_input_stream_read_byte (_tmp1_, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		guint8 _tmp2_ = 0U;
		g_propagate_error (error, _inner_error0_);
		return _tmp2_;
	}
	result = _tmp0_;
	return result;
}

void
bird_font_otf_input_stream_close (BirdFontOtfInputStream* self)
{
	GError* _inner_error0_ = NULL;
	g_return_if_fail (self != NULL);
	{
		GFileInputStream* _tmp0_;
		GDataInputStream* _tmp1_;
		_tmp0_ = self->fin;
		g_input_stream_close ((GInputStream*) _tmp0_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_IO_ERROR) {
				goto __catch0_g_io_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
		_tmp1_ = self->din;
		g_input_stream_close ((GInputStream*) _tmp1_, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			if (_inner_error0_->domain == G_IO_ERROR) {
				goto __catch0_g_io_error;
			}
			g_critical ("file %s: line %d: unexpected 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;
		}
	}
	goto __finally0;
	__catch0_g_io_error:
	{
		GError* e = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp2_ = e;
		_tmp3_ = _tmp2_->message;
		g_warning ("OtfInputStream.vala:43: %s", _tmp3_);
		_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;
	}
}

static void
bird_font_otf_input_stream_class_init (BirdFontOtfInputStreamClass * klass,
                                       gpointer klass_data)
{
	bird_font_otf_input_stream_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = bird_font_otf_input_stream_finalize;
}

static void
bird_font_otf_input_stream_instance_init (BirdFontOtfInputStream * self,
                                          gpointer klass)
{
}

static void
bird_font_otf_input_stream_finalize (GObject * obj)
{
	BirdFontOtfInputStream * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, BIRD_FONT_TYPE_OTF_INPUT_STREAM, BirdFontOtfInputStream);
	_g_object_unref0 (self->fin);
	_g_object_unref0 (self->din);
	G_OBJECT_CLASS (bird_font_otf_input_stream_parent_class)->finalize (obj);
}

/** Reader for otf data types. */
static GType
bird_font_otf_input_stream_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (BirdFontOtfInputStreamClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) bird_font_otf_input_stream_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (BirdFontOtfInputStream), 0, (GInstanceInitFunc) bird_font_otf_input_stream_instance_init, NULL };
	GType bird_font_otf_input_stream_type_id;
	bird_font_otf_input_stream_type_id = g_type_register_static (G_TYPE_OBJECT, "BirdFontOtfInputStream", &g_define_type_info, 0);
	return bird_font_otf_input_stream_type_id;
}

GType
bird_font_otf_input_stream_get_type (void)
{
	static volatile gsize bird_font_otf_input_stream_type_id__once = 0;
	if (g_once_init_enter (&bird_font_otf_input_stream_type_id__once)) {
		GType bird_font_otf_input_stream_type_id;
		bird_font_otf_input_stream_type_id = bird_font_otf_input_stream_get_type_once ();
		g_once_init_leave (&bird_font_otf_input_stream_type_id__once, bird_font_otf_input_stream_type_id);
	}
	return bird_font_otf_input_stream_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;
}

