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

/*
 * Color lines for GNOME
 * Copyright © 1999 Free Software Foundation
 * Authors: Robert Szokovacs <szo@szo.hu>
 *          Szabolcs Ban <shooby@gnome.hu>
 *          Karuna Grewal <karunagrewal98@gmail.com>
 *          Ruxandra Simion <ruxandra.simion93@gmail.com>
 * Copyright © 2007 Christian Persch
 *
 * This game is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
 */

#include <glib-object.h>
#include <glib.h>
#include <gee.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 TYPE_NEXT_PIECES_GENERATOR (next_pieces_generator_get_type ())
#define NEXT_PIECES_GENERATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NEXT_PIECES_GENERATOR, NextPiecesGenerator))
#define NEXT_PIECES_GENERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NEXT_PIECES_GENERATOR, NextPiecesGeneratorClass))
#define IS_NEXT_PIECES_GENERATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NEXT_PIECES_GENERATOR))
#define IS_NEXT_PIECES_GENERATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NEXT_PIECES_GENERATOR))
#define NEXT_PIECES_GENERATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NEXT_PIECES_GENERATOR, NextPiecesGeneratorClass))

typedef struct _NextPiecesGenerator NextPiecesGenerator;
typedef struct _NextPiecesGeneratorClass NextPiecesGeneratorClass;
typedef struct _NextPiecesGeneratorPrivate NextPiecesGeneratorPrivate;

#define TYPE_PIECE (piece_get_type ())
#define PIECE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PIECE, Piece))
#define PIECE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PIECE, PieceClass))
#define IS_PIECE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PIECE))
#define IS_PIECE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PIECE))
#define PIECE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PIECE, PieceClass))

typedef struct _Piece Piece;
typedef struct _PieceClass PieceClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _piece_unref0(var) ((var == NULL) ? NULL : (var = (piece_unref (var), NULL)))
typedef struct _ParamSpecNextPiecesGenerator ParamSpecNextPiecesGenerator;

struct _NextPiecesGenerator {
	GTypeInstance parent_instance;
	volatile int ref_count;
	NextPiecesGeneratorPrivate * priv;
};

struct _NextPiecesGeneratorClass {
	GTypeClass parent_class;
	void (*finalize) (NextPiecesGenerator *self);
};

struct _NextPiecesGeneratorPrivate {
	gint n_types;
	gint n_next_pieces;
	GeeArrayList* pieces;
};

struct _ParamSpecNextPiecesGenerator {
	GParamSpec parent_instance;
};

static gint NextPiecesGenerator_private_offset;
static gpointer next_pieces_generator_parent_class = NULL;

VALA_EXTERN gpointer next_pieces_generator_ref (gpointer instance);
VALA_EXTERN void next_pieces_generator_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_next_pieces_generator (const gchar* name,
                                              const gchar* nick,
                                              const gchar* blurb,
                                              GType object_type,
                                              GParamFlags flags);
VALA_EXTERN void value_set_next_pieces_generator (GValue* value,
                                      gpointer v_object);
VALA_EXTERN void value_take_next_pieces_generator (GValue* value,
                                       gpointer v_object);
VALA_EXTERN gpointer value_get_next_pieces_generator (const GValue* value);
VALA_EXTERN GType next_pieces_generator_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (NextPiecesGenerator, next_pieces_generator_unref)
VALA_EXTERN gpointer piece_ref (gpointer instance);
VALA_EXTERN void piece_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_piece (const gchar* name,
                              const gchar* nick,
                              const gchar* blurb,
                              GType object_type,
                              GParamFlags flags);
VALA_EXTERN void value_set_piece (GValue* value,
                      gpointer v_object);
VALA_EXTERN void value_take_piece (GValue* value,
                       gpointer v_object);
VALA_EXTERN gpointer value_get_piece (const GValue* value);
VALA_EXTERN GType piece_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Piece, piece_unref)
VALA_EXTERN NextPiecesGenerator* next_pieces_generator_new (gint n_next_pieces,
                                                gint n_types);
VALA_EXTERN NextPiecesGenerator* next_pieces_generator_construct (GType object_type,
                                                      gint n_next_pieces,
                                                      gint n_types);
static gint next_pieces_generator_yield_next_piece (NextPiecesGenerator* self);
VALA_EXTERN GeeArrayList* next_pieces_generator_yield_next_pieces (NextPiecesGenerator* self);
VALA_EXTERN Piece* piece_new (gint id);
VALA_EXTERN Piece* piece_construct (GType object_type,
                        gint id);
static void next_pieces_generator_finalize (NextPiecesGenerator * obj);
static GType next_pieces_generator_get_type_once (void);

static inline gpointer
next_pieces_generator_get_instance_private (NextPiecesGenerator* self)
{
	return G_STRUCT_MEMBER_P (self, NextPiecesGenerator_private_offset);
}

