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

#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE (sway_notification_center_ordered_hash_table_get_type ())
#define SWAY_NOTIFICATION_CENTER_ORDERED_HASH_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE, SwayNotificationCenterOrderedHashTable))
#define SWAY_NOTIFICATION_CENTER_ORDERED_HASH_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE, SwayNotificationCenterOrderedHashTableClass))
#define SWAY_NOTIFICATION_CENTER_IS_ORDERED_HASH_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE))
#define SWAY_NOTIFICATION_CENTER_IS_ORDERED_HASH_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE))
#define SWAY_NOTIFICATION_CENTER_ORDERED_HASH_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE, SwayNotificationCenterOrderedHashTableClass))

typedef struct _SwayNotificationCenterOrderedHashTable SwayNotificationCenterOrderedHashTable;
typedef struct _SwayNotificationCenterOrderedHashTableClass SwayNotificationCenterOrderedHashTableClass;
typedef struct _SwayNotificationCenterOrderedHashTablePrivate SwayNotificationCenterOrderedHashTablePrivate;
#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))
typedef struct _SwayNotificationCenterParamSpecOrderedHashTable SwayNotificationCenterParamSpecOrderedHashTable;

struct _SwayNotificationCenterOrderedHashTable {
	GTypeInstance parent_instance;
	volatile int ref_count;
	SwayNotificationCenterOrderedHashTablePrivate * priv;
};

struct _SwayNotificationCenterOrderedHashTableClass {
	GTypeClass parent_class;
	void (*finalize) (SwayNotificationCenterOrderedHashTable *self);
};

struct _SwayNotificationCenterOrderedHashTablePrivate {
	GType t_type;
	GBoxedCopyFunc t_dup_func;
	GDestroyNotify t_destroy_func;
	GHashTable* hash_table;
	GList* order;
};

struct _SwayNotificationCenterParamSpecOrderedHashTable {
	GParamSpec parent_instance;
};

static gint SwayNotificationCenterOrderedHashTable_private_offset;
static gpointer sway_notification_center_ordered_hash_table_parent_class = NULL;

VALA_EXTERN gpointer sway_notification_center_ordered_hash_table_ref (gpointer instance);
VALA_EXTERN void sway_notification_center_ordered_hash_table_unref (gpointer instance);
VALA_EXTERN GParamSpec* sway_notification_center_param_spec_ordered_hash_table (const gchar* name,
                                                                    const gchar* nick,
                                                                    const gchar* blurb,
                                                                    GType object_type,
                                                                    GParamFlags flags);
VALA_EXTERN void sway_notification_center_value_set_ordered_hash_table (GValue* value,
                                                            gpointer v_object);
VALA_EXTERN void sway_notification_center_value_take_ordered_hash_table (GValue* value,
                                                             gpointer v_object);
VALA_EXTERN gpointer sway_notification_center_value_get_ordered_hash_table (const GValue* value);
VALA_EXTERN GType sway_notification_center_ordered_hash_table_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (SwayNotificationCenterOrderedHashTable, sway_notification_center_ordered_hash_table_unref)
static void _g_free0_ (gpointer var);
static inline void _g_list_free__g_free0_ (GList* self);
VALA_EXTERN SwayNotificationCenterOrderedHashTable* sway_notification_center_ordered_hash_table_new (GType t_type,
                                                                                         GBoxedCopyFunc t_dup_func,
                                                                                         GDestroyNotify t_destroy_func);
VALA_EXTERN SwayNotificationCenterOrderedHashTable* sway_notification_center_ordered_hash_table_construct (GType object_type,
                                                                                               GType t_type,
                                                                                               GBoxedCopyFunc t_dup_func,
                                                                                               GDestroyNotify t_destroy_func);
VALA_EXTERN gconstpointer sway_notification_center_ordered_hash_table_get (SwayNotificationCenterOrderedHashTable* self,
                                                               const gchar* key);
