/* database-uri-iterator.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from database-uri-iterator.vala, do not modify */

/* This file is part of GNOME Games. License: GPL-3.0+.*/

#include <glib-object.h>
#include "gnome-games.h"
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>

#define GAMES_DATABASE_URI_ITERATOR_SELECT_GAME_RESOURCE_QUERY "\n\t\tSELECT uri FROM game_resources;\n\t"
#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

#define GAMES_TYPE_DATABASE_URI_ITERATOR (games_database_uri_iterator_get_type ())
#define GAMES_DATABASE_URI_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_DATABASE_URI_ITERATOR, GamesDatabaseUriIterator))
#define GAMES_DATABASE_URI_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_DATABASE_URI_ITERATOR, GamesDatabaseUriIteratorClass))
#define GAMES_IS_DATABASE_URI_ITERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_DATABASE_URI_ITERATOR))
#define GAMES_IS_DATABASE_URI_ITERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_DATABASE_URI_ITERATOR))
#define GAMES_DATABASE_URI_ITERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_DATABASE_URI_ITERATOR, GamesDatabaseUriIteratorClass))

typedef struct _GamesDatabaseUriIterator GamesDatabaseUriIterator;
typedef struct _GamesDatabaseUriIteratorClass GamesDatabaseUriIteratorClass;
typedef struct _GamesDatabaseUriIteratorPrivate GamesDatabaseUriIteratorPrivate;
enum  {
	GAMES_DATABASE_URI_ITERATOR_0_PROPERTY,
	GAMES_DATABASE_URI_ITERATOR_NUM_PROPERTIES
};
static GParamSpec* games_database_uri_iterator_properties[GAMES_DATABASE_URI_ITERATOR_NUM_PROPERTIES];
#define _sqlite3_finalize0(var) ((var == NULL) ? NULL : (var = (sqlite3_finalize (var), NULL)))
#define _games_uri_unref0(var) ((var == NULL) ? NULL : (var = (games_uri_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))

struct _GamesDatabaseUriIterator {
	GObject parent_instance;
	GamesDatabaseUriIteratorPrivate * priv;
};

struct _GamesDatabaseUriIteratorClass {
	GObjectClass parent_class;
};

struct _GamesDatabaseUriIteratorPrivate {
	sqlite3_stmt* statement;
	GamesUri* uri;
};

static gint GamesDatabaseUriIterator_private_offset;
static gpointer games_database_uri_iterator_parent_class = NULL;
static GamesUriIteratorIface * games_database_uri_iterator_games_uri_iterator_parent_iface = NULL;

VALA_EXTERN GType games_database_uri_iterator_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GamesDatabaseUriIterator* games_database_uri_iterator_new (sqlite3* database);
VALA_EXTERN GamesDatabaseUriIterator* games_database_uri_iterator_construct (GType object_type,
                                                                 sqlite3* database);
VALA_EXTERN sqlite3_stmt* games_database_prepare (sqlite3* database,
                                      const gchar* query,
                                      GError** error);
static GamesUri* games_database_uri_iterator_real_get (GamesUriIterator* base);
static gboolean games_database_uri_iterator_real_next (GamesUriIterator* base);
static void games_database_uri_iterator_finalize (GObject * obj);
static GType games_database_uri_iterator_get_type_once (void);

static inline gpointer
games_database_uri_iterator_get_instance_private (GamesDatabaseUriIterator* self)
{
	return G_STRUCT_MEMBER_P (self, GamesDatabaseUriIterator_private_offset);
}

GamesDatabaseUriIterator*
games_database_uri_iterator_construct (GType object_type,
                                       sqlite3* database)
{
	GamesDatabaseUriIterator * self = NULL;
	GError* _inner_error0_ = NULL;
	g_return_val_if_fail (database != NULL, NULL);
	self = (GamesDatabaseUriIterator*) g_object_new (object_type, NULL);
	{
		sqlite3_stmt* _tmp0_ = NULL;
		sqlite3_stmt* _tmp1_;
		sqlite3_stmt* _tmp2_;
		_tmp1_ = games_database_prepare (database, GAMES_DATABASE_URI_ITERATOR_SELECT_GAME_RESOURCE_QUERY, &_inner_error0_);
		_tmp0_ = _tmp1_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
		_tmp2_ = _tmp0_;
		_tmp0_ = NULL;
		_sqlite3_finalize0 (self->priv->statement);
		self->priv->statement = _tmp2_;
		_sqlite3_finalize0 (_tmp0_);
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp3_;
		const gchar* _tmp4_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp3_ = e;
		_tmp4_ = _tmp3_->message;
		g_debug ("database-uri-iterator.vala:16: %s", _tmp4_);
		_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 NULL;
	}
	return self;
}

