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

/*
 * Copyright (c) 2024-2025 focus-timer contributors
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Authors: Kamil Prusko <kamilprusko@gmail.com>
 */

#include "ft_core.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <glib-object.h>
#include <gom/gom.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_free0(var) (var = (g_free (var), NULL))
enum  {
	FT_GAP_0_PROPERTY,
	FT_GAP_START_TIME_PROPERTY,
	FT_GAP_END_TIME_PROPERTY,
	FT_GAP_DURATION_PROPERTY,
	FT_GAP_FLAGS_PROPERTY,
	FT_GAP_TIME_BLOCK_PROPERTY,
	FT_GAP_NUM_PROPERTIES
};
static GParamSpec* ft_gap_properties[FT_GAP_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	FT_GAP_CHANGED_SIGNAL,
	FT_GAP_NUM_SIGNALS
};
static guint ft_gap_signals[FT_GAP_NUM_SIGNALS] = {0};
#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 _FtGapPrivate {
	FtTimeBlock* _time_block;
	gint64 _start_time;
	gint64 _end_time;
	FtGapFlags _flags;
};

static gint FtGap_private_offset;
static gpointer ft_gap_parent_class = NULL;
static FtSchedulableIface * ft_gap_ft_schedulable_parent_iface = NULL;

static void _vala_array_add17 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void _vala_array_add18 (gchar** * array,
                        gint* length,
                        gint* size,
                        gchar* value);
static void ft_gap_emit_changed (FtGap* self);
static void ft_gap_real_set_time_range (FtSchedulable* base,
                                 gint64 start_time,
                                 gint64 end_time);
static void ft_gap_real_move_by (FtSchedulable* base,
                          gint64 offset);
static void ft_gap_real_move_to (FtSchedulable* base,
                          gint64 start_time);
VALA_EXTERN gboolean ft_gap_should_create_entry (FtGap* self);
VALA_EXTERN gboolean ft_gap_should_update_entry (FtGap* self);
VALA_EXTERN FtGapEntry* ft_gap_create_or_update_entry (FtGap* self);
VALA_EXTERN void ft_gap_unset_entry (FtGap* self);
static void ft_gap_real_dispose (GObject* base);
static void ft_gap_finalize (GObject * obj);
static GType ft_gap_get_type_once (void);
static void _vala_ft_gap_get_property (GObject * object,
                                guint property_id,
                                GValue * value,
                                GParamSpec * pspec);
static void _vala_ft_gap_set_property (GObject * object,
                                guint property_id,
                                const GValue * value,
                                GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gchar*
string_strip (const gchar* self)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_strdup (self);
	_result_ = _tmp0_;
	g_strstrip (_result_);
	result = _result_;
	return result;
}

