/* DatabaseSourceCollection.c generated by valac 0.56.19, the Vala compiler
 * generated from DatabaseSourceCollection.vala, do not modify */

/*
* Copyright (c) 2011-2013 Yorba Foundation
*
* 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 General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

#include "io.elementary.photos.h"
#include <glib.h>
#include <gee.h>
#include <glib-object.h>
#include <string.h>
#include <stdlib.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

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _DatabaseSourceCollectionPrivate {
	GetSourceDatabaseKey source_key_func;
	gpointer source_key_func_target;
	GeeHashMap* map;
};

struct _DatabaseSourceHoldingTankPrivate {
	GetSourceDatabaseKey get_key;
	gpointer get_key_target;
	GeeHashMap* map;
};

static gint DatabaseSourceCollection_private_offset;
static gpointer database_source_collection_parent_class = NULL;
static gint DatabaseSourceHoldingTank_private_offset;
static gpointer database_source_holding_tank_parent_class = NULL;

static guint _int64_hash_gee_hash_data_func (gconstpointer v,
                                      gpointer self);
static gboolean _int64_equal_gee_equal_data_func (gconstpointer a,
                                           gconstpointer b,
                                           gpointer self);
static gint64* _int64_dup (gint64* self);
static void database_source_collection_real_notify_items_added (DataCollection* base,
                                                         GeeIterable* added);
static void database_source_collection_real_notify_items_removed (DataCollection* base,
                                                           GeeIterable* removed);
static void database_source_collection_finalize (DataCollection * obj);
static GType database_source_collection_get_type_once (void);
static void database_source_holding_tank_real_notify_contents_altered (SourceHoldingTank* base,
                                                                GeeCollection* added,
                                                                GeeCollection* removed);
static void database_source_holding_tank_finalize (SourceHoldingTank * obj);
static GType database_source_holding_tank_get_type_once (void);

static inline gpointer
database_source_collection_get_instance_private (DatabaseSourceCollection* self)
{
	return G_STRUCT_MEMBER_P (self, DatabaseSourceCollection_private_offset);
}

static guint
_int64_hash_gee_hash_data_func (gconstpointer v,
                                gpointer self)
{
	guint result;
	result = int64_hash ((gint64*) v);
	return result;
}

static gboolean
_int64_equal_gee_equal_data_func (gconstpointer a,
                                  gconstpointer b,
                                  gpointer self)
{
	gboolean result;
	result = int64_equal ((gint64*) a, (gint64*) b);
	return result;
}

static gint64*
_int64_dup (gint64* self)
{
	gint64* dup;
	dup = g_new0 (gint64, 1);
	memcpy (dup, self, sizeof (gint64));
	return dup;
}

DatabaseSourceCollection*
database_source_collection_construct (GType object_type,
                                      const gchar* name,
                                      GetSourceDatabaseKey source_key_func,
                                      gpointer source_key_func_target)
{
	DatabaseSourceCollection* self = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	self = (DatabaseSourceCollection*) source_collection_construct (object_type, name);
	self->priv->source_key_func = source_key_func;
	self->priv->source_key_func_target = source_key_func_target;
	return self;
}

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

static void
database_source_collection_real_notify_items_added (DataCollection* base,
                                                    GeeIterable* added)
{
	DatabaseSourceCollection * self;
	self = (DatabaseSourceCollection*) base;
	g_return_if_fail (added != NULL);
	{
		GeeIterator* _object_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (added);
		_object_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			DataObject* object = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			DataSource* source = NULL;
			DataObject* _tmp4_;
			DataSource* _tmp5_;
			gint64 key = 0LL;
			GetSourceDatabaseKey _tmp6_;
			gpointer _tmp6__target;
			DataSource* _tmp7_;
			GeeHashMap* _tmp8_;
			GeeHashMap* _tmp9_;
			DataSource* _tmp10_;
			_tmp1_ = _object_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _object_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			object = (DataObject*) _tmp3_;
			_tmp4_ = object;
			_tmp5_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp4_, TYPE_DATA_SOURCE, DataSource));
			source = _tmp5_;
			_tmp6_ = self->priv->source_key_func;
			_tmp6__target = self->priv->source_key_func_target;
			_tmp7_ = source;
			key = _tmp6_ (_tmp7_, _tmp6__target);
			_tmp8_ = self->priv->map;
			_vala_assert (!gee_abstract_map_has_key ((GeeAbstractMap*) _tmp8_, &key), "!map.has_key (key)");
			_tmp9_ = self->priv->map;
			_tmp10_ = source;
			gee_abstract_map_set ((GeeAbstractMap*) _tmp9_, &key, _tmp10_);
			_g_object_unref0 (source);
			_g_object_unref0 (object);
		}
		_g_object_unref0 (_object_it);
	}
	DATA_COLLECTION_CLASS (database_source_collection_parent_class)->notify_items_added ((DataCollection*) G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_SOURCE_COLLECTION, SourceCollection), added);
}

static void
database_source_collection_real_notify_items_removed (DataCollection* base,
                                                      GeeIterable* removed)
{
	DatabaseSourceCollection * self;
	self = (DatabaseSourceCollection*) base;
	g_return_if_fail (removed != NULL);
	{
		GeeIterator* _object_it = NULL;
		GeeIterator* _tmp0_;
		_tmp0_ = gee_iterable_iterator (removed);
		_object_it = _tmp0_;
		while (TRUE) {
			GeeIterator* _tmp1_;
			DataObject* object = NULL;
			GeeIterator* _tmp2_;
			gpointer _tmp3_;
			gint64 key = 0LL;
			GetSourceDatabaseKey _tmp4_;
			gpointer _tmp4__target;
			DataObject* _tmp5_;
			gboolean is_removed = FALSE;
			GeeHashMap* _tmp6_;
			_tmp1_ = _object_it;
			if (!gee_iterator_next (_tmp1_)) {
				break;
			}
			_tmp2_ = _object_it;
			_tmp3_ = gee_iterator_get (_tmp2_);
			object = (DataObject*) _tmp3_;
			_tmp4_ = self->priv->source_key_func;
			_tmp4__target = self->priv->source_key_func_target;
			_tmp5_ = object;
			key = _tmp4_ (G_TYPE_CHECK_INSTANCE_CAST (_tmp5_, TYPE_DATA_SOURCE, DataSource), _tmp4__target);
			_tmp6_ = self->priv->map;
			is_removed = gee_abstract_map_unset ((GeeAbstractMap*) _tmp6_, &key, NULL);
			_vala_assert (is_removed, "is_removed");
			_g_object_unref0 (object);
		}
		_g_object_unref0 (_object_it);
	}
	DATA_COLLECTION_CLASS (database_source_collection_parent_class)->notify_items_removed ((DataCollection*) G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_SOURCE_COLLECTION, SourceCollection), removed);
}

DataSource*
database_source_collection_fetch_by_key (DatabaseSourceCollection* self,
                                         gint64 key)
{
	GeeHashMap* _tmp0_;
	gpointer _tmp1_;
	DataSource* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->map;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, &key);
	result = (DataSource*) _tmp1_;
	return result;
}

static void
database_source_collection_class_init (DatabaseSourceCollectionClass * klass,
                                       gpointer klass_data)
{
	database_source_collection_parent_class = g_type_class_peek_parent (klass);
	((DataCollectionClass *) klass)->finalize = database_source_collection_finalize;
	g_type_class_adjust_private_offset (klass, &DatabaseSourceCollection_private_offset);
	((DataCollectionClass *) klass)->notify_items_added = (void (*) (DataCollection*, GeeIterable*)) database_source_collection_real_notify_items_added;
	((DataCollectionClass *) klass)->notify_items_removed = (void (*) (DataCollection*, GeeIterable*)) database_source_collection_real_notify_items_removed;
}

static void
database_source_collection_instance_init (DatabaseSourceCollection * self,
                                          gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = database_source_collection_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, TYPE_DATA_SOURCE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _int64_hash_gee_hash_data_func, NULL, NULL, _int64_equal_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->map = _tmp0_;
}

static void
database_source_collection_finalize (DataCollection * obj)
{
	DatabaseSourceCollection * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_DATABASE_SOURCE_COLLECTION, DatabaseSourceCollection);
	_g_object_unref0 (self->priv->map);
	DATA_COLLECTION_CLASS (database_source_collection_parent_class)->finalize (obj);
}

static GType
database_source_collection_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DatabaseSourceCollectionClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) database_source_collection_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DatabaseSourceCollection), 0, (GInstanceInitFunc) database_source_collection_instance_init, NULL };
	GType database_source_collection_type_id;
	database_source_collection_type_id = g_type_register_static (TYPE_SOURCE_COLLECTION, "DatabaseSourceCollection", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	DatabaseSourceCollection_private_offset = g_type_add_instance_private (database_source_collection_type_id, sizeof (DatabaseSourceCollectionPrivate));
	return database_source_collection_type_id;
}

GType
database_source_collection_get_type (void)
{
	static volatile gsize database_source_collection_type_id__once = 0;
	if (g_once_init_enter (&database_source_collection_type_id__once)) {
		GType database_source_collection_type_id;
		database_source_collection_type_id = database_source_collection_get_type_once ();
		g_once_init_leave (&database_source_collection_type_id__once, database_source_collection_type_id);
	}
	return database_source_collection_type_id__once;
}

static inline gpointer
database_source_holding_tank_get_instance_private (DatabaseSourceHoldingTank* self)
{
	return G_STRUCT_MEMBER_P (self, DatabaseSourceHoldingTank_private_offset);
}

DatabaseSourceHoldingTank*
database_source_holding_tank_construct (GType object_type,
                                        SourceCollection* sources,
                                        SourceHoldingTankCheckToKeep check_to_keep,
                                        gpointer check_to_keep_target,
                                        GetSourceDatabaseKey get_key,
                                        gpointer get_key_target)
{
	DatabaseSourceHoldingTank* self = NULL;
	g_return_val_if_fail (sources != NULL, NULL);
	self = (DatabaseSourceHoldingTank*) source_holding_tank_construct (object_type, sources, check_to_keep, check_to_keep_target);
	self->priv->get_key = get_key;
	self->priv->get_key_target = get_key_target;
	return self;
}

DatabaseSourceHoldingTank*
database_source_holding_tank_new (SourceCollection* sources,
                                  SourceHoldingTankCheckToKeep check_to_keep,
                                  gpointer check_to_keep_target,
                                  GetSourceDatabaseKey get_key,
                                  gpointer get_key_target)
{
	return database_source_holding_tank_construct (TYPE_DATABASE_SOURCE_HOLDING_TANK, sources, check_to_keep, check_to_keep_target, get_key, get_key_target);
}

DataSource*
database_source_holding_tank_get_by_id (DatabaseSourceHoldingTank* self,
                                        gint64 id)
{
	GeeHashMap* _tmp0_;
	gpointer _tmp1_;
	DataSource* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->map;
	_tmp1_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp0_, &id);
	result = (DataSource*) _tmp1_;
	return result;
}

static void
database_source_holding_tank_real_notify_contents_altered (SourceHoldingTank* base,
                                                           GeeCollection* added,
                                                           GeeCollection* removed)
{
	DatabaseSourceHoldingTank * self;
	self = (DatabaseSourceHoldingTank*) base;
	if (added != NULL) {
		{
			GeeIterator* _source_it = NULL;
			GeeIterator* _tmp0_;
			_tmp0_ = gee_iterable_iterator ((GeeIterable*) added);
			_source_it = _tmp0_;
			while (TRUE) {
				GeeIterator* _tmp1_;
				DataSource* source = NULL;
				GeeIterator* _tmp2_;
				gpointer _tmp3_;
				GeeHashMap* _tmp4_;
				GetSourceDatabaseKey _tmp5_;
				gpointer _tmp5__target;
				DataSource* _tmp6_;
				gint64 _tmp7_;
				DataSource* _tmp8_;
				_tmp1_ = _source_it;
				if (!gee_iterator_next (_tmp1_)) {
					break;
				}
				_tmp2_ = _source_it;
				_tmp3_ = gee_iterator_get (_tmp2_);
				source = (DataSource*) _tmp3_;
				_tmp4_ = self->priv->map;
				_tmp5_ = self->priv->get_key;
				_tmp5__target = self->priv->get_key_target;
				_tmp6_ = source;
				_tmp7_ = _tmp5_ (_tmp6_, _tmp5__target);
				_tmp8_ = source;
				gee_abstract_map_set ((GeeAbstractMap*) _tmp4_, &_tmp7_, _tmp8_);
				_g_object_unref0 (source);
			}
			_g_object_unref0 (_source_it);
		}
	}
	if (removed != NULL) {
		{
			GeeIterator* _source_it = NULL;
			GeeIterator* _tmp9_;
			_tmp9_ = gee_iterable_iterator ((GeeIterable*) removed);
			_source_it = _tmp9_;
			while (TRUE) {
				GeeIterator* _tmp10_;
				DataSource* source = NULL;
				GeeIterator* _tmp11_;
				gpointer _tmp12_;
				GeeHashMap* _tmp13_;
				GetSourceDatabaseKey _tmp14_;
				gpointer _tmp14__target;
				DataSource* _tmp15_;
				gint64 _tmp16_;
				_tmp10_ = _source_it;
				if (!gee_iterator_next (_tmp10_)) {
					break;
				}
				_tmp11_ = _source_it;
				_tmp12_ = gee_iterator_get (_tmp11_);
				source = (DataSource*) _tmp12_;
				_tmp13_ = self->priv->map;
				_tmp14_ = self->priv->get_key;
				_tmp14__target = self->priv->get_key_target;
				_tmp15_ = source;
				_tmp16_ = _tmp14_ (_tmp15_, _tmp14__target);
				gee_abstract_map_unset ((GeeAbstractMap*) _tmp13_, &_tmp16_, NULL);
				_g_object_unref0 (source);
			}
			_g_object_unref0 (_source_it);
		}
	}
	SOURCE_HOLDING_TANK_CLASS (database_source_holding_tank_parent_class)->notify_contents_altered (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_SOURCE_HOLDING_TANK, SourceHoldingTank), added, removed);
}

static void
database_source_holding_tank_class_init (DatabaseSourceHoldingTankClass * klass,
                                         gpointer klass_data)
{
	database_source_holding_tank_parent_class = g_type_class_peek_parent (klass);
	((SourceHoldingTankClass *) klass)->finalize = database_source_holding_tank_finalize;
	g_type_class_adjust_private_offset (klass, &DatabaseSourceHoldingTank_private_offset);
	((SourceHoldingTankClass *) klass)->notify_contents_altered = (void (*) (SourceHoldingTank*, GeeCollection*, GeeCollection*)) database_source_holding_tank_real_notify_contents_altered;
}

static void
database_source_holding_tank_instance_init (DatabaseSourceHoldingTank * self,
                                            gpointer klass)
{
	GeeHashMap* _tmp0_;
	self->priv = database_source_holding_tank_get_instance_private (self);
	_tmp0_ = gee_hash_map_new (G_TYPE_INT64, (GBoxedCopyFunc) _int64_dup, (GDestroyNotify) g_free, TYPE_DATA_SOURCE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _int64_hash_gee_hash_data_func, NULL, NULL, _int64_equal_gee_equal_data_func, NULL, NULL, NULL, NULL, NULL);
	self->priv->map = _tmp0_;
}

static void
database_source_holding_tank_finalize (SourceHoldingTank * obj)
{
	DatabaseSourceHoldingTank * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_DATABASE_SOURCE_HOLDING_TANK, DatabaseSourceHoldingTank);
	_g_object_unref0 (self->priv->map);
	SOURCE_HOLDING_TANK_CLASS (database_source_holding_tank_parent_class)->finalize (obj);
}

static GType
database_source_holding_tank_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DatabaseSourceHoldingTankClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) database_source_holding_tank_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DatabaseSourceHoldingTank), 0, (GInstanceInitFunc) database_source_holding_tank_instance_init, NULL };
	GType database_source_holding_tank_type_id;
	database_source_holding_tank_type_id = g_type_register_static (TYPE_SOURCE_HOLDING_TANK, "DatabaseSourceHoldingTank", &g_define_type_info, 0);
	DatabaseSourceHoldingTank_private_offset = g_type_add_instance_private (database_source_holding_tank_type_id, sizeof (DatabaseSourceHoldingTankPrivate));
	return database_source_holding_tank_type_id;
}

GType
database_source_holding_tank_get_type (void)
{
	static volatile gsize database_source_holding_tank_type_id__once = 0;
	if (g_once_init_enter (&database_source_holding_tank_type_id__once)) {
		GType database_source_holding_tank_type_id;
		database_source_holding_tank_type_id = database_source_holding_tank_get_type_once ();
		g_once_init_leave (&database_source_holding_tank_type_id__once, database_source_holding_tank_type_id);
	}
	return database_source_holding_tank_type_id__once;
}

