/* simple-result-set.c generated by valac 0.56.19, the Vala compiler
 * generated from simple-result-set.vala, do not modify */

/* simple-result-set.vala
 *
 * Copyright © 2012 Canonical Ltd.
 *             By Siegfried-A. Gevatter <siegfried.gevatter@collabora.co.uk>
 *
 * Based upon a C implementation (© 2009 Canonical Ltd) by:
 *  Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, 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 Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "zeitgeist-datamodel.h"
#include <glib.h>
#include <glib-object.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

enum  {
	ZEITGEIST_SIMPLE_RESULT_SET_0_PROPERTY,
	ZEITGEIST_SIMPLE_RESULT_SET_NUM_PROPERTIES
};
static GParamSpec* zeitgeist_simple_result_set_properties[ZEITGEIST_SIMPLE_RESULT_SET_NUM_PROPERTIES];
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))

struct _ZeitgeistSimpleResultSetPrivate {
	GPtrArray* events;
	guint num_estimated_matches;
	guint cursor;
};

static gint ZeitgeistSimpleResultSet_private_offset;
static gpointer zeitgeist_simple_result_set_parent_class = NULL;
static ZeitgeistResultSetIface * zeitgeist_simple_result_set_zeitgeist_result_set_parent_iface = NULL;

static guint zeitgeist_simple_result_set_real_size (ZeitgeistResultSet* base);
static guint zeitgeist_simple_result_set_real_estimated_matches (ZeitgeistResultSet* base);
static guint zeitgeist_simple_result_set_real_tell (ZeitgeistResultSet* base);
static gboolean zeitgeist_simple_result_set_real_has_next (ZeitgeistResultSet* base);
static ZeitgeistEvent* zeitgeist_simple_result_set_real_next_value (ZeitgeistResultSet* base);
static void zeitgeist_simple_result_set_real_reset (ZeitgeistResultSet* base);
static void zeitgeist_simple_result_set_finalize (GObject * obj);
static GType zeitgeist_simple_result_set_get_type_once (void);

static inline gpointer
zeitgeist_simple_result_set_get_instance_private (ZeitgeistSimpleResultSet* self)
{
	return G_STRUCT_MEMBER_P (self, ZeitgeistSimpleResultSet_private_offset);
}

static gpointer
_g_ptr_array_ref0 (gpointer self)
{
	return self ? g_ptr_array_ref (self) : NULL;
}

static gint
vala_g_ptr_array_get_length (GPtrArray* self)
{
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	result = (gint) self->len;
	return result;
}

ZeitgeistSimpleResultSet*
zeitgeist_simple_result_set_construct (GType object_type,
                                       GPtrArray* events)
{
	ZeitgeistSimpleResultSet * self = NULL;
	GPtrArray* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	g_return_val_if_fail (events != NULL, NULL);
	self = (ZeitgeistSimpleResultSet*) g_object_new (object_type, NULL);
	_tmp0_ = _g_ptr_array_ref0 (events);
	_g_ptr_array_unref0 (self->priv->events);
	self->priv->events = _tmp0_;
	_tmp1_ = vala_g_ptr_array_get_length (events);
	_tmp2_ = _tmp1_;
	self->priv->num_estimated_matches = (guint) _tmp2_;
	self->priv->cursor = (guint) 0;
	return self;
}

ZeitgeistSimpleResultSet*
zeitgeist_simple_result_set_new (GPtrArray* events)
{
	return zeitgeist_simple_result_set_construct (ZEITGEIST_TYPE_SIMPLE_RESULT_SET, events);
}

ZeitgeistSimpleResultSet*
zeitgeist_simple_result_set_construct_with_num_matches (GType object_type,
                                                        GPtrArray* events,
                                                        guint matches)
{
	ZeitgeistSimpleResultSet * self = NULL;
	GPtrArray* _tmp0_;
	g_return_val_if_fail (events != NULL, NULL);
	self = (ZeitgeistSimpleResultSet*) g_object_new (object_type, NULL);
	_tmp0_ = _g_ptr_array_ref0 (events);
	_g_ptr_array_unref0 (self->priv->events);
	self->priv->events = _tmp0_;
	self->priv->num_estimated_matches = matches;
	self->priv->cursor = (guint) 0;
	return self;
}

ZeitgeistSimpleResultSet*
zeitgeist_simple_result_set_new_with_num_matches (GPtrArray* events,
                                                  guint matches)
{
	return zeitgeist_simple_result_set_construct_with_num_matches (ZEITGEIST_TYPE_SIMPLE_RESULT_SET, events, matches);
}

static guint
zeitgeist_simple_result_set_real_size (ZeitgeistResultSet* base)
{
	ZeitgeistSimpleResultSet * self;
	GPtrArray* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	guint result;
	self = (ZeitgeistSimpleResultSet*) base;
	_tmp0_ = self->priv->events;
	_tmp1_ = vala_g_ptr_array_get_length (_tmp0_);
	_tmp2_ = _tmp1_;
	result = (guint) _tmp2_;
	return result;
}

static guint
zeitgeist_simple_result_set_real_estimated_matches (ZeitgeistResultSet* base)
{
	ZeitgeistSimpleResultSet * self;
	guint result;
	self = (ZeitgeistSimpleResultSet*) base;
	result = self->priv->num_estimated_matches;
	return result;
}

static guint
zeitgeist_simple_result_set_real_tell (ZeitgeistResultSet* base)
{
	ZeitgeistSimpleResultSet * self;
	guint result;
	self = (ZeitgeistSimpleResultSet*) base;
	result = self->priv->cursor;
	return result;
}

static gboolean
zeitgeist_simple_result_set_real_has_next (ZeitgeistResultSet* base)
{
	ZeitgeistSimpleResultSet * self;
	GPtrArray* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gboolean result;
	self = (ZeitgeistSimpleResultSet*) base;
	_tmp0_ = self->priv->events;
	_tmp1_ = vala_g_ptr_array_get_length (_tmp0_);
	_tmp2_ = _tmp1_;
	result = self->priv->cursor < ((guint) _tmp2_);
	return result;
}

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

static ZeitgeistEvent*
zeitgeist_simple_result_set_real_next_value (ZeitgeistResultSet* base)
{
	ZeitgeistSimpleResultSet * self;
	GPtrArray* _tmp0_;
	guint _tmp1_;
	gconstpointer _tmp2_;
	ZeitgeistEvent* _tmp3_;
	ZeitgeistEvent* result;
	self = (ZeitgeistSimpleResultSet*) base;
	if (!zeitgeist_result_set_has_next ((ZeitgeistResultSet*) self)) {
		result = NULL;
		return result;
	}
	_tmp0_ = self->priv->events;
	_tmp1_ = self->priv->cursor;
	self->priv->cursor = _tmp1_ + 1;
	_tmp2_ = g_ptr_array_index (_tmp0_, _tmp1_);
	_tmp3_ = _g_object_ref0 ((ZeitgeistEvent*) _tmp2_);
	result = _tmp3_;
	return result;
}

static void
zeitgeist_simple_result_set_real_reset (ZeitgeistResultSet* base)
{
	ZeitgeistSimpleResultSet * self;
	self = (ZeitgeistSimpleResultSet*) base;
	self->priv->cursor = (guint) 0;
}

static void
zeitgeist_simple_result_set_class_init (ZeitgeistSimpleResultSetClass * klass,
                                        gpointer klass_data)
{
	zeitgeist_simple_result_set_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ZeitgeistSimpleResultSet_private_offset);
	G_OBJECT_CLASS (klass)->finalize = zeitgeist_simple_result_set_finalize;
}

static void
zeitgeist_simple_result_set_zeitgeist_result_set_interface_init (ZeitgeistResultSetIface * iface,
                                                                 gpointer iface_data)
{
	zeitgeist_simple_result_set_zeitgeist_result_set_parent_iface = g_type_interface_peek_parent (iface);
	iface->size = (guint (*) (ZeitgeistResultSet*)) zeitgeist_simple_result_set_real_size;
	iface->estimated_matches = (guint (*) (ZeitgeistResultSet*)) zeitgeist_simple_result_set_real_estimated_matches;
	iface->tell = (guint (*) (ZeitgeistResultSet*)) zeitgeist_simple_result_set_real_tell;
	iface->has_next = (gboolean (*) (ZeitgeistResultSet*)) zeitgeist_simple_result_set_real_has_next;
	iface->next_value = (ZeitgeistEvent* (*) (ZeitgeistResultSet*)) zeitgeist_simple_result_set_real_next_value;
	iface->reset = (void (*) (ZeitgeistResultSet*)) zeitgeist_simple_result_set_real_reset;
}

static void
zeitgeist_simple_result_set_instance_init (ZeitgeistSimpleResultSet * self,
                                           gpointer klass)
{
	self->priv = zeitgeist_simple_result_set_get_instance_private (self);
}

static void
zeitgeist_simple_result_set_finalize (GObject * obj)
{
	ZeitgeistSimpleResultSet * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, ZEITGEIST_TYPE_SIMPLE_RESULT_SET, ZeitgeistSimpleResultSet);
	_g_ptr_array_unref0 (self->priv->events);
	G_OBJECT_CLASS (zeitgeist_simple_result_set_parent_class)->finalize (obj);
}

static GType
zeitgeist_simple_result_set_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ZeitgeistSimpleResultSetClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) zeitgeist_simple_result_set_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ZeitgeistSimpleResultSet), 0, (GInstanceInitFunc) zeitgeist_simple_result_set_instance_init, NULL };
	static const GInterfaceInfo zeitgeist_result_set_info = { (GInterfaceInitFunc) zeitgeist_simple_result_set_zeitgeist_result_set_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType zeitgeist_simple_result_set_type_id;
	zeitgeist_simple_result_set_type_id = g_type_register_static (G_TYPE_OBJECT, "ZeitgeistSimpleResultSet", &g_define_type_info, 0);
	g_type_add_interface_static (zeitgeist_simple_result_set_type_id, ZEITGEIST_TYPE_RESULT_SET, &zeitgeist_result_set_info);
	ZeitgeistSimpleResultSet_private_offset = g_type_add_instance_private (zeitgeist_simple_result_set_type_id, sizeof (ZeitgeistSimpleResultSetPrivate));
	return zeitgeist_simple_result_set_type_id;
}

GType
zeitgeist_simple_result_set_get_type (void)
{
	static volatile gsize zeitgeist_simple_result_set_type_id__once = 0;
	if (g_once_init_enter (&zeitgeist_simple_result_set_type_id__once)) {
		GType zeitgeist_simple_result_set_type_id;
		zeitgeist_simple_result_set_type_id = zeitgeist_simple_result_set_get_type_once ();
		g_once_init_leave (&zeitgeist_simple_result_set_type_id__once, zeitgeist_simple_result_set_type_id);
	}
	return zeitgeist_simple_result_set_type_id__once;
}

