/* mame-game-info.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from mame-game-info.vala, do not modify */

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

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <gobject/gvaluecollector.h>
#include "games-mame-plugin.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

#define GAMES_TYPE_MAME_GAME_INFO (games_mame_game_info_get_type ())
#define GAMES_MAME_GAME_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_MAME_GAME_INFO, GamesMameGameInfo))
#define GAMES_MAME_GAME_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_MAME_GAME_INFO, GamesMameGameInfoClass))
#define GAMES_IS_MAME_GAME_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_MAME_GAME_INFO))
#define GAMES_IS_MAME_GAME_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_MAME_GAME_INFO))
#define GAMES_MAME_GAME_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_MAME_GAME_INFO, GamesMameGameInfoClass))

typedef struct _GamesMameGameInfo GamesMameGameInfo;
typedef struct _GamesMameGameInfoClass GamesMameGameInfoClass;
typedef struct _GamesMameGameInfoPrivate GamesMameGameInfoPrivate;
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
typedef struct _GamesParamSpecMameGameInfo GamesParamSpecMameGameInfo;

struct _GamesMameGameInfo {
	GTypeInstance parent_instance;
	volatile int ref_count;
	GamesMameGameInfoPrivate * priv;
};

struct _GamesMameGameInfoClass {
	GTypeClass parent_class;
	void (*finalize) (GamesMameGameInfo *self);
};

struct _GamesParamSpecMameGameInfo {
	GParamSpec parent_instance;
};

static gpointer games_mame_game_info_parent_class = NULL;
static GHashTable* games_mame_game_info_supported_games;
static GHashTable* games_mame_game_info_supported_games = NULL;
static GType games_mame_game_info_type_id = 0;

VALA_EXTERN gpointer games_mame_game_info_ref (gpointer instance);
VALA_EXTERN void games_mame_game_info_unref (gpointer instance);
VALA_EXTERN GParamSpec* games_param_spec_mame_game_info (const gchar* name,
                                             const gchar* nick,
                                             const gchar* blurb,
                                             GType object_type,
                                             GParamFlags flags);
VALA_EXTERN void games_value_set_mame_game_info (GValue* value,
                                     gpointer v_object);
VALA_EXTERN void games_value_take_mame_game_info (GValue* value,
                                      gpointer v_object);
VALA_EXTERN gpointer games_value_get_mame_game_info (const GValue* value);
GType games_mame_game_info_register_type (GTypeModule * module);
VALA_EXTERN GType games_mame_game_info_get_type (void) G_GNUC_CONST ;
VALA_EXTERN GHashTable* games_mame_game_info_get_supported_games (GError** error);
static void _g_free0_ (gpointer var);
VALA_EXTERN GamesMameGameInfo* games_mame_game_info_new (void);
VALA_EXTERN GamesMameGameInfo* games_mame_game_info_construct (GType object_type);
static void games_mame_game_info_finalize (GamesMameGameInfo * obj);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

static gpointer
_g_hash_table_ref0 (gpointer self)
{
	return self ? g_hash_table_ref (self) : NULL;
}

static void
_g_free0_ (gpointer var)
{
	var = (g_free (var), NULL);
}

