/* localsearch-query-triplets.c generated by valac 0.56.19, the Vala compiler
 * generated from localsearch-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-localsearch.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.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  {
	RYGEL_LOCAL_SEARCH_QUERY_TRIPLETS_0_PROPERTY,
	RYGEL_LOCAL_SEARCH_QUERY_TRIPLETS_NUM_PROPERTIES
};
static GParamSpec* rygel_local_search_query_triplets_properties[RYGEL_LOCAL_SEARCH_QUERY_TRIPLETS_NUM_PROPERTIES];
#define _rygel_local_search_query_triplet_unref0(var) ((var == NULL) ? NULL : (var = (rygel_local_search_query_triplet_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

static gpointer rygel_local_search_query_triplets_parent_class = NULL;

static gboolean rygel_local_search_query_triplets_check_graph_change (RygelLocalSearchQueryTriplets* self,
                                                               gint i);
static gboolean rygel_local_search_query_triplets_real_add (GeeAbstractCollection* base,
                                                     RygelLocalSearchQueryTriplet* triplet);
static GType rygel_local_search_query_triplets_get_type_once (void);

RygelLocalSearchQueryTriplets*
rygel_local_search_query_triplets_construct (GType object_type)
{
	RygelLocalSearchQueryTriplets * self = NULL;
	self = (RygelLocalSearchQueryTriplets*) gee_array_list_construct (object_type, RYGEL_LOCAL_SEARCH_TYPE_QUERY_TRIPLET, (GBoxedCopyFunc) rygel_local_search_query_triplet_ref, (GDestroyNotify) rygel_local_search_query_triplet_unref, (GeeEqualDataFunc) rygel_local_search_query_triplet_equal_func, NULL, NULL);
	return self;
}

RygelLocalSearchQueryTriplets*
rygel_local_search_query_triplets_new (void)
{
	return rygel_local_search_query_triplets_construct (RYGEL_LOCAL_SEARCH_TYPE_QUERY_TRIPLETS);
}

RygelLocalSearchQueryTriplets*
rygel_local_search_query_triplets_construct_clone (GType object_type,
                                                   RygelLocalSearchQueryTriplets* triplets)
{
	RygelLocalSearchQueryTriplets * self = NULL;
	g_return_val_if_fail (triplets != NULL, NULL);
	self = (RygelLocalSearchQueryTriplets*) gee_array_list_construct (object_type, RYGEL_LOCAL_SEARCH_TYPE_QUERY_TRIPLET, (GBoxedCopyFunc) rygel_local_search_query_triplet_ref, (GDestroyNotify) rygel_local_search_query_triplet_unref, (GeeEqualDataFunc) rygel_local_search_query_triplet_equal_func, NULL, NULL);
	{
		RygelLocalSearchQueryTriplets* _triplet_list = NULL;
		gint _triplet_size = 0;
		RygelLocalSearchQueryTriplets* _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_;
			RygelLocalSearchQueryTriplet* triplet = NULL;
			RygelLocalSearchQueryTriplets* _tmp5_;
			gpointer _tmp6_;
			RygelLocalSearchQueryTriplet* _tmp7_;
			RygelLocalSearchQueryTriplet* _tmp8_;
			RygelLocalSearchQueryTriplet* _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 = (RygelLocalSearchQueryTriplet*) _tmp6_;
			_tmp7_ = triplet;
			_tmp8_ = rygel_local_search_query_triplet_new_clone (_tmp7_);
			_tmp9_ = _tmp8_;
			gee_abstract_collection_add ((GeeAbstractCollection*) self, _tmp9_);
			_rygel_local_search_query_triplet_unref0 (_tmp9_);
			_rygel_local_search_query_triplet_unref0 (triplet);
		}
	}
	return self;
}

RygelLocalSearchQueryTriplets*
rygel_local_search_query_triplets_new_clone (RygelLocalSearchQueryTriplets* triplets)
{
	return rygel_local_search_query_triplets_construct_clone (RYGEL_LOCAL_SEARCH_TYPE_QUERY_TRIPLETS, triplets);
}

gchar*
rygel_local_search_query_triplets_serialize (RygelLocalSearchQueryTriplets* 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_;
				RygelLocalSearchQueryTriplet* _tmp7_;
				const gchar* _tmp8_;
				gboolean _tmp9_;
				const gchar* _tmp17_;
				gpointer _tmp18_;
				RygelLocalSearchQueryTriplet* _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_ = (RygelLocalSearchQueryTriplet*) _tmp6_;
				_tmp8_ = _tmp7_->graph;
				_tmp9_ = _tmp8_ != NULL;
				_rygel_local_search_query_triplet_unref0 (_tmp7_);
				if (_tmp9_) {
					_tmp5_ = include_subject;
				} else {
					_tmp5_ = FALSE;
				}
				if (_tmp5_) {
					const gchar* _tmp10_;
					gpointer _tmp11_;
					RygelLocalSearchQueryTriplet* _tmp12_;
					const gchar* _tmp13_;
					gchar* _tmp14_;
					gchar* _tmp15_;
					gchar* _tmp16_;
					_tmp10_ = str;
					_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
					_tmp12_ = (RygelLocalSearchQueryTriplet*) _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_local_search_query_triplet_unref0 (_tmp12_);
				}
				_tmp17_ = str;
				_tmp18_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
				_tmp19_ = (RygelLocalSearchQueryTriplet*) _tmp18_;
				_tmp20_ = rygel_local_search_query_triplet_to_string (_tmp19_, include_subject);
				_tmp21_ = _tmp20_;
				_tmp22_ = g_strconcat (_tmp17_, _tmp21_, NULL);
				_g_free0 (str);
				str = _tmp22_;
				_g_free0 (_tmp21_);
				_rygel_local_search_query_triplet_unref0 (_tmp19_);
				_tmp23_ = gee_abstract_collection_get_size ((GeeAbstractCollection*) self);
				_tmp24_ = _tmp23_;
				if (i < (_tmp24_ - 1)) {
					gboolean _tmp25_ = FALSE;
					gpointer _tmp26_;
					RygelLocalSearchQueryTriplet* _tmp27_;
					const gchar* _tmp28_;
					gpointer _tmp29_;
					RygelLocalSearchQueryTriplet* _tmp30_;
					const gchar* _tmp31_;
					gboolean _tmp32_;
					_tmp26_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
					_tmp27_ = (RygelLocalSearchQueryTriplet*) _tmp26_;
					_tmp28_ = _tmp27_->subject;
					_tmp29_ = gee_abstract_list_get ((GeeAbstractList*) self, i + 1);
					_tmp30_ = (RygelLocalSearchQueryTriplet*) _tmp29_;
					_tmp31_ = _tmp30_->subject;
					_tmp32_ = g_strcmp0 (_tmp28_, _tmp31_) != 0;
					_rygel_local_search_query_triplet_unref0 (_tmp30_);
					_rygel_local_search_query_triplet_unref0 (_tmp27_);
					if (_tmp32_) {
						_tmp25_ = TRUE;
					} else {
						_tmp25_ = rygel_local_search_query_triplets_check_graph_change (self, i);
					}
					include_subject = _tmp25_;
					if (include_subject) {
						const gchar* _tmp33_;
						gchar* _tmp34_;
						gpointer _tmp35_;
						RygelLocalSearchQueryTriplet* _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_ = (RygelLocalSearchQueryTriplet*) _tmp35_;
						_tmp37_ = _tmp36_->graph;
						_tmp38_ = _tmp37_ != NULL;
						_rygel_local_search_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_;
					RygelLocalSearchQueryTriplet* _tmp44_;
					const gchar* _tmp45_;
					gboolean _tmp46_;
					_tmp43_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
					_tmp44_ = (RygelLocalSearchQueryTriplet*) _tmp43_;
					_tmp45_ = _tmp44_->graph;
					_tmp46_ = _tmp45_ != NULL;
					_rygel_local_search_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_local_search_query_triplets_real_add (GeeAbstractCollection* base,
                                            RygelLocalSearchQueryTriplet* triplet)
{
	RygelLocalSearchQueryTriplets * self;
	gboolean result;
	self = (RygelLocalSearchQueryTriplets*) base;
	g_return_val_if_fail (triplet != NULL, FALSE);
	if (!gee_abstract_collection_contains ((GeeAbstractCollection*) self, triplet)) {
		result = GEE_ABSTRACT_COLLECTION_CLASS (rygel_local_search_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_local_search_query_triplets_check_graph_change (RygelLocalSearchQueryTriplets* self,
                                                      gint i)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	gboolean _tmp2_ = FALSE;
	gpointer _tmp3_;
	RygelLocalSearchQueryTriplet* _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_ = (RygelLocalSearchQueryTriplet*) _tmp3_;
	_tmp5_ = _tmp4_->graph;
	_tmp6_ = _tmp5_ == NULL;
	_rygel_local_search_query_triplet_unref0 (_tmp4_);
	if (_tmp6_) {
		gpointer _tmp7_;
		RygelLocalSearchQueryTriplet* _tmp8_;
		const gchar* _tmp9_;
		_tmp7_ = gee_abstract_list_get ((GeeAbstractList*) self, i + 1);
		_tmp8_ = (RygelLocalSearchQueryTriplet*) _tmp7_;
		_tmp9_ = _tmp8_->graph;
		_tmp2_ = _tmp9_ != NULL;
		_rygel_local_search_query_triplet_unref0 (_tmp8_);
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		_tmp1_ = TRUE;
	} else {
		gboolean _tmp10_ = FALSE;
		gpointer _tmp11_;
		RygelLocalSearchQueryTriplet* _tmp12_;
		const gchar* _tmp13_;
		gboolean _tmp14_;
		_tmp11_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
		_tmp12_ = (RygelLocalSearchQueryTriplet*) _tmp11_;
		_tmp13_ = _tmp12_->graph;
		_tmp14_ = _tmp13_ != NULL;
		_rygel_local_search_query_triplet_unref0 (_tmp12_);
		if (_tmp14_) {
			gpointer _tmp15_;
			RygelLocalSearchQueryTriplet* _tmp16_;
			const gchar* _tmp17_;
			_tmp15_ = gee_abstract_list_get ((GeeAbstractList*) self, i + 1);
			_tmp16_ = (RygelLocalSearchQueryTriplet*) _tmp15_;
			_tmp17_ = _tmp16_->graph;
			_tmp10_ = _tmp17_ == NULL;
			_rygel_local_search_query_triplet_unref0 (_tmp16_);
		} else {
			_tmp10_ = FALSE;
		}
		_tmp1_ = _tmp10_;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		gpointer _tmp18_;
		RygelLocalSearchQueryTriplet* _tmp19_;
		const gchar* _tmp20_;
		gpointer _tmp21_;
		RygelLocalSearchQueryTriplet* _tmp22_;
		const gchar* _tmp23_;
		_tmp18_ = gee_abstract_list_get ((GeeAbstractList*) self, i);
		_tmp19_ = (RygelLocalSearchQueryTriplet*) _tmp18_;
		_tmp20_ = _tmp19_->graph;
		_tmp21_ = gee_abstract_list_get ((GeeAbstractList*) self, i + 1);
		_tmp22_ = (RygelLocalSearchQueryTriplet*) _tmp21_;
		_tmp23_ = _tmp22_->graph;
		_tmp0_ = g_strcmp0 (_tmp20_, _tmp23_) != 0;
		_rygel_local_search_query_triplet_unref0 (_tmp22_);
		_rygel_local_search_query_triplet_unref0 (_tmp19_);
	}
	result = _tmp0_;
	return result;
}

static void
rygel_local_search_query_triplets_class_init (RygelLocalSearchQueryTripletsClass * klass,
                                              gpointer klass_data)
{
	rygel_local_search_query_triplets_parent_class = g_type_class_peek_parent (klass);
	((GeeAbstractCollectionClass *) klass)->add = (gboolean (*) (GeeAbstractCollection*, gconstpointer)) rygel_local_search_query_triplets_real_add;
}

static void
rygel_local_search_query_triplets_instance_init (RygelLocalSearchQueryTriplets * self,
                                                 gpointer klass)
{
}

/**
 * Represents a list of SPARQL Triplet
 */
 G_GNUC_NO_INLINE static GType
rygel_local_search_query_triplets_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (RygelLocalSearchQueryTripletsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) rygel_local_search_query_triplets_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (RygelLocalSearchQueryTriplets), 0, (GInstanceInitFunc) rygel_local_search_query_triplets_instance_init, NULL };
	GType rygel_local_search_query_triplets_type_id;
	rygel_local_search_query_triplets_type_id = g_type_register_static (GEE_TYPE_ARRAY_LIST, "RygelLocalSearchQueryTriplets", &g_define_type_info, 0);
	return rygel_local_search_query_triplets_type_id;
}

GType
rygel_local_search_query_triplets_get_type (void)
{
	static volatile gsize rygel_local_search_query_triplets_type_id__once = 0;
	if (g_once_init_enter (&rygel_local_search_query_triplets_type_id__once)) {
		GType rygel_local_search_query_triplets_type_id;
		rygel_local_search_query_triplets_type_id = rygel_local_search_query_triplets_get_type_once ();
		g_once_init_leave (&rygel_local_search_query_triplets_type_id__once, rygel_local_search_query_triplets_type_id);
	}
	return rygel_local_search_query_triplets_type_id__once;
}

