/* rygel-tracker-query-triplets.c generated by valac 0.42.1.67-6c68, the Vala compiler
 * generated from rygel-tracker-query-triplets.vala, do not modify */

/*
 * Copyright (C) 2008 Nokia Corporation.
 *
 * Author: Zeeshan Ali <zeenix@gmail.com>
 *
 * This file is part of Rygel.
 *
 * Rygel 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.
 *
 * Rygel 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#define RYGEL_TRACKER_TYPE_QUERY_TRIPLETS (rygel_tracker_query_triplets_get_type ())
#define RYGEL_TRACKER_QUERY_TRIPLETS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS, RygelTrackerQueryTriplets))
#define RYGEL_TRACKER_QUERY_TRIPLETS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS, RygelTrackerQueryTripletsClass))
#define RYGEL_TRACKER_IS_QUERY_TRIPLETS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS))
#define RYGEL_TRACKER_IS_QUERY_TRIPLETS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS))
#define RYGEL_TRACKER_QUERY_TRIPLETS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLETS, RygelTrackerQueryTripletsClass))

typedef struct _RygelTrackerQueryTriplets RygelTrackerQueryTriplets;
typedef struct _RygelTrackerQueryTripletsClass RygelTrackerQueryTripletsClass;
typedef struct _RygelTrackerQueryTripletsPrivate RygelTrackerQueryTripletsPrivate;
enum  {
	RYGEL_TRACKER_QUERY_TRIPLETS_0_PROPERTY,
	RYGEL_TRACKER_QUERY_TRIPLETS_NUM_PROPERTIES
};
static GParamSpec* rygel_tracker_query_triplets_properties[RYGEL_TRACKER_QUERY_TRIPLETS_NUM_PROPERTIES];

#define RYGEL_TRACKER_TYPE_QUERY_TRIPLET (rygel_tracker_query_triplet_get_type ())
#define RYGEL_TRACKER_QUERY_TRIPLET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLET, RygelTrackerQueryTriplet))
#define RYGEL_TRACKER_QUERY_TRIPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RYGEL_TRACKER_TYPE_QUERY_TRIPLET, RygelTrackerQueryTripletClass))
#define RYGEL_TRACKER_IS_QUERY_TRIPLET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLET))
#define RYGEL_TRACKER_IS_QUERY_TRIPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RYGEL_TRACKER_TYPE_QUERY_TRIPLET))
#define RYGEL_TRACKER_QUERY_TRIPLET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RYGEL_TRACKER_TYPE_QUERY_TRIPLET, RygelTrackerQueryTripletClass))

typedef struct _RygelTrackerQueryTriplet RygelTrackerQueryTriplet;
typedef struct _RygelTrackerQueryTripletClass RygelTrackerQueryTripletClass;
#define _rygel_tracker_query_triplet_unref0(var) ((var == NULL) ? NULL : (var = (rygel_tracker_query_triplet_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _RygelTrackerQueryTripletPrivate RygelTrackerQueryTripletPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _RygelTrackerQueryTriplets {
	GeeArrayList parent_instance;
	RygelTrackerQueryTripletsPrivate * priv;
};

struct _RygelTrackerQueryTripletsClass {
	GeeArrayListClass parent_class;
};

struct _RygelTrackerQueryTriplet {
	GTypeInstance parent_instance;
	volatile int ref_count;
	RygelTrackerQueryTripletPrivate * priv;
	gchar* graph;
	gchar* subject;
	gchar* predicate;
	gchar* obj;
	RygelTrackerQueryTriplet* next;
};

struct _RygelTrackerQueryTripletClass {
	GTypeClass parent_class;
	void (*finalize) (RygelTrackerQueryTriplet *self);
};

static gpointer rygel_tracker_query_triplets_parent_class = NULL;

GType rygel_tracker_query_triplets_get_type (void) G_GNUC_CONST;
RygelTrackerQueryTriplets* rygel_tracker_query_triplets_new (void);
RygelTrackerQueryTriplets* rygel_tracker_query_triplets_construct (GType object_type);
gpointer rygel_tracker_query_triplet_ref (gpointer instance);
void rygel_tracker_query_triplet_unref (gpointer instance);
GParamSpec* rygel_tracker_param_spec_query_triplet (const gchar* name,
                                                    const gchar* nick,
                                                    const gchar* blurb,
                                                    GType object_type,
                                                    GParamFlags flags);
void rygel_tracker_value_set_query_triplet (GValue* value,
                                            gpointer v_object);
void rygel_tracker_value_take_query_triplet (GValue* value,
                                             gpointer v_object);
gpointer rygel_tracker_value_get_query_triplet (const GValue* value);
GType rygel_tracker_query_triplet_get_type (void) G_GNUC_CONST;
gboolean rygel_tracker_query_triplet_equal_func (RygelTrackerQueryTriplet* a,
                                                 RygelTrackerQueryTriplet* b);
RygelTrackerQueryTriplets* rygel_tracker_query_triplets_new_clone (RygelTrackerQueryTriplets* triplets);
RygelTrackerQueryTriplets* rygel_tracker_query_triplets_construct_clone (GType object_type,
                                                                         RygelTrackerQueryTriplets* triplets);
RygelTrackerQueryTriplet* rygel_tracker_query_triplet_new_clone (RygelTrackerQueryTriplet* triplet);
RygelTrackerQueryTriplet* rygel_tracker_query_triplet_construct_clone (GType object_type,
                                                                       RygelTrackerQueryTriplet* triplet);
gchar* rygel_tracker_query_triplets_serialize (RygelTrackerQueryTriplets* self);
gchar* rygel_tracker_query_triplet_to_string (RygelTrackerQueryTriplet* self,
                                              gboolean include_subject);
static gboolean rygel_tracker_query_triplets_check_graph_change (RygelTrackerQueryTriplets* self,
                                                          gint i);
static gboolean rygel_tracker_query_triplets_real_add (GeeAbstractCollection* base,
                                                RygelTrackerQueryTriplet* triplet);

RygelTrackerQueryTriplets*
rygel_tracker_query_triplets_construct (GType object_type)
{
	RygelTrackerQueryTriplets * self = NULL;
	self = (RygelTrackerQueryTriplets*) gee_array_list_construct (object_type, RYGEL_TRACKER_TYPE_QUERY_TRIPLET, (GBoxedCopyFunc) rygel_tracker_query_triplet_ref, (GDestroyNotify) rygel_tracker_query_triplet_unref, (GeeEqualDataFunc) rygel_tracker_query_triplet_equal_func, NULL, NULL);
	return self;
}

RygelTrackerQueryTriplets*
rygel_tracker_query_triplets_new (void)
{
	return rygel_tracker_query_triplets_construct (RYGEL_TRACKER_TYPE_QUERY_TRIPLETS);
}

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

RygelTrackerQueryTriplets*
rygel_tracker_query_triplets_construct_clone (GType object_type,
                                              RygelTrackerQueryTriplets* triplets)
{
	RygelTrackerQueryTriplets * self = NULL;
	g_return_val_if_fail (triplets != NULL, NULL);
	self = (RygelTrackerQueryTriplets*) gee_array_list_construct (object_type, RYGEL_TRACKER_TYPE_QUERY_TRIPLET, (GBoxedCopyFunc) rygel_tracker_query_triplet_ref, (GDestroyNotify) rygel_tracker_query_triplet_unref, (GeeEqualDataFunc) rygel_tracker_query_triplet_equal_func, NULL, NULL);
	{
		RygelTrackerQueryTriplets* _triplet_list = NULL;
		RygelTrackerQueryTriplets* _tmp0_;
		gint _triplet_size = 0;
		RygelTrackerQueryTriplets* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _triplet_index = 0;
		_tmp0_ = _g_object_ref0 (triplets);
		_triplet_list = _tmp0_;
		_tmp1_ = _triplet_list;
		_tmp2_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_triplet_size = _tmp3_;
		_triplet_index = -1;
		while (TRUE) {
			RygelTrackerQueryTriplet* triplet = NULL;
			RygelTrackerQueryTriplets* _tmp4_;
			gpointer _tmp5_;
			RygelTrackerQueryTriplet* _tmp6_;
			RygelTrackerQueryTriplet* _tmp7_;
			RygelTrackerQueryTriplet* _tmp8_;
			_triplet_index = _triplet_index + 1;
			if (!(_triplet_index < _triplet_size)) {
				break;
			}
			_tmp4_ = _triplet_list;
			_tmp5_ = gee_abstract_list_get ((GeeAbstractList*) _tmp4_, _triplet_index);
			triplet = (RygelTrackerQueryTriplet*) _tmp5_;
			_tmp6_ = triplet;
			_tmp7_ = rygel_tracker_query_triplet_new_clone (_tmp6_);
			_tmp8_ = _tmp7_;
			gee_abstract_collection_add ((GeeAbstractCollection*) self, _tmp8_);
			_rygel_tracker_query_triplet_unref0 (_tmp8_);
			_rygel_tracker_query_triplet_unref0 (triplet);
		}
		_g_object_unref0 (_triplet_list);
	}
	return self;
}

RygelTrackerQueryTriplets*
rygel_tracker_query_triplets_new_clone (RygelTrackerQueryTriplets* triplets)
{
	return rygel_tracker_query_triplets_construct_clone (RYGEL_TRACKER_TYPE_QUERY_TRIPLETS, triplets);
}

gchar*
rygel_tracker_query_triplets_serialize (RygelTrackerQueryTriplets* self)
{
	gchar* result = NULL;
	gchar* str = NULL;
	gchar* _tmp0_;
	gboolean include_subject = FALSE;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup ("");
	str = _tmp0_;
	include_subject = TRUE;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				gint _tmp3_;
				gint _tmp4_;
				gboolean _tmp5_ = FALSE;
				gpointer _tmp6_;
				RygelTrackerQueryTriplet* _tmp7_;
				const gchar* _tmp8_;
				gboolean _tmp9_;
				const gchar* _tmp17_;
				gpointer _tmp18_;
				RygelTrackerQueryTriplet* _tmp19_;
				gchar* _tmp20_;
				gchar* _tmp21_;
				gchar* _tmp22_;
				gint _tmp23_;
				gint _tmp24_;
				if (!_tmp1_) {
					gint _tmp2_;
					_tmp2_ = i;
					i = _tmp2_ + 1;
				}
				_tmp1_ = FALSE;
				_tmp3_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) self);
				_tmp4_ = _tmp3_;
				if (!(i < _tmp4_)) {
					break;
				}
				_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
				_tmp7_ = (RygelTrackerQueryTriplet*) _tmp6_;
				_tmp8_ = _tmp7_->graph;
				_tmp9_ = _tmp8_ != NULL;
				_rygel_tracker_query_triplet_unref0 (_tmp7_);
				if (_tmp9_) {
					_tmp5_ = include_subject;
				} else {
					_tmp5_ = FALSE;
				}
				if (_tmp5_) {
					const gchar* _tmp10_;
					gpointer _tmp11_;
					RygelTrackerQueryTriplet* _tmp12_;
					const gchar* _tmp13_;
					gchar* _tmp14_;
					gchar* _tmp15_;
					gchar* _tmp16_;
					_tmp10_ = str;
					_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
					_tmp12_ = (RygelTrackerQueryTriplet*) _tmp11_;
					_tmp13_ = _tmp12_->graph;
					_tmp14_ = g_strdup_printf ("GRAPH <%s> {", _tmp13_);
					_tmp15_ = _tmp14_;
					_tmp16_ = g_strconcat (_tmp10_, _tmp15_, NULL);
					_g_free0 (str);
					str = _tmp16_;
					_g_free0 (_tmp15_);
					_rygel_tracker_query_triplet_unref0 (_tmp12_);
				}
				_tmp17_ = str;
				_tmp18_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
				_tmp19_ = (RygelTrackerQueryTriplet*) _tmp18_;
				_tmp20_ = rygel_tracker_query_triplet_to_string (_tmp19_, include_subject);
				_tmp21_ = _tmp20_;
				_tmp22_ = g_strconcat (_tmp17_, _tmp21_, NULL);
				_g_free0 (str);
				str = _tmp22_;
				_g_free0 (_tmp21_);
				_rygel_tracker_query_triplet_unref0 (_tmp19_);
				_tmp23_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) self);
				_tmp24_ = _tmp23_;
				if (i < (_tmp24_ - 1)) {
					gboolean _tmp25_ = FALSE;
					gpointer _tmp26_;
					RygelTrackerQueryTriplet* _tmp27_;
					const gchar* _tmp28_;
					gpointer _tmp29_;
					RygelTrackerQueryTriplet* _tmp30_;
					const gchar* _tmp31_;
					gboolean _tmp32_;
					_tmp26_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
					_tmp27_ = (RygelTrackerQueryTriplet*) _tmp26_;
					_tmp28_ = _tmp27_->subject;
					_tmp29_ = gee_abstract_list_get ((GeeAbstractList*) self, i + 1);
					_tmp30_ = (RygelTrackerQueryTriplet*) _tmp29_;
					_tmp31_ = _tmp30_->subject;
					_tmp32_ = g_strcmp0 (_tmp28_, _tmp31_) != 0;
					_rygel_tracker_query_triplet_unref0 (_tmp30_);
					_rygel_tracker_query_triplet_unref0 (_tmp27_);
					if (_tmp32_) {
						_tmp25_ = TRUE;
					} else {
						_tmp25_ = rygel_tracker_query_triplets_check_graph_change (self, i);
					}
					include_subject = _tmp25_;
					if (include_subject) {
						const gchar* _tmp33_;
						gchar* _tmp34_;
						gpointer _tmp35_;
						RygelTrackerQueryTriplet* _tmp36_;
						const gchar* _tmp37_;
						gboolean _tmp38_;
						_tmp33_ = str;
						_tmp34_ = g_strconcat (_tmp33_, " . ", NULL);
						_g_free0 (str);
						str = _tmp34_;
						_tmp35_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
						_tmp36_ = (RygelTrackerQueryTriplet*) _tmp35_;
						_tmp37_ = _tmp36_->graph;
						_tmp38_ = _tmp37_ != NULL;
						_rygel_tracker_query_triplet_unref0 (_tmp36_);
						if (_tmp38_) {
							const gchar* _tmp39_;
							gchar* _tmp40_;
							_tmp39_ = str;
							_tmp40_ = g_strconcat (_tmp39_, "} ", NULL);
							_g_free0 (str);
							str = _tmp40_;
						}
					} else {
						const gchar* _tmp41_;
						gchar* _tmp42_;
						_tmp41_ = str;
						_tmp42_ = g_strconcat (_tmp41_, " ; ", NULL);
						_g_free0 (str);
						str = _tmp42_;
					}
				} else {
					gpointer _tmp43_;
					RygelTrackerQueryTriplet* _tmp44_;
					const gchar* _tmp45_;
					gboolean _tmp46_;
					_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
					_tmp44_ = (RygelTrackerQueryTriplet*) _tmp43_;
					_tmp45_ = _tmp44_->graph;
					_tmp46_ = _tmp45_ != NULL;
					_rygel_tracker_query_triplet_unref0 (_tmp44_);
					if (_tmp46_) {
						const gchar* _tmp47_;
						gchar* _tmp48_;
						_tmp47_ = str;
						_tmp48_ = g_strconcat (_tmp47_, " . } ", NULL);
						_g_free0 (str);
						str = _tmp48_;
					}
				}
			}
		}
	}
	result = str;
	return result;
}

static gboolean
rygel_tracker_query_triplets_real_add (GeeAbstractCollection* base,
                                       RygelTrackerQueryTriplet* triplet)
{
	RygelTrackerQueryTriplets * self;
	gboolean result = FALSE;
	self = (RygelTrackerQueryTriplets*) base;
	g_return_val_if_fail (triplet != NULL, FALSE);
	if (!gee_abstract_collection_contains ((GeeAbstractCollection*) self, triplet)) {
		result = GEE_ABSTRACT_COLLECTION_CLASS (rygel_tracker_query_triplets_parent_class)->add ((GeeAbstractCollection*) G_TYPE_CHECK_INSTANCE_CAST (self, GEE_TYPE_ARRAY_LIST, GeeArrayList), triplet);
		return result;
	}
	result = FALSE;
	return result;
}

static gboolean
rygel_tracker_query_triplets_check_graph_change (RygelTrackerQueryTriplets* self,
                                                 gint i)
{
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gpointer _tmp3_;
	RygelTrackerQueryTriplet* _tmp4_;
	const gchar* _tmp5_;
	gboolean _tmp6_;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp3_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
	_tmp4_ = (RygelTrackerQueryTriplet*) _tmp3_;
	_tmp5_ = _tmp4_->graph;
	_tmp6_ = _tmp5_ == NULL;
	_rygel_tracker_query_triplet_unref0 (_tmp4_);
	if (_tmp6_) {
		gpointer _tmp7_;
		RygelTrackerQueryTriplet* _tmp8_;
		const gchar* _tmp9_;
		_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) self, i + 1);
		_tmp8_ = (RygelTrackerQueryTriplet*) _tmp7_;
		_tmp9_ = _tmp8_->graph;
		_tmp2_ = _tmp9_ != NULL;
		_rygel_tracker_query_triplet_unref0 (_tmp8_);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		gboolean _tmp10_ = FALSE;
		gpointer _tmp11_;
		RygelTrackerQueryTriplet* _tmp12_;
		const gchar* _tmp13_;
		gboolean _tmp14_;
		_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
		_tmp12_ = (RygelTrackerQueryTriplet*) _tmp11_;
		_tmp13_ = _tmp12_->graph;
		_tmp14_ = _tmp13_ != NULL;
		_rygel_tracker_query_triplet_unref0 (_tmp12_);
		if (_tmp14_) {
			gpointer _tmp15_;
			RygelTrackerQueryTriplet* _tmp16_;
			const gchar* _tmp17_;
			_tmp15_ = gee_abstract_list_get ((GeeAbstractList*) self, i + 1);
			_tmp16_ = (RygelTrackerQueryTriplet*) _tmp15_;
			_tmp17_ = _tmp16_->graph;
			_tmp10_ = _tmp17_ == NULL;
			_rygel_tracker_query_triplet_unref0 (_tmp16_);
		} else {
			_tmp10_ = FALSE;
		}
		_tmp1_ = _tmp10_;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gpointer _tmp18_;
		RygelTrackerQueryTriplet* _tmp19_;
		const gchar* _tmp20_;
		gpointer _tmp21_;
		RygelTrackerQueryTriplet* _tmp22_;
		const gchar* _tmp23_;
		_tmp18_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
		_tmp19_ = (RygelTrackerQueryTriplet*) _tmp18_;
		_tmp20_ = _tmp19_->graph;
		_tmp21_ = gee_abstract_list_get ((GeeAbstractList*) self, i + 1);
		_tmp22_ = (RygelTrackerQueryTriplet*) _tmp21_;
		_tmp23_ = _tmp22_->graph;
		_tmp0_ = g_strcmp0 (_tmp20_, _tmp23_) != 0;
		_rygel_tracker_query_triplet_unref0 (_tmp22_);
		_rygel_tracker_query_triplet_unref0 (_tmp19_);
	}
	result = _tmp0_;
	return result;
}

static void
rygel_tracker_query_triplets_class_init (RygelTrackerQueryTripletsClass * klass)
{
	rygel_tracker_query_triplets_parent_class = g_type_class_peek_parent (klass);
	((GeeAbstractCollectionClass *) klass)->add = (gboolean (*) (GeeAbstractCollection*, gconstpointer)) rygel_tracker_query_triplets_real_add;
}

static void
rygel_tracker_query_triplets_instance_init (RygelTrackerQueryTriplets * self)
{
}

/**
 * Represents a list of SPARQL Triplet
 */
GType
rygel_tracker_query_triplets_get_type (void)
{
	static volatile gsize rygel_tracker_query_triplets_type_id__volatile = 0;
	if (g_once_init_enter (&rygel_tracker_query_triplets_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (RygelTrackerQueryTripletsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_tracker_query_triplets_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelTrackerQueryTriplets), 0, (GInstanceInitFunc) rygel_tracker_query_triplets_instance_init, NULL };
		GType rygel_tracker_query_triplets_type_id;
		rygel_tracker_query_triplets_type_id = g_type_register_static (GEE_TYPE_ARRAY_LIST, "RygelTrackerQueryTriplets", &g_define_type_info, 0);
		g_once_init_leave (&rygel_tracker_query_triplets_type_id__volatile, rygel_tracker_query_triplets_type_id);
	}
	return rygel_tracker_query_triplets_type_id__volatile;
}