GHashTable*
games_mame_game_info_get_supported_games (GError** error)
{
	GHashTable* _tmp0_;
	GHashFunc _tmp3_;
	GEqualFunc _tmp4_;
	GHashTable* _tmp5_;
	GBytes* bytes = NULL;
	GBytes* _tmp6_;
	gchar* text = NULL;
	GBytes* _tmp7_;
	gsize _tmp8_ = 0;
	guint8* _tmp9_;
	gchar* _tmp10_;
	gchar** lines = NULL;
	const gchar* _tmp11_;
	gchar** _tmp12_;
	gchar** _tmp13_;
	gint lines_length1;
	gint _lines_size_;
	gchar** _tmp14_;
	gint _tmp14__length1;
	GHashTable* _tmp31_;
	GHashTable* _tmp32_;
	GError* _inner_error0_ = NULL;
	GHashTable* result;
	_tmp0_ = games_mame_game_info_supported_games;
	if (_tmp0_ != NULL) {
		GHashTable* _tmp1_;
		GHashTable* _tmp2_;
		_tmp1_ = games_mame_game_info_supported_games;
		_tmp2_ = _g_hash_table_ref0 (_tmp1_);
		result = _tmp2_;
		return result;
	}
	_tmp3_ = g_str_hash;
	_tmp4_ = g_str_equal;
	_tmp5_ = g_hash_table_new_full (_tmp3_, _tmp4_, _g_free0_, _g_free0_);
	_g_hash_table_unref0 (games_mame_game_info_supported_games);
	games_mame_game_info_supported_games = _tmp5_;
	_tmp6_ = g_resources_lookup_data ("/org/gnome/Games/plugins/mame/supported-games", G_RESOURCE_LOOKUP_FLAGS_NONE, &_inner_error0_);
	bytes = _tmp6_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp7_ = bytes;
	_tmp9_ = g_bytes_get_data (_tmp7_, &_tmp8_);
	_tmp10_ = g_strdup ((const gchar*) _tmp9_);
	text = _tmp10_;
	_tmp11_ = text;
	_tmp13_ = _tmp12_ = g_strsplit (_tmp11_, "\n", 0);
	lines = _tmp13_;
	lines_length1 = _vala_array_length (_tmp12_);
	_lines_size_ = lines_length1;
	_tmp14_ = lines;
	_tmp14__length1 = lines_length1;
	{
		gchar** line_collection = NULL;
		gint line_collection_length1 = 0;
		gint _line_collection_size_ = 0;
		gint line_it = 0;
		line_collection = _tmp14_;
		line_collection_length1 = _tmp14__length1;
		for (line_it = 0; line_it < line_collection_length1; line_it = line_it + 1) {
			gchar* _tmp15_;
			gchar* line = NULL;
			_tmp15_ = g_strdup (line_collection[line_it]);
			line = _tmp15_;
			{
				gchar** parts = NULL;
				const gchar* _tmp16_;
				gchar** _tmp17_;
				gchar** _tmp18_;
				gint parts_length1;
				gint _parts_size_;
				gchar** _tmp19_;
				gint _tmp19__length1;
				gchar* id = NULL;
				gchar** _tmp20_;
				gint _tmp20__length1;
				const gchar* _tmp21_;
				gchar* _tmp22_;
				gchar* name = NULL;
				gchar** _tmp23_;
				gint _tmp23__length1;
				const gchar* _tmp24_;
				gchar* _tmp25_;
				GHashTable* _tmp26_;
				const gchar* _tmp27_;
				gchar* _tmp28_;
				const gchar* _tmp29_;
				gchar* _tmp30_;
				_tmp16_ = line;
				_tmp18_ = _tmp17_ = g_strsplit (_tmp16_, " ", 2);
				parts = _tmp18_;
				parts_length1 = _vala_array_length (_tmp17_);
				_parts_size_ = parts_length1;
				_tmp19_ = parts;
				_tmp19__length1 = parts_length1;
				if (_tmp19__length1 < 2) {
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (line);
					continue;
				}
				_tmp20_ = parts;
				_tmp20__length1 = parts_length1;
				_tmp21_ = _tmp20_[0];
				_tmp22_ = g_strdup (_tmp21_);
				id = _tmp22_;
				_tmp23_ = parts;
				_tmp23__length1 = parts_length1;
				_tmp24_ = _tmp23_[1];
				_tmp25_ = g_strdup (_tmp24_);
				name = _tmp25_;
				_tmp26_ = games_mame_game_info_supported_games;
				_tmp27_ = id;
				_tmp28_ = g_strdup (_tmp27_);
				_tmp29_ = name;
				_tmp30_ = g_strdup (_tmp29_);
				g_hash_table_insert (_tmp26_, _tmp28_, _tmp30_);
				_g_free0 (name);
				_g_free0 (id);
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (line);
			}
		}
	}
	_tmp31_ = games_mame_game_info_supported_games;
	_tmp32_ = _g_hash_table_ref0 (_tmp31_);
	result = _tmp32_;
	lines = (_vala_array_free (lines, lines_length1, (GDestroyNotify) g_free), NULL);
	_g_free0 (text);
	_g_bytes_unref0 (bytes);
	return result;
}