FtGapFlags
ft_gap_flags_from_string (const gchar* str)
{
	FtGapFlags _result_ = 0U;
	gchar** _tmp0_;
	gchar** _tmp1_;
	FtGapFlags result;
	_result_ = FT_GAP_FLAGS_DEFAULT;
	if (str == NULL) {
		result = _result_;
		return result;
	}
	_tmp1_ = _tmp0_ = g_strsplit (str, "|", 0);
	{
		gchar** part_collection = NULL;
		gint part_collection_length1 = 0;
		gint _part_collection_size_ = 0;
		gint part_it = 0;
		part_collection = _tmp1_;
		part_collection_length1 = _vala_array_length (_tmp0_);
		for (part_it = 0; part_it < part_collection_length1; part_it = part_it + 1) {
			gchar* _tmp2_;
			gchar* part = NULL;
			_tmp2_ = g_strdup (part_collection[part_it]);
			part = _tmp2_;
			{
				const gchar* _tmp3_;
				gchar* _tmp4_;
				gchar* _tmp5_;
				GQuark _tmp7_ = 0U;
				static GQuark _tmp6_label0 = 0;
				static GQuark _tmp6_label1 = 0;
				static GQuark _tmp6_label2 = 0;
				_tmp3_ = part;
				_tmp4_ = string_strip (_tmp3_);
				_tmp5_ = _tmp4_;
				_tmp7_ = (NULL == _tmp5_) ? 0 : g_quark_from_string (_tmp5_);
				g_free (_tmp5_);
				if (_tmp7_ == ((0 != _tmp6_label0) ? _tmp6_label0 : (_tmp6_label0 = g_quark_from_static_string ("default")))) {
					switch (0) {
						default:
						{
							break;
						}
					}
				} else if (_tmp7_ == ((0 != _tmp6_label1) ? _tmp6_label1 : (_tmp6_label1 = g_quark_from_static_string ("interruption")))) {
					switch (0) {
						default:
						{
							_result_ |= FT_GAP_FLAGS_INTERRUPTION;
							break;
						}
					}
				} else if (_tmp7_ == ((0 != _tmp6_label2) ? _tmp6_label2 : (_tmp6_label2 = g_quark_from_static_string ("sleep")))) {
					switch (0) {
						default:
						{
							_result_ |= FT_GAP_FLAGS_SLEEP;
							break;
						}
					}
				} else {
					switch (0) {
						default:
						{
							const gchar* _tmp8_;
							gchar* _tmp9_;
							gchar* _tmp10_;
							_tmp8_ = part;
							_tmp9_ = string_strip (_tmp8_);
							_tmp10_ = _tmp9_;
							g_warning ("gap.vala:42: Unknown `GapFlags` value '%s'", _tmp10_);
							_g_free0 (_tmp10_);
							break;
						}
					}
				}
				_g_free0 (part);
			}
		}
		part_collection = (_vala_array_free (part_collection, part_collection_length1, (GDestroyNotify) g_free), NULL);
	}
	result = _result_;
	return result;
}

static void
_vala_array_add17 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static void
_vala_array_add18 (gchar** * array,
                   gint* length,
                   gint* size,
                   gchar* value)
{
	if ((*length) == (*size)) {
		*size = (*size) ? (2 * (*size)) : 4;
		*array = g_renew (gchar*, *array, (*size) + 1);
	}
	(*array)[(*length)++] = value;
	(*array)[*length] = NULL;
}

