/* simple-result-set.c generated by valac 0.26.1, 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 <glib.h>
#include <glib-object.h>


#define ZEITGEIST_TYPE_RESULT_SET (zeitgeist_result_set_get_type ())
#define ZEITGEIST_RESULT_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZEITGEIST_TYPE_RESULT_SET, ZeitgeistResultSet))
#define ZEITGEIST_IS_RESULT_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZEITGEIST_TYPE_RESULT_SET))
#define ZEITGEIST_RESULT_SET_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), ZEITGEIST_TYPE_RESULT_SET, ZeitgeistResultSetIface))

typedef struct _ZeitgeistResultSet ZeitgeistResultSet;
typedef struct _ZeitgeistResultSetIface ZeitgeistResultSetIface;

#define ZEITGEIST_TYPE_EVENT (zeitgeist_event_get_type ())
#define ZEITGEIST_EVENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZEITGEIST_TYPE_EVENT, ZeitgeistEvent))
#define ZEITGEIST_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZEITGEIST_TYPE_EVENT, ZeitgeistEventClass))
#define ZEITGEIST_IS_EVENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZEITGEIST_TYPE_EVENT))
#define ZEITGEIST_IS_EVENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZEITGEIST_TYPE_EVENT))
#define ZEITGEIST_EVENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZEITGEIST_TYPE_EVENT, ZeitgeistEventClass))

typedef struct _ZeitgeistEvent ZeitgeistEvent;
typedef struct _ZeitgeistEventClass ZeitgeistEventClass;

#define ZEITGEIST_TYPE_SIMPLE_RESULT_SET (zeitgeist_simple_result_set_get_type ())
#define ZEITGEIST_SIMPLE_RESULT_SET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZEITGEIST_TYPE_SIMPLE_RESULT_SET, ZeitgeistSimpleResultSet))
#define ZEITGEIST_SIMPLE_RESULT_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZEITGEIST_TYPE_SIMPLE_RESULT_SET, ZeitgeistSimpleResultSetClass))
#define ZEITGEIST_IS_SIMPLE_RESULT_SET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZEITGEIST_TYPE_SIMPLE_RESULT_SET))
#define ZEITGEIST_IS_SIMPLE_RESULT_SET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZEITGEIST_TYPE_SIMPLE_RESULT_SET))
#define ZEITGEIST_SIMPLE_RESULT_SET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZEITGEIST_TYPE_SIMPLE_RESULT_SET, ZeitgeistSimpleResultSetClass))

typedef struct _ZeitgeistSimpleResultSet ZeitgeistSimpleResultSet;
typedef struct _ZeitgeistSimpleResultSetClass ZeitgeistSimpleResultSetClass;
typedef struct _ZeitgeistSimpleResultSetPrivate ZeitgeistSimpleResultSetPrivate;
#define _g_ptr_array_unref0(var) ((var == NULL) ? NULL : (var = (g_ptr_array_unref (var), NULL)))

struct _ZeitgeistResultSetIface {
	GTypeInterface parent_iface;
	guint (*size) (ZeitgeistResultSet* self);
	guint (*estimated_matches) (ZeitgeistResultSet* self);
	ZeitgeistEvent* (*next_value) (ZeitgeistResultSet* self);
	gboolean (*has_next) (ZeitgeistResultSet* self);
	guint (*tell) (ZeitgeistResultSet* self);
	void (*reset) (ZeitgeistResultSet* self);
};

struct _ZeitgeistSimpleResultSet {
	GObject parent_instance;
	ZeitgeistSimpleResultSetPrivate * priv;
};

struct _ZeitgeistSimpleResultSetClass {
	GObjectClass parent_class;
};

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


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

GType zeitgeist_event_get_type (void) G_GNUC_CONST;
GType zeitgeist_result_set_get_type (void) G_GNUC_CONST;
GType zeitgeist_simple_result_set_get_type (void) G_GNUC_CONST;
#define ZEITGEIST_SIMPLE_RESULT_SET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), ZEITGEIST_TYPE_SIMPLE_RESULT_SET, ZeitgeistSimpleResultSetPrivate))
enum  {
	ZEITGEIST_SIMPLE_RESULT_SET_DUMMY_PROPERTY
};
ZeitgeistSimpleResultSet* zeitgeist_simple_result_set_new (GPtrArray* events);
ZeitgeistSimpleResultSet* zeitgeist_simple_result_set_construct (GType object_type, GPtrArray* events);
ZeitgeistSimpleResultSet* zeitgeist_simple_result_set_new_with_num_matches (GPtrArray* events, guint matches);
ZeitgeistSimpleResultSet* zeitgeist_simple_result_set_construct_with_num_matches (GType object_type, GPtrArray* events, guint matches);
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);
gboolean zeitgeist_result_set_has_next (ZeitgeistResultSet* self);
static void zeitgeist_simple_result_set_real_reset (ZeitgeistResultSet* base);
static void zeitgeist_simple_result_set_finalize (GObject* obj);


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


static gint g_ptr_array_get_length (GPtrArray* self) {
	gint result;
	guint _tmp0_ = 0U;
	g_return_val_if_fail (self != NULL, 0);
	_tmp0_ = self->len;
	result = (gint) _tmp0_;
	return result;
}


static void g_ptr_array_set_length (GPtrArray* self, gint value) {
	gint _tmp0_ = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	g_ptr_array_set_size (self, _tmp0_);
}


ZeitgeistSimpleResultSet* zeitgeist_simple_result_set_construct (GType object_type, GPtrArray* events) {
	ZeitgeistSimpleResultSet * self = NULL;
	GPtrArray* _tmp0_ = NULL;
	GPtrArray* _tmp1_ = NULL;
	GPtrArray* _tmp2_ = NULL;
	gint _tmp3_ = 0;
	gint _tmp4_ = 0;
	g_return_val_if_fail (events != NULL, NULL);
	self = (ZeitgeistSimpleResultSet*) g_object_new (object_type, NULL);
	_tmp0_ = events;
	_tmp1_ = _g_ptr_array_ref0 (_tmp0_);
	_g_ptr_array_unref0 (self->priv->events);
	self->priv->events = _tmp1_;
	_tmp2_ = events;
	_tmp3_ = g_ptr_array_get_length (_tmp2_);
	_tmp4_ = _tmp3_;
	self->priv->num_estimated_matches = (guint) _tmp4_;
	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_ = NULL;
	GPtrArray* _tmp1_ = NULL;
	guint _tmp2_ = 0U;
	g_return_val_if_fail (events != NULL, NULL);
	self = (ZeitgeistSimpleResultSet*) g_object_new (object_type, NULL);
	_tmp0_ = events;
	_tmp1_ = _g_ptr_array_ref0 (_tmp0_);
	_g_ptr_array_unref0 (self->priv->events);
	self->priv->events = _tmp1_;
	_tmp2_ = matches;
	self->priv->num_estimated_matches = _tmp2_;
	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;
	guint result = 0U;
	GPtrArray* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	gint _tmp2_ = 0;
	self = (ZeitgeistSimpleResultSet*) base;
	_tmp0_ = self->priv->events;
	_tmp1_ = 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 = 0U;
	guint _tmp0_ = 0U;
	self = (ZeitgeistSimpleResultSet*) base;
	_tmp0_ = self->priv->num_estimated_matches;
	result = _tmp0_;
	return result;
}


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


static gboolean zeitgeist_simple_result_set_real_has_next (ZeitgeistResultSet* base) {
	ZeitgeistSimpleResultSet * self;
	gboolean result = FALSE;
	guint _tmp0_ = 0U;
	GPtrArray* _tmp1_ = NULL;
	gint _tmp2_ = 0;
	gint _tmp3_ = 0;
	self = (ZeitgeistSimpleResultSet*) base;
	_tmp0_ = self->priv->cursor;
	_tmp1_ = self->priv->events;
	_tmp2_ = g_ptr_array_get_length (_tmp1_);
	_tmp3_ = _tmp2_;
	result = _tmp0_ < ((guint) _tmp3_);
	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;
	ZeitgeistEvent* result = NULL;
	gboolean _tmp0_ = FALSE;
	GPtrArray* _tmp1_ = NULL;
	guint _tmp2_ = 0U;
	gconstpointer _tmp3_ = NULL;
	ZeitgeistEvent* _tmp4_ = NULL;
	self = (ZeitgeistSimpleResultSet*) base;
	_tmp0_ = zeitgeist_result_set_has_next ((ZeitgeistResultSet*) self);
	if (!_tmp0_) {
		result = NULL;
		return result;
	}
	_tmp1_ = self->priv->events;
	_tmp2_ = self->priv->cursor;
	self->priv->cursor = _tmp2_ + 1;
	_tmp3_ = g_ptr_array_index (_tmp1_, _tmp2_);
	_tmp4_ = _g_object_ref0 ((ZeitgeistEvent*) _tmp3_);
	result = _tmp4_;
	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) {
	zeitgeist_simple_result_set_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ZeitgeistSimpleResultSetPrivate));
	G_OBJECT_CLASS (klass)->finalize = zeitgeist_simple_result_set_finalize;
}


static void zeitgeist_simple_result_set_zeitgeist_result_set_interface_init (ZeitgeistResultSetIface * iface) {
	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) {
	self->priv = ZEITGEIST_SIMPLE_RESULT_SET_GET_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);
}


GType zeitgeist_simple_result_set_get_type (void) {
	static volatile gsize zeitgeist_simple_result_set_type_id__volatile = 0;
	if (g_once_init_enter (&zeitgeist_simple_result_set_type_id__volatile)) {
		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);
		g_once_init_leave (&zeitgeist_simple_result_set_type_id__volatile, zeitgeist_simple_result_set_type_id);
	}
	return zeitgeist_simple_result_set_type_id__volatile;
}



