/* rygel-tracker-query-triplets.c generated by valac 0.56.1, 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 "rygel-tracker3.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

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_query_triplet_unref0(var) ((var == NULL) ? NULL : (var = (rygel_tracker_query_triplet_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

static gpointer rygel_tracker_query_triplets_parent_class = NULL;

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);
static GType rygel_tracker_query_triplets_get_type_once (void);

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);
}

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;
		gint _triplet_size = 0;
		RygelTrackerQueryTriplets* _tmp0_;
		gint _tmp1_;
		gint _tmp2_;
		gint _triplet_index = 0;
		_triplet_list = triplets;
		_tmp0_ = _triplet_list;
		_tmp1_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) _tmp0_);
		_tmp2_ = _tmp1_;
		_triplet_size = _tmp2_;
		_triplet_index = -1;
		while (TRUE) {
			gint _tmp3_;
			gint _tmp4_;
			RygelTrackerQueryTriplet* triplet = NULL;
			RygelTrackerQueryTriplets* _tmp5_;
			gpointer _tmp6_;
			RygelTrackerQueryTriplet* _tmp7_;
			RygelTrackerQueryTriplet* _tmp8_;
			RygelTrackerQueryTriplet* _tmp9_;
			_triplet_index = _triplet_index + 1;
			_tmp3_ = _triplet_index;
			_tmp4_ = _triplet_size;
			if (!(_tmp3_ < _tmp4_)) {
				break;
			}
			_tmp5_ = _triplet_list;
			_tmp6_ = gee_abstract_list_get ((GeeAbstractList*) _tmp5_, _triplet_index);
			triplet = (RygelTrackerQueryTriplet*) _tmp6_;
			_tmp7_ = triplet;
			_tmp8_ = rygel_tracker_query_triplet_new_clone (_tmp7_);
			_tmp9_ = _tmp8_;
			gee_abstract_collection_add ((GeeAbstractCollection*) self, _tmp9_);
			_rygel_tracker_query_triplet_unref0 (_tmp9_);
			_rygel_tracker_query_triplet_unref0 (triplet);
		}
	}
	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* str = NULL;
	gchar* _tmp0_;
	gboolean include_subject = FALSE;
	gchar* result;
	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;
	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 _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gpointer _tmp3_;
	RygelTrackerQueryTriplet* _tmp4_;
	const gchar* _tmp5_;
	gboolean _tmp6_;
	gboolean result;
	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,
                                         gpointer klass_data)
{
	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,
                                            gpointer klass)
{
}

/**
 * Represents a list of SPARQL Triplet
 */
static GType
rygel_tracker_query_triplets_get_type_once (void)
{
	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);
	return rygel_tracker_query_triplets_type_id;
}

GType
rygel_tracker_query_triplets_get_type (void)
{
	static volatile gsize rygel_tracker_query_triplets_type_id__once = 0;
	if (g_once_init_enter (&rygel_tracker_query_triplets_type_id__once)) {
		GType rygel_tracker_query_triplets_type_id;
		rygel_tracker_query_triplets_type_id = rygel_tracker_query_triplets_get_type_once ();
		g_once_init_leave (&rygel_tracker_query_triplets_type_id__once, rygel_tracker_query_triplets_type_id);
	}
	return rygel_tracker_query_triplets_type_id__once;
}