static gchar*
_vala_g_strjoinv (const gchar* separator,
                  gchar** str_array,
                  gint str_array_length1)
{
	gboolean _tmp0_ = FALSE;
	gchar* result;
	if (separator == NULL) {
		separator = "";
	}
	if (str_array != NULL) {
		gboolean _tmp1_ = FALSE;
		if (str_array_length1 > 0) {
			_tmp1_ = TRUE;
		} else {
			gboolean _tmp2_ = FALSE;
			if (str_array_length1 == -1) {
				const gchar* _tmp3_;
				_tmp3_ = str_array[0];
				_tmp2_ = _tmp3_ != NULL;
			} else {
				_tmp2_ = FALSE;
			}
			_tmp1_ = _tmp2_;
		}
		_tmp0_ = _tmp1_;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		gint i = 0;
		gsize len = 0UL;
		gint _tmp16_;
		gint _tmp17_;
		const gchar* res = NULL;
		void* _tmp18_;
		const gchar* _tmp19_ = NULL;
		const gchar* _tmp20_;
		void* ptr = NULL;
		const gchar* _tmp22_;
		void* _tmp23_;
		const gchar* _tmp33_;
		len = (gsize) 1;
		{
			gboolean _tmp4_ = FALSE;
			i = 0;
			_tmp4_ = TRUE;
			while (TRUE) {
				gboolean _tmp6_ = FALSE;
				gboolean _tmp7_ = FALSE;
				gint _tmp10_ = 0;
				const gchar* _tmp11_;
				if (!_tmp4_) {
					gint _tmp5_;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp4_ = FALSE;
				if (str_array_length1 != -1) {
					_tmp7_ = i < str_array_length1;
				} else {
					_tmp7_ = FALSE;
				}
				if (_tmp7_) {
					_tmp6_ = TRUE;
				} else {
					gboolean _tmp8_ = FALSE;
					if (str_array_length1 == -1) {
						const gchar* _tmp9_;
						_tmp9_ = str_array[i];
						_tmp8_ = _tmp9_ != NULL;
					} else {
						_tmp8_ = FALSE;
					}
					_tmp6_ = _tmp8_;
				}
				if (!_tmp6_) {
					break;
				}
				_tmp11_ = str_array[i];
				if (_tmp11_ != NULL) {
					const gchar* _tmp12_;
					gint _tmp13_;
					gint _tmp14_;
					_tmp12_ = str_array[i];
					_tmp13_ = strlen ((const gchar*) _tmp12_);
					_tmp14_ = _tmp13_;
					_tmp10_ = _tmp14_;
				} else {
					_tmp10_ = 0;
				}
				len += (gsize) _tmp10_;
			}
		}
		if (i == 0) {
			gchar* _tmp15_;
			_tmp15_ = g_strdup ("");
			result = _tmp15_;
			return result;
		}
		str_array_length1 = i;
		_tmp16_ = strlen ((const gchar*) separator);
		_tmp17_ = _tmp16_;
		len += (gsize) (_tmp17_ * (i - 1));
		_tmp18_ = g_malloc (len);
		res = _tmp18_;
		_tmp20_ = str_array[0];
		if (_tmp20_ != NULL) {
			const gchar* _tmp21_;
			_tmp21_ = str_array[0];
			_tmp19_ = (const gchar*) _tmp21_;
		} else {
			_tmp19_ = "";
		}
		_tmp22_ = res;
		_tmp23_ = g_stpcpy ((void*) _tmp22_, _tmp19_);
		ptr = _tmp23_;
		{
			gboolean _tmp24_ = FALSE;
			i = 1;
			_tmp24_ = TRUE;
			while (TRUE) {
				void* _tmp26_;
				void* _tmp27_;
				const gchar* _tmp28_ = NULL;
				const gchar* _tmp29_;
				void* _tmp31_;
				void* _tmp32_;
				if (!_tmp24_) {
					gint _tmp25_;
					_tmp25_ = i;
					i = _tmp25_ + 1;
				}
				_tmp24_ = FALSE;
				if (!(i < str_array_length1)) {
					break;
				}
				_tmp26_ = ptr;
				_tmp27_ = g_stpcpy (_tmp26_, (const gchar*) separator);
				ptr = _tmp27_;
				_tmp29_ = str_array[i];
				if (_tmp29_ != NULL) {
					const gchar* _tmp30_;
					_tmp30_ = str_array[i];
					_tmp28_ = (const gchar*) _tmp30_;
				} else {
					_tmp28_ = "";
				}
				_tmp31_ = ptr;
				_tmp32_ = g_stpcpy (_tmp31_, _tmp28_);
				ptr = _tmp32_;
			}
		}
		_tmp33_ = res;
		res = NULL;
		result = (gchar*) _tmp33_;
		return result;
	} else {
		gchar* _tmp34_;
		_tmp34_ = g_strdup ("");
		result = _tmp34_;
		return result;
	}
}

gchar*
ft_gap_flags_to_string (FtGapFlags self)
{
	gchar** strings_array = NULL;
	gchar** _tmp0_;
	gint strings_array_length1;
	gint _strings_array_size_;
	gchar* _tmp3_ = NULL;
	gchar** _tmp4_;
	gint _tmp4__length1;
	gchar* _tmp8_;
	gchar* result;
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	strings_array = _tmp0_;
	strings_array_length1 = 0;
	_strings_array_size_ = strings_array_length1;
	if ((self & FT_GAP_FLAGS_INTERRUPTION) > 0) {
		gchar* _tmp1_;
		_tmp1_ = g_strdup ("interruption");
		_vala_array_add17 (&strings_array, &strings_array_length1, &_strings_array_size_, _tmp1_);
	}
	if ((self & FT_GAP_FLAGS_SLEEP) > 0) {
		gchar* _tmp2_;
		_tmp2_ = g_strdup ("sleep");
		_vala_array_add18 (&strings_array, &strings_array_length1, &_strings_array_size_, _tmp2_);
	}
	_tmp4_ = strings_array;
	_tmp4__length1 = strings_array_length1;
	if (_tmp4__length1 > 0) {
		gchar** _tmp5_;
		gint _tmp5__length1;
		gchar* _tmp6_;
		_tmp5_ = strings_array;
		_tmp5__length1 = strings_array_length1;
		_tmp6_ = _vala_g_strjoinv (" | ", _tmp5_, (gint) _tmp5__length1);
		_g_free0 (_tmp3_);
		_tmp3_ = _tmp6_;
	} else {
		gchar* _tmp7_;
		_tmp7_ = g_strdup ("default");
		_g_free0 (_tmp3_);
		_tmp3_ = _tmp7_;
	}
	_tmp8_ = _tmp3_;
	_tmp3_ = NULL;
	result = _tmp8_;
	_g_free0 (_tmp3_);
	strings_array = (_vala_array_free (strings_array, strings_array_length1, (GDestroyNotify) g_free), NULL);
	return result;
}

static GType
ft_gap_flags_get_type_once (void)
{
	static const GFlagsValue values[] = {{FT_GAP_FLAGS_DEFAULT, "FT_GAP_FLAGS_DEFAULT", "default"}, {FT_GAP_FLAGS_INTERRUPTION, "FT_GAP_FLAGS_INTERRUPTION", "interruption"}, {FT_GAP_FLAGS_SLEEP, "FT_GAP_FLAGS_SLEEP", "sleep"}, {0, NULL, NULL}};
	GType ft_gap_flags_type_id;
	ft_gap_flags_type_id = g_flags_register_static ("FtGapFlags", values);
	return ft_gap_flags_type_id;
}

GType
ft_gap_flags_get_type (void)
{
	static volatile gsize ft_gap_flags_type_id__once = 0;
	if (g_once_init_enter (&ft_gap_flags_type_id__once)) {
		GType ft_gap_flags_type_id;
		ft_gap_flags_type_id = ft_gap_flags_get_type_once ();
		g_once_init_leave (&ft_gap_flags_type_id__once, ft_gap_flags_type_id);
	}
	return ft_gap_flags_type_id__once;
}

static inline gpointer
ft_gap_get_instance_private (FtGap* self)
{
	return G_STRUCT_MEMBER_P (self, FtGap_private_offset);
}

FtGap*
ft_gap_construct (GType object_type,
                  FtGapFlags flags)
{
	FtGap * self = NULL;
	self = (FtGap*) g_object_new (object_type, "flags", flags, NULL);
	return self;
}

FtGap*
ft_gap_new (FtGapFlags flags)
{
	return ft_gap_construct (FT_TYPE_GAP, flags);
}

FtGap*
ft_gap_construct_with_start_time (GType object_type,
                                  gint64 start_time,
                                  FtGapFlags flags)
{
	FtGap * self = NULL;
	self = (FtGap*) g_object_new (object_type, "flags", flags, NULL);
	ft_schedulable_set_time_range ((FtSchedulable*) self, start_time, self->priv->_end_time);
	return self;
}

FtGap*
ft_gap_new_with_start_time (gint64 start_time,
                            FtGapFlags flags)
{
	return ft_gap_construct_with_start_time (FT_TYPE_GAP, start_time, flags);
}

inline gboolean
ft_gap_has_flag (FtGap* self,
                 FtGapFlags flag)
{
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	result = (self->priv->_flags & flag) == flag;
	return result;
}

inline void
ft_gap_set_flag (FtGap* self,
                 FtGapFlags flag)
{
	FtGapFlags _tmp0_;
	FtGapFlags _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = ft_gap_get_flags (self);
	_tmp1_ = _tmp0_;
	ft_gap_set_flags (self, _tmp1_ | flag);
}

inline void
ft_gap_unset_flag (FtGap* self,
                   FtGapFlags flag)
{
	g_return_if_fail (self != NULL);
	ft_gap_set_flags (self, self->priv->_flags & (~flag));
}

static void
ft_gap_emit_changed (FtGap* self)
{
	gulong _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->version;
	self->version = _tmp0_ + 1;
	g_signal_emit (self, ft_gap_signals[FT_GAP_CHANGED_SIGNAL], 0);
}

static void
ft_gap_real_set_time_range (FtSchedulable* base,
                            gint64 start_time,
                            gint64 end_time)
{
	FtGap * self;
	gint64 old_start_time = 0LL;
	gint64 old_end_time = 0LL;
	gint64 old_duration = 0LL;
	gboolean changed = FALSE;
	self = (FtGap*) base;
	old_start_time = self->priv->_start_time;
	old_end_time = self->priv->_end_time;
	old_duration = self->priv->_end_time - self->priv->_start_time;
	changed = FALSE;
	self->priv->_start_time = start_time;
	self->priv->_end_time = end_time;
	if (self->priv->_start_time != old_start_time) {
		g_object_notify ((GObject*) self, "start-time");
		changed = TRUE;
	}
	if (self->priv->_end_time != old_end_time) {
		g_object_notify ((GObject*) self, "end-time");
		changed = TRUE;
	}
	if ((self->priv->_end_time - self->priv->_start_time) != old_duration) {
		g_object_notify ((GObject*) self, "duration");
	}
	if (changed) {
		ft_gap_emit_changed (self);
	}
}

static void
ft_gap_real_move_by (FtSchedulable* base,
                     gint64 offset)
{
	FtGap * self;
	gint64 _tmp0_ = 0LL;
	gint64 start_time = 0LL;
	gint64 _tmp1_ = 0LL;
	gint64 end_time = 0LL;
	self = (FtGap*) base;
	if (ft_timestamp_is_defined (self->priv->_start_time)) {
		_tmp0_ = ft_timestamp_add_interval (self->priv->_start_time, offset);
	} else {
		_tmp0_ = FT_TIMESTAMP_UNDEFINED;
	}
	start_time = _tmp0_;
	if (ft_timestamp_is_defined (self->priv->_end_time)) {
		_tmp1_ = ft_timestamp_add_interval (self->priv->_end_time, offset);
	} else {
		_tmp1_ = FT_TIMESTAMP_UNDEFINED;
	}
	end_time = _tmp1_;
	ft_schedulable_set_time_range ((FtSchedulable*) self, start_time, end_time);
}

static void
ft_gap_real_move_to (FtSchedulable* base,
                     gint64 start_time)
{
	FtGap * self;
	gboolean _tmp0_ = FALSE;
	self = (FtGap*) base;
	if (ft_timestamp_is_undefined (self->priv->_start_time)) {
		_tmp0_ = ft_timestamp_is_undefined (self->priv->_end_time);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		ft_schedulable_set_time_range ((FtSchedulable*) self, start_time, self->priv->_end_time);
		return;
	}
	if (ft_timestamp_is_undefined (self->priv->_start_time)) {
		g_warning ("gap.vala:244: Unable to move gap. Gap start-time is undefined.");
		return;
	}
	ft_schedulable_move_by ((FtSchedulable*) self, ft_timestamp_subtract (start_time, self->priv->_start_time));
}

gboolean
ft_gap_should_create_entry (FtGap* self)
{
	gint64 _tmp0_;
	gint64 _tmp1_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = ft_schedulable_get_start_time ((FtSchedulable*) self);
	_tmp1_ = _tmp0_;
	result = ft_timestamp_is_defined (_tmp1_);
	return result;
}

gboolean
ft_gap_should_update_entry (FtGap* self)
{
	gboolean _tmp0_ = FALSE;
	FtGapEntry* _tmp1_;
	FtGapEntry* _tmp5_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp1_ = self->entry;
	if (_tmp1_ == NULL) {
		_tmp0_ = TRUE;
	} else {
		FtGapEntry* _tmp2_;
		gint64 _tmp3_;
		gint64 _tmp4_;
		_tmp2_ = self->entry;
		_tmp3_ = ft_gap_entry_get_id (_tmp2_);
		_tmp4_ = _tmp3_;
		_tmp0_ = _tmp4_ == ((gint64) 0);
	}
	if (_tmp0_) {
		result = TRUE;
		return result;
	}
	_tmp5_ = self->entry;
	result = _tmp5_->version != self->version;
	return result;
}

FtGapEntry*
ft_gap_create_or_update_entry (FtGap* self)
{
	FtTimeBlock* _tmp0_;
	FtTimeBlockEntry* _tmp1_;
	FtGapEntry* _tmp2_;
	FtGapEntry* _tmp9_;
	FtGapEntry* _tmp10_;
	FtGapEntry* _tmp11_;
	gchar* _tmp12_;
	gchar* _tmp13_;
	FtGapEntry* _tmp14_;
	FtGapEntry* _tmp15_;
	FtGapEntry* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_time_block;
	_tmp1_ = _tmp0_->entry;
	_vala_return_val_if_fail (_tmp1_ != NULL, "this.time_block.entry != null", NULL);
	_tmp2_ = self->entry;
	if (_tmp2_ == NULL) {
		FtGapEntry* _tmp3_;
		FtGapEntry* _tmp4_;
		GomRepository* _tmp5_;
		FtTimeBlock* _tmp6_;
		FtTimeBlockEntry* _tmp7_;
		FtGapEntry* _tmp8_;
		_tmp3_ = ft_gap_entry_new ();
		_g_object_unref0 (self->entry);
		self->entry = _tmp3_;
		_tmp4_ = self->entry;
		_tmp5_ = ft_database_get_repository ();
		g_object_set ((GomResource*) _tmp4_, "repository", _tmp5_, NULL);
		_tmp6_ = self->priv->_time_block;
		_tmp7_ = _tmp6_->entry;
		_tmp8_ = self->entry;
		g_object_bind_property_with_closures ((GObject*) _tmp7_, "id", (GObject*) _tmp8_, "time-block-id", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	}
	_tmp9_ = self->entry;
	ft_gap_entry_set_start_time (_tmp9_, self->priv->_start_time);
	_tmp10_ = self->entry;
	ft_gap_entry_set_end_time (_tmp10_, self->priv->_end_time);
	_tmp11_ = self->entry;
	_tmp12_ = ft_gap_flags_to_string (self->priv->_flags);
	_tmp13_ = _tmp12_;
	ft_gap_entry_set_flags (_tmp11_, _tmp13_);
	_g_free0 (_tmp13_);
	_tmp14_ = self->entry;
	_tmp14_->version = self->version;
	_tmp15_ = self->entry;
	result = _tmp15_;
	return result;
}

void
ft_gap_unset_entry (FtGap* self)
{
	g_return_if_fail (self != NULL);
	_g_object_unref0 (self->entry);
	self->entry = NULL;
}

static void
ft_gap_real_dispose (GObject* base)
{
	FtGap * self;
	self = (FtGap*) base;
	ft_gap_set_time_block (self, NULL);
	_g_object_unref0 (self->entry);
	self->entry = NULL;
	G_OBJECT_CLASS (ft_gap_parent_class)->dispose ((GObject*) G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_INITIALLY_UNOWNED, GInitiallyUnowned));
}

static gint64
ft_gap_real_get_start_time (FtSchedulable* base)
{
	gint64 result;
	FtGap* self;
	self = (FtGap*) base;
	result = self->priv->_start_time;
	return result;
}

static void
ft_gap_real_set_start_time (FtSchedulable* base,
                            gint64 value)
{
	FtGap* self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	self = (FtGap*) base;
	if (self->priv->_start_time == value) {
		return;
	}
	if (ft_timestamp_is_undefined (value)) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = ft_timestamp_is_undefined (self->priv->_end_time);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = value <= self->priv->_end_time;
	}
	if (_tmp0_) {
		ft_schedulable_set_time_range ((FtSchedulable*) self, value, self->priv->_end_time);
	} else {
		ft_schedulable_set_time_range ((FtSchedulable*) self, value, value);
	}
}