VALA_EXTERN void sway_notification_center_ordered_hash_table_insert (SwayNotificationCenterOrderedHashTable* self,
                                                         gchar* key,
                                                         gpointer value);
VALA_EXTERN GList* sway_notification_center_ordered_hash_table_get_keys (SwayNotificationCenterOrderedHashTable* self);
VALA_EXTERN gboolean sway_notification_center_ordered_hash_table_lookup_extended (SwayNotificationCenterOrderedHashTable* self,
                                                                      const gchar* lookup_key,
                                                                      const gchar** orig_key,
                                                                      gconstpointer* value);
VALA_EXTERN guint sway_notification_center_ordered_hash_table_get_length (SwayNotificationCenterOrderedHashTable* self);
static void sway_notification_center_ordered_hash_table_finalize (SwayNotificationCenterOrderedHashTable * obj);
static GType sway_notification_center_ordered_hash_table_get_type_once (void);

static inline gpointer
sway_notification_center_ordered_hash_table_get_instance_private (SwayNotificationCenterOrderedHashTable* self)
{
	return G_STRUCT_MEMBER_P (self, SwayNotificationCenterOrderedHashTable_private_offset);
}

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

static inline void
_g_list_free__g_free0_ (GList* self)
{
	g_list_free_full (self, (GDestroyNotify) _g_free0_);
}

SwayNotificationCenterOrderedHashTable*
sway_notification_center_ordered_hash_table_construct (GType object_type,
                                                       GType t_type,
                                                       GBoxedCopyFunc t_dup_func,
                                                       GDestroyNotify t_destroy_func)
{
	SwayNotificationCenterOrderedHashTable* self = NULL;
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GHashTable* _tmp2_;
	self = (SwayNotificationCenterOrderedHashTable*) g_type_create_instance (object_type);
	self->priv->t_type = t_type;
	self->priv->t_dup_func = t_dup_func;
	self->priv->t_destroy_func = t_destroy_func;
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_hash_table_new_full (_tmp0_, _tmp1_, _g_free0_, t_destroy_func);
	_g_hash_table_unref0 (self->priv->hash_table);
	self->priv->hash_table = _tmp2_;
	(self->priv->order == NULL) ? NULL : (self->priv->order = (_g_list_free__g_free0_ (self->priv->order), NULL));
	self->priv->order = NULL;
	return self;
}

SwayNotificationCenterOrderedHashTable*
sway_notification_center_ordered_hash_table_new (GType t_type,
                                                 GBoxedCopyFunc t_dup_func,
                                                 GDestroyNotify t_destroy_func)
{
	return sway_notification_center_ordered_hash_table_construct (SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE, t_type, t_dup_func, t_destroy_func);
}

gconstpointer
sway_notification_center_ordered_hash_table_get (SwayNotificationCenterOrderedHashTable* self,
                                                 const gchar* key)
{
	GHashTable* _tmp0_;
	gconstpointer _tmp1_;
	gconstpointer result;
	g_return_val_if_fail (SWAY_NOTIFICATION_CENTER_IS_ORDERED_HASH_TABLE (self), NULL);
	g_return_val_if_fail (key != NULL, NULL);
	_tmp0_ = self->priv->hash_table;
	_tmp1_ = g_hash_table_lookup (_tmp0_, key);
	result = _tmp1_;
	return result;
}

void
sway_notification_center_ordered_hash_table_insert (SwayNotificationCenterOrderedHashTable* self,
                                                    gchar* key,
                                                    gpointer value)
{
	GHashTable* _tmp0_;
	GHashTable* _tmp2_;
	gchar* _tmp3_;
	gpointer _tmp4_;
	g_return_if_fail (SWAY_NOTIFICATION_CENTER_IS_ORDERED_HASH_TABLE (self));
	g_return_if_fail (key != NULL);
	_tmp0_ = self->priv->hash_table;
	if (!g_hash_table_contains (_tmp0_, key)) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup (key);
		self->priv->order = g_list_append (self->priv->order, _tmp1_);
	}
	_tmp2_ = self->priv->hash_table;
	_tmp3_ = g_strdup (key);
	_tmp4_ = ((value != NULL) && (self->priv->t_dup_func != NULL)) ? self->priv->t_dup_func ((gpointer) value) : ((gpointer) value);
	g_hash_table_insert (_tmp2_, _tmp3_, _tmp4_);
	_g_free0 (key);
	((value == NULL) || (self->priv->t_destroy_func == NULL)) ? NULL : (value = (self->priv->t_destroy_func (value), NULL));
}

