/* string-input-stream.c generated by valac 0.35.5, the Vala compiler
 * generated from string-input-stream.vala, do not modify */

/* This file is part of GNOME Games. License: GPLv3*/

#include <glib.h>
#include <glib-object.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <string.h>


#define GAMES_TYPE_STRING_INPUT_STREAM (games_string_input_stream_get_type ())
#define GAMES_STRING_INPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_STRING_INPUT_STREAM, GamesStringInputStream))
#define GAMES_STRING_INPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_STRING_INPUT_STREAM, GamesStringInputStreamClass))
#define GAMES_IS_STRING_INPUT_STREAM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_STRING_INPUT_STREAM))
#define GAMES_IS_STRING_INPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_STRING_INPUT_STREAM))
#define GAMES_STRING_INPUT_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_STRING_INPUT_STREAM, GamesStringInputStreamClass))

typedef struct _GamesStringInputStream GamesStringInputStream;
typedef struct _GamesStringInputStreamClass GamesStringInputStreamClass;
typedef struct _GamesStringInputStreamPrivate GamesStringInputStreamPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GamesStringInputStream {
	GObject parent_instance;
	GamesStringInputStreamPrivate * priv;
};

struct _GamesStringInputStreamClass {
	GObjectClass parent_class;
};

struct _GamesStringInputStreamPrivate {
	GFile* file;
};


static gpointer games_string_input_stream_parent_class = NULL;

GType games_string_input_stream_get_type (void) G_GNUC_CONST;
#define GAMES_STRING_INPUT_STREAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GAMES_TYPE_STRING_INPUT_STREAM, GamesStringInputStreamPrivate))
enum  {
	GAMES_STRING_INPUT_STREAM_DUMMY_PROPERTY
};
GamesStringInputStream* games_string_input_stream_new (GFile* file);
GamesStringInputStream* games_string_input_stream_construct (GType object_type, GFile* file);
gboolean games_string_input_stream_has_string (GamesStringInputStream* self, gsize offset, const gchar* value, GError** error);
gchar* games_string_input_stream_read_string_for_size (GamesStringInputStream* self, gsize offset, gsize size, GError** error);
gchar* games_string_input_stream_read_string (GamesStringInputStream* self, gsize offset, GError** error);
static void games_string_input_stream_finalize (GObject * obj);


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


GamesStringInputStream* games_string_input_stream_construct (GType object_type, GFile* file) {
	GamesStringInputStream * self = NULL;
	GFile* _tmp0_;
	GFile* _tmp1_;
	g_return_val_if_fail (file != NULL, NULL);
	self = (GamesStringInputStream*) g_object_new (object_type, NULL);
	_tmp0_ = file;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->file);
	self->priv->file = _tmp1_;
	return self;
}


GamesStringInputStream* games_string_input_stream_new (GFile* file) {
	return games_string_input_stream_construct (GAMES_TYPE_STRING_INPUT_STREAM, file);
}


gboolean games_string_input_stream_has_string (GamesStringInputStream* self, gsize offset, const gchar* value, GError** error) {
	gboolean result = FALSE;
	gchar* _tmp0_;
	gsize _tmp1_;
	const gchar* _tmp2_;
	gint _tmp3_;
	gint _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	const gchar* _tmp9_;
	gboolean _tmp10_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (value != NULL, FALSE);
	_tmp1_ = offset;
	_tmp2_ = value;
	_tmp3_ = strlen (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = games_string_input_stream_read_string_for_size (self, _tmp1_, (gsize) _tmp4_, &_inner_error_);
	_tmp0_ = _tmp5_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		gboolean _tmp6_ = FALSE;
		g_propagate_error (error, _inner_error_);
		return _tmp6_;
	}
	_tmp7_ = _tmp0_;
	_tmp0_ = NULL;
	_tmp8_ = _tmp7_;
	_tmp9_ = value;
	_tmp10_ = g_strcmp0 (_tmp8_, _tmp9_) == 0;
	_g_free0 (_tmp8_);
	result = _tmp10_;
	_g_free0 (_tmp0_);
	return result;
}