static gint64
ft_gap_real_get_end_time (FtSchedulable* base)
{
	gint64 result;
	FtGap* self;
	self = (FtGap*) base;
	result = self->priv->_end_time;
	return result;
}

static void
ft_gap_real_set_end_time (FtSchedulable* base,
                          gint64 value)
{
	FtGap* self;
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	self = (FtGap*) base;
	if (self->priv->_end_time == value) {
		return;
	}
	if (ft_timestamp_is_undefined (value)) {
		_tmp1_ = TRUE;
	} else {
		_tmp1_ = ft_timestamp_is_undefined (self->priv->_start_time);
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		_tmp0_ = value >= self->priv->_start_time;
	}
	if (_tmp0_) {
		ft_schedulable_set_time_range ((FtSchedulable*) self, self->priv->_start_time, value);
	} else {
		ft_schedulable_set_time_range ((FtSchedulable*) self, value, value);
	}
}

static gint64
ft_gap_real_get_duration (FtSchedulable* base)
{
	gint64 result;
	FtGap* self;
	self = (FtGap*) base;
	result = ft_timestamp_subtract (self->priv->_end_time, self->priv->_start_time);
	return result;
}

static void
ft_gap_real_set_duration (FtSchedulable* base,
                          gint64 value)
{
	FtGap* self;
	self = (FtGap*) base;
	if (ft_timestamp_is_defined (self->priv->_start_time)) {
		ft_schedulable_set_time_range ((FtSchedulable*) self, self->priv->_start_time, ft_timestamp_add_interval (self->priv->_start_time, value));
	} else {
		g_warning ("gap.vala:127: Can't change time-block duration without a defined start" \
"-time.");
	}
}