GList*
sway_notification_center_ordered_hash_table_get_keys (SwayNotificationCenterOrderedHashTable* self)
{
	GList* _tmp0_;
	GList* _tmp1_;
	GList* result;
	g_return_val_if_fail (SWAY_NOTIFICATION_CENTER_IS_ORDERED_HASH_TABLE (self), NULL);
	_tmp0_ = self->priv->order;
	_tmp1_ = g_list_copy (_tmp0_);
	result = _tmp1_;
	return result;
}

gboolean
sway_notification_center_ordered_hash_table_lookup_extended (SwayNotificationCenterOrderedHashTable* self,
                                                             const gchar* lookup_key,
                                                             const gchar** orig_key,
                                                             gconstpointer* value)
{
	const gchar* _vala_orig_key = NULL;
	gconstpointer _vala_value = NULL;
	GHashTable* _tmp0_;
	gconstpointer _tmp1_ = NULL;
	gconstpointer _tmp2_ = NULL;
	gboolean _tmp3_;
	gboolean result;
	g_return_val_if_fail (SWAY_NOTIFICATION_CENTER_IS_ORDERED_HASH_TABLE (self), FALSE);
	g_return_val_if_fail (lookup_key != NULL, FALSE);
	_tmp0_ = self->priv->hash_table;
	_tmp3_ = g_hash_table_lookup_extended (_tmp0_, lookup_key, &_tmp1_, &_tmp2_);
	_vala_orig_key = (const gchar*) _tmp1_;
	_vala_value = _tmp2_;
	result = _tmp3_;
	if (orig_key) {
		*orig_key = _vala_orig_key;
	}
	if (value) {
		*value = _vala_value;
	}
	return result;
}

guint
sway_notification_center_ordered_hash_table_get_length (SwayNotificationCenterOrderedHashTable* self)
{
	guint result;
	GHashTable* _tmp0_;
	guint _tmp1_;
	guint _tmp2_;
	g_return_val_if_fail (SWAY_NOTIFICATION_CENTER_IS_ORDERED_HASH_TABLE (self), 0U);
	_tmp0_ = self->priv->hash_table;
	_tmp1_ = g_hash_table_size (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

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

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

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

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

static gchar*
sway_notification_center_value_ordered_hash_table_collect_value (GValue* value,
                                                                 guint n_collect_values,
                                                                 GTypeCValue* collect_values,
                                                                 guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		SwayNotificationCenterOrderedHashTable * 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 = sway_notification_center_ordered_hash_table_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
sway_notification_center_value_ordered_hash_table_lcopy_value (const GValue* value,
                                                               guint n_collect_values,
                                                               GTypeCValue* collect_values,
                                                               guint collect_flags)
{
	SwayNotificationCenterOrderedHashTable ** 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 = sway_notification_center_ordered_hash_table_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
sway_notification_center_param_spec_ordered_hash_table (const gchar* name,
                                                        const gchar* nick,
                                                        const gchar* blurb,
                                                        GType object_type,
                                                        GParamFlags flags)
{
	SwayNotificationCenterParamSpecOrderedHashTable* spec;
	g_return_val_if_fail (g_type_is_a (object_type, SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE), 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
sway_notification_center_value_get_ordered_hash_table (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE), NULL);
	return value->data[0].v_pointer;
}

void
sway_notification_center_value_set_ordered_hash_table (GValue* value,
                                                       gpointer v_object)
{
	SwayNotificationCenterOrderedHashTable * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE));
		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;
		sway_notification_center_ordered_hash_table_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		sway_notification_center_ordered_hash_table_unref (old);
	}
}

void
sway_notification_center_value_take_ordered_hash_table (GValue* value,
                                                        gpointer v_object)
{
	SwayNotificationCenterOrderedHashTable * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE));
		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) {
		sway_notification_center_ordered_hash_table_unref (old);
	}
}