gchar* games_string_input_stream_read_string (GamesStringInputStream* self, gsize offset, GError** error) {
	gchar* result = NULL;
	GFileInputStream* _tmp0_;
	GFile* _tmp1_;
	GFileInputStream* _tmp2_;
	GDataInputStream* stream;
	GDataInputStream* _tmp3_;
	GDataInputStream* _tmp4_;
	gsize _tmp5_;
	gsize length = 0UL;
	gchar* _tmp6_;
	GDataInputStream* _tmp7_;
	gsize _tmp8_ = 0UL;
	gchar* _tmp9_;
	gchar* _tmp10_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = self->priv->file;
	_tmp2_ = g_file_read (_tmp1_, NULL, &_inner_error_);
	_tmp0_ = _tmp2_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp3_ = g_data_input_stream_new ((GInputStream*) _tmp0_);
	stream = _tmp3_;
	_tmp4_ = stream;
	_tmp5_ = offset;
	g_seekable_seek ((GSeekable*) _tmp4_, (gint64) _tmp5_, G_SEEK_SET, NULL, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (stream);
		_g_object_unref0 (_tmp0_);
		return NULL;
	}
	_tmp7_ = stream;
	_tmp9_ = g_data_input_stream_read_upto (_tmp7_, "\0", (gssize) 1, &_tmp8_, NULL, &_inner_error_);
	length = _tmp8_;
	_tmp6_ = _tmp9_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (stream);
		_g_object_unref0 (_tmp0_);
		return NULL;
	}
	_tmp10_ = _tmp6_;
	_tmp6_ = NULL;
	result = _tmp10_;
	_g_free0 (_tmp6_);
	_g_object_unref0 (stream);
	_g_object_unref0 (_tmp0_);
	return result;
}


gchar* games_string_input_stream_read_string_for_size (GamesStringInputStream* self, gsize offset, gsize size, GError** error) {
	gchar* result = NULL;
	GFileInputStream* stream;
	GFile* _tmp0_;
	GFileInputStream* _tmp1_;
	GFileInputStream* _tmp2_;
	gsize _tmp3_;
	guint8* buffer;
	gsize _tmp4_;
	guint8* _tmp5_;
	gint buffer_length1;
	gint _buffer_size_;
	GFileInputStream* _tmp6_;
	guint8* _tmp7_;
	gint _tmp7__length1;
	guint8* _tmp8_;
	gint _tmp8__length1;
	gchar* _tmp9_;
	GError * _inner_error_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->file;
	_tmp1_ = g_file_read (_tmp0_, NULL, &_inner_error_);
	stream = _tmp1_;
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		return NULL;
	}
	_tmp2_ = stream;
	_tmp3_ = offset;
	G_FILE_INPUT_STREAM_GET_CLASS (_tmp2_)->seek (_tmp2_, (gint64) _tmp3_, G_SEEK_SET, NULL, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		_g_object_unref0 (stream);
		return NULL;
	}
	_tmp4_ = size;
	_tmp5_ = g_new0 (guint8, _tmp4_);
	buffer = _tmp5_;
	buffer_length1 = _tmp4_;
	_buffer_size_ = buffer_length1;
	_tmp6_ = stream;
	_tmp7_ = buffer;
	_tmp7__length1 = buffer_length1;
	g_input_stream_read ((GInputStream*) _tmp6_, _tmp7_, (gsize) _tmp7__length1, NULL, &_inner_error_);
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		g_propagate_error (error, _inner_error_);
		buffer = (g_free (buffer), NULL);
		_g_object_unref0 (stream);
		return NULL;
	}
	_tmp8_ = buffer;
	_tmp8__length1 = buffer_length1;
	_tmp9_ = g_strdup ((const gchar*) _tmp8_);
	result = _tmp9_;
	buffer = (g_free (buffer), NULL);
	_g_object_unref0 (stream);
	return result;
}


static void games_string_input_stream_class_init (GamesStringInputStreamClass * klass) {
	games_string_input_stream_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GamesStringInputStreamPrivate));
	G_OBJECT_CLASS (klass)->finalize = games_string_input_stream_finalize;
}


static void games_string_input_stream_instance_init (GamesStringInputStream * self) {
	self->priv = GAMES_STRING_INPUT_STREAM_GET_PRIVATE (self);
}


static void games_string_input_stream_finalize (GObject * obj) {
	GamesStringInputStream * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_STRING_INPUT_STREAM, GamesStringInputStream);
	_g_object_unref0 (self->priv->file);
	G_OBJECT_CLASS (games_string_input_stream_parent_class)->finalize (obj);
}


GType games_string_input_stream_get_type (void) {
	static volatile gsize games_string_input_stream_type_id__volatile = 0;
	if (g_once_init_enter (&games_string_input_stream_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GamesStringInputStreamClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_string_input_stream_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesStringInputStream), 0, (GInstanceInitFunc) games_string_input_stream_instance_init, NULL };
		GType games_string_input_stream_type_id;
		games_string_input_stream_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesStringInputStream", &g_define_type_info, 0);
		g_once_init_leave (&games_string_input_stream_type_id__volatile, games_string_input_stream_type_id);
	}
	return games_string_input_stream_type_id__volatile;
}