FtGapFlags
ft_gap_get_flags (FtGap* self)
{
	FtGapFlags result;
	g_return_val_if_fail (self != NULL, 0U);
	result = self->priv->_flags;
	return result;
}

void
ft_gap_set_flags (FtGap* self,
                  FtGapFlags value)
{
	g_return_if_fail (self != NULL);
	if (self->priv->_flags != value) {
		gulong _tmp0_;
		self->priv->_flags = value;
		_tmp0_ = self->version;
		self->version = _tmp0_ + 1;
	}
	g_object_notify_by_pspec ((GObject *) self, ft_gap_properties[FT_GAP_FLAGS_PROPERTY]);
}

FtTimeBlock*
ft_gap_get_time_block (FtGap* self)
{
	FtTimeBlock* result;
	FtTimeBlock* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_time_block;
	result = _tmp0_;
	return result;
}

void
ft_gap_set_time_block (FtGap* self,
                       FtTimeBlock* value)
{
	FtTimeBlock* old_value;
	g_return_if_fail (self != NULL);
	old_value = ft_gap_get_time_block (self);
	if (old_value != value) {
		self->priv->_time_block = value;
		g_object_notify_by_pspec ((GObject *) self, ft_gap_properties[FT_GAP_TIME_BLOCK_PROPERTY]);
	}
}