static void
sway_notification_center_ordered_hash_table_class_init (SwayNotificationCenterOrderedHashTableClass * klass,
                                                        gpointer klass_data)
{
	sway_notification_center_ordered_hash_table_parent_class = g_type_class_peek_parent (klass);
	((SwayNotificationCenterOrderedHashTableClass *) klass)->finalize = sway_notification_center_ordered_hash_table_finalize;
	g_type_class_adjust_private_offset (klass, &SwayNotificationCenterOrderedHashTable_private_offset);
}

static void
sway_notification_center_ordered_hash_table_instance_init (SwayNotificationCenterOrderedHashTable * self,
                                                           gpointer klass)
{
	self->priv = sway_notification_center_ordered_hash_table_get_instance_private (self);
	self->ref_count = 1;
}

static void
sway_notification_center_ordered_hash_table_finalize (SwayNotificationCenterOrderedHashTable * obj)
{
	SwayNotificationCenterOrderedHashTable * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, SWAY_NOTIFICATION_CENTER_TYPE_ORDERED_HASH_TABLE, SwayNotificationCenterOrderedHashTable);
	g_signal_handlers_destroy (self);
	_g_hash_table_unref0 (self->priv->hash_table);
	(self->priv->order == NULL) ? NULL : (self->priv->order = (_g_list_free__g_free0_ (self->priv->order), NULL));
}

/** A regular GLib HashTable but preserves the order of inserted keys and values */
 G_GNUC_NO_INLINE static GType
sway_notification_center_ordered_hash_table_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { sway_notification_center_value_ordered_hash_table_init, sway_notification_center_value_ordered_hash_table_free_value, sway_notification_center_value_ordered_hash_table_copy_value, sway_notification_center_value_ordered_hash_table_peek_pointer, "p", sway_notification_center_value_ordered_hash_table_collect_value, "p", sway_notification_center_value_ordered_hash_table_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (SwayNotificationCenterOrderedHashTableClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) sway_notification_center_ordered_hash_table_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (SwayNotificationCenterOrderedHashTable), 0, (GInstanceInitFunc) sway_notification_center_ordered_hash_table_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) };
	GType sway_notification_center_ordered_hash_table_type_id;
	sway_notification_center_ordered_hash_table_type_id = g_type_register_fundamental (g_type_fundamental_next (), "SwayNotificationCenterOrderedHashTable", &g_define_type_info, &g_define_type_fundamental_info, 0);
	SwayNotificationCenterOrderedHashTable_private_offset = g_type_add_instance_private (sway_notification_center_ordered_hash_table_type_id, sizeof (SwayNotificationCenterOrderedHashTablePrivate));
	return sway_notification_center_ordered_hash_table_type_id;
}

GType
sway_notification_center_ordered_hash_table_get_type (void)
{
	static gsize sway_notification_center_ordered_hash_table_type_id__once = 0;
	if (g_once_init_enter (&sway_notification_center_ordered_hash_table_type_id__once)) {
		GType sway_notification_center_ordered_hash_table_type_id;
		sway_notification_center_ordered_hash_table_type_id = sway_notification_center_ordered_hash_table_get_type_once ();
		g_once_init_leave (&sway_notification_center_ordered_hash_table_type_id__once, sway_notification_center_ordered_hash_table_type_id);
	}
	return sway_notification_center_ordered_hash_table_type_id__once;
}

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

void
sway_notification_center_ordered_hash_table_unref (gpointer instance)
{
	SwayNotificationCenterOrderedHashTable * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		SWAY_NOTIFICATION_CENTER_ORDERED_HASH_TABLE_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