NextPiecesGenerator*
next_pieces_generator_construct (GType object_type,
                                 gint n_next_pieces,
                                 gint n_types)
{
	NextPiecesGenerator* self = NULL;
	GeeArrayList* _tmp0_;
	self = (NextPiecesGenerator*) g_type_create_instance (object_type);
	_tmp0_ = gee_array_list_new (TYPE_PIECE, (GBoxedCopyFunc) piece_ref, (GDestroyNotify) piece_unref, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->pieces);
	self->priv->pieces = _tmp0_;
	self->priv->n_next_pieces = n_next_pieces;
	self->priv->n_types = n_types;
	return self;
}

NextPiecesGenerator*
next_pieces_generator_new (gint n_next_pieces,
                           gint n_types)
{
	return next_pieces_generator_construct (TYPE_NEXT_PIECES_GENERATOR, n_next_pieces, n_types);
}

static gint
next_pieces_generator_yield_next_piece (NextPiecesGenerator* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, 0);
	result = (gint) g_random_int_range ((gint32) 0, (gint32) self->priv->n_types);
	return result;
}

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

GeeArrayList*
next_pieces_generator_yield_next_pieces (NextPiecesGenerator* self)
{
	GeeArrayList* _tmp0_;
	GeeArrayList* _tmp6_;
	GeeArrayList* _tmp7_;
	GeeArrayList* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->pieces;
	gee_abstract_collection_clear ((GeeAbstractCollection*) _tmp0_);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				gint id = 0;
				GeeArrayList* _tmp3_;
				Piece* _tmp4_;
				Piece* _tmp5_;
				if (!_tmp1_) {
					gint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp1_ = FALSE;
				if (!(i < self->priv->n_next_pieces)) {
					break;
				}
				id = next_pieces_generator_yield_next_piece (self);
				_tmp3_ = self->priv->pieces;
				_tmp4_ = piece_new (id);
				_tmp5_ = _tmp4_;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp3_, _tmp5_);
				_piece_unref0 (_tmp5_);
			}
		}
	}
	_tmp6_ = self->priv->pieces;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	result = _tmp7_;
	return result;
}

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

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

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

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

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

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

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

void
value_set_next_pieces_generator (GValue* value,
                                 gpointer v_object)
{
	NextPiecesGenerator * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_NEXT_PIECES_GENERATOR));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_NEXT_PIECES_GENERATOR));
		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;
		next_pieces_generator_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		next_pieces_generator_unref (old);
	}
}

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

static void
next_pieces_generator_class_init (NextPiecesGeneratorClass * klass,
                                  gpointer klass_data)
{
	next_pieces_generator_parent_class = g_type_class_peek_parent (klass);
	((NextPiecesGeneratorClass *) klass)->finalize = next_pieces_generator_finalize;
	g_type_class_adjust_private_offset (klass, &NextPiecesGenerator_private_offset);
}

static void
next_pieces_generator_instance_init (NextPiecesGenerator * self,
                                     gpointer klass)
{
	self->priv = next_pieces_generator_get_instance_private (self);
	self->ref_count = 1;
}

static void
next_pieces_generator_finalize (NextPiecesGenerator * obj)
{
	NextPiecesGenerator * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_NEXT_PIECES_GENERATOR, NextPiecesGenerator);
	g_signal_handlers_destroy (self);
	_g_object_unref0 (self->priv->pieces);
}

static GType
next_pieces_generator_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { value_next_pieces_generator_init, value_next_pieces_generator_free_value, value_next_pieces_generator_copy_value, value_next_pieces_generator_peek_pointer, "p", value_next_pieces_generator_collect_value, "p", value_next_pieces_generator_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (NextPiecesGeneratorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) next_pieces_generator_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (NextPiecesGenerator), 0, (GInstanceInitFunc) next_pieces_generator_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 next_pieces_generator_type_id;
	next_pieces_generator_type_id = g_type_register_fundamental (g_type_fundamental_next (), "NextPiecesGenerator", &g_define_type_info, &g_define_type_fundamental_info, 0);
	NextPiecesGenerator_private_offset = g_type_add_instance_private (next_pieces_generator_type_id, sizeof (NextPiecesGeneratorPrivate));
	return next_pieces_generator_type_id;
}

GType
next_pieces_generator_get_type (void)
{
	static volatile gsize next_pieces_generator_type_id__once = 0;
	if (g_once_init_enter (&next_pieces_generator_type_id__once)) {
		GType next_pieces_generator_type_id;
		next_pieces_generator_type_id = next_pieces_generator_get_type_once ();
		g_once_init_leave (&next_pieces_generator_type_id__once, next_pieces_generator_type_id);
	}
	return next_pieces_generator_type_id__once;
}

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

void
next_pieces_generator_unref (gpointer instance)
{
	NextPiecesGenerator * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		NEXT_PIECES_GENERATOR_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