static void
ft_gap_class_init (FtGapClass * klass,
                   gpointer klass_data)
{
	ft_gap_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &FtGap_private_offset);
	((GObjectClass *) klass)->dispose = (void (*) (GObject*)) ft_gap_real_dispose;
	G_OBJECT_CLASS (klass)->get_property = _vala_ft_gap_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_ft_gap_set_property;
	G_OBJECT_CLASS (klass)->finalize = ft_gap_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_GAP_START_TIME_PROPERTY, ft_gap_properties[FT_GAP_START_TIME_PROPERTY] = g_param_spec_int64 ("start-time", "start-time", "start-time", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_GAP_END_TIME_PROPERTY, ft_gap_properties[FT_GAP_END_TIME_PROPERTY] = g_param_spec_int64 ("end-time", "end-time", "end-time", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	/**
	         * `duration` of a time block, including gaps
	         */
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_GAP_DURATION_PROPERTY, ft_gap_properties[FT_GAP_DURATION_PROPERTY] = g_param_spec_int64 ("duration", "duration", "duration", G_MININT64, G_MAXINT64, 0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_EXPLICIT_NOTIFY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_GAP_FLAGS_PROPERTY, ft_gap_properties[FT_GAP_FLAGS_PROPERTY] = g_param_spec_flags ("flags", "flags", "flags", FT_TYPE_GAP_FLAGS, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), FT_GAP_TIME_BLOCK_PROPERTY, ft_gap_properties[FT_GAP_TIME_BLOCK_PROPERTY] = g_param_spec_object ("time-block", "time-block", "time-block", FT_TYPE_TIME_BLOCK, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	ft_gap_signals[FT_GAP_CHANGED_SIGNAL] = g_signal_new ("changed", FT_TYPE_GAP, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}

static void
ft_gap_ft_schedulable_interface_init (FtSchedulableIface * iface,
                                      gpointer iface_data)
{
	ft_gap_ft_schedulable_parent_iface = g_type_interface_peek_parent (iface);
	iface->set_time_range = (void (*) (FtSchedulable*, gint64, gint64)) ft_gap_real_set_time_range;
	iface->move_by = (void (*) (FtSchedulable*, gint64)) ft_gap_real_move_by;
	iface->move_to = (void (*) (FtSchedulable*, gint64)) ft_gap_real_move_to;
	iface->get_start_time = ft_gap_real_get_start_time;
	iface->set_start_time = ft_gap_real_set_start_time;
	iface->get_end_time = ft_gap_real_get_end_time;
	iface->set_end_time = ft_gap_real_set_end_time;
	iface->get_duration = ft_gap_real_get_duration;
	iface->set_duration = ft_gap_real_set_duration;
}

static void
ft_gap_instance_init (FtGap * self,
                      gpointer klass)
{
	self->priv = ft_gap_get_instance_private (self);
	self->version = (gulong) 0;
	self->entry = NULL;
	self->priv->_start_time = FT_TIMESTAMP_UNDEFINED;
	self->priv->_end_time = FT_TIMESTAMP_UNDEFINED;
	self->priv->_flags = FT_GAP_FLAGS_DEFAULT;
}

static void
ft_gap_finalize (GObject * obj)
{
	FtGap * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, FT_TYPE_GAP, FtGap);
	_g_object_unref0 (self->entry);
	G_OBJECT_CLASS (ft_gap_parent_class)->finalize (obj);
}

static GType
ft_gap_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (FtGapClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ft_gap_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (FtGap), 0, (GInstanceInitFunc) ft_gap_instance_init, NULL };
	static const GInterfaceInfo ft_schedulable_info = { (GInterfaceInitFunc) ft_gap_ft_schedulable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType ft_gap_type_id;
	ft_gap_type_id = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, "FtGap", &g_define_type_info, 0);
	g_type_add_interface_static (ft_gap_type_id, FT_TYPE_SCHEDULABLE, &ft_schedulable_info);
	FtGap_private_offset = g_type_add_instance_private (ft_gap_type_id, sizeof (FtGapPrivate));
	return ft_gap_type_id;
}

GType
ft_gap_get_type (void)
{
	static volatile gsize ft_gap_type_id__once = 0;
	if (g_once_init_enter (&ft_gap_type_id__once)) {
		GType ft_gap_type_id;
		ft_gap_type_id = ft_gap_get_type_once ();
		g_once_init_leave (&ft_gap_type_id__once, ft_gap_type_id);
	}
	return ft_gap_type_id__once;
}

static void
_vala_ft_gap_get_property (GObject * object,
                           guint property_id,
                           GValue * value,
                           GParamSpec * pspec)
{
	FtGap * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_GAP, FtGap);
	switch (property_id) {
		case FT_GAP_START_TIME_PROPERTY:
		g_value_set_int64 (value, ft_schedulable_get_start_time ((FtSchedulable*) self));
		break;
		case FT_GAP_END_TIME_PROPERTY:
		g_value_set_int64 (value, ft_schedulable_get_end_time ((FtSchedulable*) self));
		break;
		case FT_GAP_DURATION_PROPERTY:
		g_value_set_int64 (value, ft_schedulable_get_duration ((FtSchedulable*) self));
		break;
		case FT_GAP_FLAGS_PROPERTY:
		g_value_set_flags (value, ft_gap_get_flags (self));
		break;
		case FT_GAP_TIME_BLOCK_PROPERTY:
		g_value_set_object (value, ft_gap_get_time_block (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_ft_gap_set_property (GObject * object,
                           guint property_id,
                           const GValue * value,
                           GParamSpec * pspec)
{
	FtGap * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, FT_TYPE_GAP, FtGap);
	switch (property_id) {
		case FT_GAP_START_TIME_PROPERTY:
		ft_schedulable_set_start_time ((FtSchedulable*) self, g_value_get_int64 (value));
		break;
		case FT_GAP_END_TIME_PROPERTY:
		ft_schedulable_set_end_time ((FtSchedulable*) self, g_value_get_int64 (value));
		break;
		case FT_GAP_DURATION_PROPERTY:
		ft_schedulable_set_duration ((FtSchedulable*) self, g_value_get_int64 (value));
		break;
		case FT_GAP_FLAGS_PROPERTY:
		ft_gap_set_flags (self, g_value_get_flags (value));
		break;
		case FT_GAP_TIME_BLOCK_PROPERTY:
		ft_gap_set_time_block (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

