/* platform-register.c generated by valac 0.56.18-dirty, the Vala compiler
 * generated from platform-register.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 "gnome-games.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_PLATFORM_REGISTER (games_platform_register_get_type ())
#define GAMES_PLATFORM_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_PLATFORM_REGISTER, GamesPlatformRegister))
#define GAMES_PLATFORM_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_PLATFORM_REGISTER, GamesPlatformRegisterClass))
#define GAMES_IS_PLATFORM_REGISTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_PLATFORM_REGISTER))
#define GAMES_IS_PLATFORM_REGISTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_PLATFORM_REGISTER))
#define GAMES_PLATFORM_REGISTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_PLATFORM_REGISTER, GamesPlatformRegisterClass))

typedef struct _GamesPlatformRegister GamesPlatformRegister;
typedef struct _GamesPlatformRegisterClass GamesPlatformRegisterClass;
typedef struct _GamesPlatformRegisterPrivate GamesPlatformRegisterPrivate;
enum  {
	GAMES_PLATFORM_REGISTER_0_PROPERTY,
	GAMES_PLATFORM_REGISTER_NUM_PROPERTIES
};
static GParamSpec* games_platform_register_properties[GAMES_PLATFORM_REGISTER_NUM_PROPERTIES];
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_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);

struct _GamesPlatformRegister {
	GObject parent_instance;
	GamesPlatformRegisterPrivate * priv;
};

struct _GamesPlatformRegisterClass {
	GObjectClass parent_class;
};

struct _GamesPlatformRegisterPrivate {
	GHashTable* platforms;
};

static gint GamesPlatformRegister_private_offset;
static gpointer games_platform_register_parent_class = NULL;
static GamesPlatformRegister* games_platform_register_instance;
static GamesPlatformRegister* games_platform_register_instance = NULL;

VALA_EXTERN GType games_platform_register_get_type (void) G_GNUC_CONST ;
static GamesPlatformRegister* games_platform_register_new (void);
static GamesPlatformRegister* games_platform_register_construct (GType object_type);
static void _g_free0_ (gpointer var);
static void _g_object_unref0_ (gpointer var);
VALA_EXTERN GamesPlatformRegister* games_platform_register_get_register (void);
VALA_EXTERN void games_platform_register_add_platform (GamesPlatformRegister* self,
                                           GamesPlatform* platform);
VALA_EXTERN GList* games_platform_register_get_all_platforms (GamesPlatformRegister* self);
static gint _games_platform_compare_gcompare_func (gconstpointer a,
                                            gconstpointer b);
VALA_EXTERN GamesPlatform* games_platform_register_get_platform (GamesPlatformRegister* self,
                                                     const gchar* id);
static void games_platform_register_finalize (GObject * obj);
static GType games_platform_register_get_type_once (void);

static inline gpointer
games_platform_register_get_instance_private (GamesPlatformRegister* self)
{
	return G_STRUCT_MEMBER_P (self, GamesPlatformRegister_private_offset);
}

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

static void
_g_object_unref0_ (gpointer var)
{
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
}

static GamesPlatformRegister*
games_platform_register_construct (GType object_type)
{
	GamesPlatformRegister * self = NULL;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	self = (GamesPlatformRegister*) g_object_new (object_type, NULL);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, _g_object_unref0_);
	_g_hash_table_unref0 (self->priv->platforms);
	self->priv->platforms = _tmp2_;
	return self;
}

static GamesPlatformRegister*
games_platform_register_new (void)
{
	return games_platform_register_construct (GAMES_TYPE_PLATFORM_REGISTER);
}

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

GamesPlatformRegister*
games_platform_register_get_register (void)
{
	GamesPlatformRegister* _tmp0_;
	GamesPlatformRegister* _tmp2_;
	GamesPlatformRegister* _tmp3_;
	GamesPlatformRegister* result;
	_tmp0_ = games_platform_register_instance;
	if (_tmp0_ == NULL) {
		GamesPlatformRegister* _tmp1_;
		_tmp1_ = games_platform_register_new ();
		_g_object_unref0 (games_platform_register_instance);
		games_platform_register_instance = _tmp1_;
	}
	_tmp2_ = games_platform_register_instance;
	_tmp3_ = _g_object_ref0 (_tmp2_);
	result = _tmp3_;
	return result;
}

void
games_platform_register_add_platform (GamesPlatformRegister* self,
                                      GamesPlatform* platform)
{
	gchar* platform_id = NULL;
	gchar* _tmp0_;
	GHashTable* _tmp1_;
	GHashTable* _tmp2_;
	gchar* _tmp3_;
	GamesPlatform* _tmp4_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (platform != NULL);
	_tmp0_ = games_platform_get_id (platform);
	platform_id = _tmp0_;
	_tmp1_ = self->priv->platforms;
	_vala_assert (!g_hash_table_contains (_tmp1_, platform_id), "!platforms.contains (platform_id)");
	_tmp2_ = self->priv->platforms;
	_tmp3_ = g_strdup (platform_id);
	_tmp4_ = _g_object_ref0 (platform);
	g_hash_table_insert (_tmp2_, _tmp3_, _tmp4_);
	_g_free0 (platform_id);
}

static gint
_games_platform_compare_gcompare_func (gconstpointer a,
                                       gconstpointer b)
{
	gint result;
	result = games_platform_compare ((GamesPlatform*) a, (GamesPlatform*) b);
	return result;
}

GList*
games_platform_register_get_all_platforms (GamesPlatformRegister* self)
{
	GList* values = NULL;
	GHashTable* _tmp0_;
	GList* _tmp1_;
	GList* _result_ = NULL;
	GList* _tmp2_;
	GList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->platforms;
	_tmp1_ = g_hash_table_get_values (_tmp0_);
	values = _tmp1_;
	_result_ = NULL;
	_tmp2_ = values;
	{
		GList* platform_collection = NULL;
		GList* platform_it = NULL;
		platform_collection = _tmp2_;
		for (platform_it = platform_collection; platform_it != NULL; platform_it = platform_it->next) {
			GamesPlatform* platform = NULL;
			platform = (GamesPlatform*) platform_it->data;
			{
				GamesPlatform* _tmp3_;
				GamesPlatform* _tmp4_;
				_tmp3_ = platform;
				_tmp4_ = _g_object_ref0 (_tmp3_);
				_result_ = g_list_prepend (_result_, _tmp4_);
			}
		}
	}
	_result_ = g_list_sort (_result_, _games_platform_compare_gcompare_func);
	result = _result_;
	(values == NULL) ? NULL : (values = (g_list_free (values), NULL));
	return result;
}

GamesPlatform*
games_platform_register_get_platform (GamesPlatformRegister* self,
                                      const gchar* id)
{
	GHashTable* _tmp0_;
	gconstpointer _tmp1_;
	GamesPlatform* _tmp2_;
	GamesPlatform* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (id != NULL, NULL);
	_tmp0_ = self->priv->platforms;
	_tmp1_ = g_hash_table_lookup (_tmp0_, id);
	_tmp2_ = _g_object_ref0 ((GamesPlatform*) _tmp1_);
	result = _tmp2_;
	return result;
}

static void
games_platform_register_class_init (GamesPlatformRegisterClass * klass,
                                    gpointer klass_data)
{
	games_platform_register_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GamesPlatformRegister_private_offset);
	G_OBJECT_CLASS (klass)->finalize = games_platform_register_finalize;
}

static void
games_platform_register_instance_init (GamesPlatformRegister * self,
                                       gpointer klass)
{
	self->priv = games_platform_register_get_instance_private (self);
}

static void
games_platform_register_finalize (GObject * obj)
{
	GamesPlatformRegister * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GAMES_TYPE_PLATFORM_REGISTER, GamesPlatformRegister);
	_g_hash_table_unref0 (self->priv->platforms);
	G_OBJECT_CLASS (games_platform_register_parent_class)->finalize (obj);
}

static GType
games_platform_register_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GamesPlatformRegisterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) games_platform_register_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GamesPlatformRegister), 0, (GInstanceInitFunc) games_platform_register_instance_init, NULL };
	GType games_platform_register_type_id;
	games_platform_register_type_id = g_type_register_static (G_TYPE_OBJECT, "GamesPlatformRegister", &g_define_type_info, 0);
	GamesPlatformRegister_private_offset = g_type_add_instance_private (games_platform_register_type_id, sizeof (GamesPlatformRegisterPrivate));
	return games_platform_register_type_id;
}

GType
games_platform_register_get_type (void)
{
	static volatile gsize games_platform_register_type_id__once = 0;
	if (g_once_init_enter (&games_platform_register_type_id__once)) {
		GType games_platform_register_type_id;
		games_platform_register_type_id = games_platform_register_get_type_once ();
		g_once_init_leave (&games_platform_register_type_id__once, games_platform_register_type_id);
	}
	return games_platform_register_type_id__once;
}