GamesDatabaseUriIterator*
games_database_uri_iterator_new (sqlite3* database)
{
	return games_database_uri_iterator_construct (GAMES_TYPE_DATABASE_URI_ITERATOR, database);
}

static gpointer
_games_uri_ref0 (gpointer self)
{
	return self ? games_uri_ref (self) : NULL;
}

static GamesUri*
games_database_uri_iterator_real_get (GamesUriIterator* base)
{
	GamesDatabaseUriIterator * self;
	GamesUri* _tmp0_;
	GamesUri* _tmp1_;
	GamesUri* result;
	self = (GamesDatabaseUriIterator*) base;
	_tmp0_ = self->priv->uri;
	_tmp1_ = _games_uri_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

static gboolean
games_database_uri_iterator_real_next (GamesUriIterator* base)
{
	GamesDatabaseUriIterator * self;
	sqlite3_stmt* _tmp0_;
	sqlite3_stmt* _tmp1_;
	sqlite3_stmt* _tmp2_;
	const gchar* _tmp3_;
	GamesUri* _tmp4_;
	gboolean result;
	self = (GamesDatabaseUriIterator*) base;
	_tmp0_ = self->priv->statement;
	if (_tmp0_ == NULL) {
		result = FALSE;
		return result;
	}
	_tmp1_ = self->priv->statement;
	if (sqlite3_step (_tmp1_) != SQLITE_ROW) {
		result = FALSE;
		return result;
	}
	_tmp2_ = self->priv->statement;
	_tmp3_ = (const gchar*) sqlite3_column_text (_tmp2_, 0);
	_tmp4_ = games_uri_new (_tmp3_);
	_games_uri_unref0 (self->priv->uri);
	self->priv->uri = _tmp4_;
	result = TRUE;
	return result;
}

static void
games_database_uri_iterator_class_init (GamesDatabaseUriIteratorClass * klass,
                                        gpointer klass_data)
{
	games_database_uri_iterator_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesDatabaseUriIterator_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_database_uri_iterator_finalize;
}

static void
games_database_uri_iterator_games_uri_iterator_interface_init (GamesUriIteratorIface * iface,
                                                               gpointer iface_data)
{
	games_database_uri_iterator_games_uri_iterator_parent_iface = g_type_interface_peek_parent (iface);
	iface->get = (GamesUri* (*) (GamesUriIterator*)) games_database_uri_iterator_real_get;
	iface->next = (gboolean (*) (GamesUriIterator*)) games_database_uri_iterator_real_next;
}

static void
games_database_uri_iterator_instance_init (GamesDatabaseUriIterator * self,
                                           gpointer klass)
{
	self->priv = games_database_uri_iterator_get_instance_private (self);
}

static void
games_database_uri_iterator_finalize (GObject * obj)
{
	GamesDatabaseUriIterator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_DATABASE_URI_ITERATOR, GamesDatabaseUriIterator);
	_sqlite3_finalize0 (self->priv->statement);
	_games_uri_unref0 (self->priv->uri);
	G_OBJECT_CLASS (games_database_uri_iterator_parent_class)->finalize (obj);
}

static GType
games_database_uri_iterator_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesDatabaseUriIteratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_database_uri_iterator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesDatabaseUriIterator), 0, (GInstanceInitFunc) games_database_uri_iterator_instance_init, NULL };
	static const GInterfaceInfo games_uri_iterator_info = { (GInterfaceInitFunc) games_database_uri_iterator_games_uri_iterator_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType games_database_uri_iterator_type_id;
	games_database_uri_iterator_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesDatabaseUriIterator", &g_define_type_info, 0);
	g_type_add_interface_static (games_database_uri_iterator_type_id, GAMES_TYPE_URI_ITERATOR, &games_uri_iterator_info);
	GamesDatabaseUriIterator_private_offset = g_type_add_instance_private (games_database_uri_iterator_type_id, sizeof (GamesDatabaseUriIteratorPrivate));
	return games_database_uri_iterator_type_id;
}

GType
games_database_uri_iterator_get_type (void)
{
	static volatile gsize games_database_uri_iterator_type_id__once = 0;
	if (g_once_init_enter (&games_database_uri_iterator_type_id__once)) {
		GType games_database_uri_iterator_type_id;
		games_database_uri_iterator_type_id = games_database_uri_iterator_get_type_once ();
		g_once_init_leave (&games_database_uri_iterator_type_id__once, games_database_uri_iterator_type_id);
	}
	return games_database_uri_iterator_type_id__once;
}