GamesMameGameInfo*
games_mame_game_info_construct (GType object_type)
{
	GamesMameGameInfo* self = NULL;
	self = (GamesMameGameInfo*) g_type_create_instance (object_type);
	return self;
}

GamesMameGameInfo*
games_mame_game_info_new (void)
{
	return games_mame_game_info_construct (GAMES_TYPE_MAME_GAME_INFO);
}

static void
games_value_mame_game_info_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
games_value_mame_game_info_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		games_mame_game_info_unref (value->data[0].v_pointer);
	}
}

static void
games_value_mame_game_info_copy_value (const GValue* src_value,
                                       GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = games_mame_game_info_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
games_value_mame_game_info_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
games_value_mame_game_info_collect_value (GValue* value,
                                          guint n_collect_values,
                                          GTypeCValue* collect_values,
                                          guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		GamesMameGameInfo * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = games_mame_game_info_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
games_value_mame_game_info_lcopy_value (const GValue* value,
                                        guint n_collect_values,
                                        GTypeCValue* collect_values,
                                        guint collect_flags)
{
	GamesMameGameInfo ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = games_mame_game_info_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
games_param_spec_mame_game_info (const gchar* name,
                                 const gchar* nick,
                                 const gchar* blurb,
                                 GType object_type,
                                 GParamFlags flags)
{
	GamesParamSpecMameGameInfo* spec;
	g_return_val_if_fail (g_type_is_a (object_type, GAMES_TYPE_MAME_GAME_INFO), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
games_value_get_mame_game_info (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GAMES_TYPE_MAME_GAME_INFO), NULL);
	return value->data[0].v_pointer;
}

void
games_value_set_mame_game_info (GValue* value,
                                gpointer v_object)
{
	GamesMameGameInfo * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GAMES_TYPE_MAME_GAME_INFO));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GAMES_TYPE_MAME_GAME_INFO));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		games_mame_game_info_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		games_mame_game_info_unref (old);
	}
}

void
games_value_take_mame_game_info (GValue* value,
                                 gpointer v_object)
{
	GamesMameGameInfo * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, GAMES_TYPE_MAME_GAME_INFO));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, GAMES_TYPE_MAME_GAME_INFO));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		games_mame_game_info_unref (old);
	}
}

static void
games_mame_game_info_class_init (GamesMameGameInfoClass * klass,
                                 gpointer klass_data)
{
	games_mame_game_info_parent_class = g_type_class_peek_parent (klass);
	((GamesMameGameInfoClass *) klass)->finalize = games_mame_game_info_finalize;
}

static void
games_mame_game_info_instance_init (GamesMameGameInfo * self,
                                    gpointer klass)
{
	self->ref_count = 1;
}

static void
games_mame_game_info_finalize (GamesMameGameInfo * obj)
{
	GamesMameGameInfo * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_MAME_GAME_INFO, GamesMameGameInfo);
	g_signal_handlers_destroy (self);
}

GType
games_mame_game_info_get_type (void)
{
	return games_mame_game_info_type_id;
}

GType
games_mame_game_info_register_type (GTypeModule * module)
{
	static const GTypeValueTable g_define_type_value_table = { games_value_mame_game_info_init, games_value_mame_game_info_free_value, games_value_mame_game_info_copy_value, games_value_mame_game_info_peek_pointer, "p", games_value_mame_game_info_collect_value, "p", games_value_mame_game_info_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (GamesMameGameInfoClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_mame_game_info_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesMameGameInfo), 0, (GInstanceInitFunc) games_mame_game_info_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	games_mame_game_info_type_id = g_type_register_fundamental (g_type_fundamental_next (), "GamesMameGameInfo", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return games_mame_game_info_type_id;
}

gpointer
games_mame_game_info_ref (gpointer instance)
{
	GamesMameGameInfo * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
games_mame_game_info_unref (gpointer instance)
{
	GamesMameGameInfo * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		GAMES_MAME_GAME_INFO_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

