/* memory-empty-buffer.c generated by valac 0.56.3, the Vala compiler
 * generated from memory-empty-buffer.vala, do not modify */

/* Copyright 2016 Software Freedom Conservancy Inc.
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

#include "geary-engine.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>

enum  {
	GEARY_MEMORY_EMPTY_BUFFER_0_PROPERTY,
	GEARY_MEMORY_EMPTY_BUFFER_SIZE_PROPERTY,
	GEARY_MEMORY_EMPTY_BUFFER_ALLOCATED_SIZE_PROPERTY,
	GEARY_MEMORY_EMPTY_BUFFER_NUM_PROPERTIES
};
static GParamSpec* geary_memory_empty_buffer_properties[GEARY_MEMORY_EMPTY_BUFFER_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_byte_array_unref0(var) ((var == NULL) ? NULL : (var = (g_byte_array_unref (var), NULL)))

struct _GearyMemoryEmptyBufferPrivate {
	GBytes* bytes;
	GByteArray* byte_array;
};

static gint GearyMemoryEmptyBuffer_private_offset;
static gpointer geary_memory_empty_buffer_parent_class = NULL;
static GearyMemoryEmptyBuffer* geary_memory_empty_buffer__instance;
static GearyMemoryEmptyBuffer* geary_memory_empty_buffer__instance = NULL;
static GearyMemoryUnownedStringBufferIface * geary_memory_empty_buffer_geary_memory_unowned_string_buffer_parent_iface = NULL;
static GearyMemoryUnownedBytesBufferIface * geary_memory_empty_buffer_geary_memory_unowned_bytes_buffer_parent_iface = NULL;
static GearyMemoryUnownedByteArrayBufferIface * geary_memory_empty_buffer_geary_memory_unowned_byte_array_buffer_parent_iface = NULL;

static GearyMemoryEmptyBuffer* geary_memory_empty_buffer_new (void);
static GearyMemoryEmptyBuffer* geary_memory_empty_buffer_construct (GType object_type);
static GBytes* geary_memory_empty_buffer_real_get_bytes (GearyMemoryBuffer* base);
static guint8* geary_memory_empty_buffer_real_to_unowned_uint8_array (GearyMemoryUnownedBytesBuffer* base,
                                                               gint* result_length1);
static const gchar* geary_memory_empty_buffer_real_to_unowned_string (GearyMemoryUnownedStringBuffer* base);
static GByteArray* geary_memory_empty_buffer_real_to_unowned_byte_array (GearyMemoryUnownedByteArrayBuffer* base);
static void geary_memory_empty_buffer_finalize (GObject * obj);
static GType geary_memory_empty_buffer_get_type_once (void);
static void _vala_geary_memory_empty_buffer_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec);

static inline gpointer
geary_memory_empty_buffer_get_instance_private (GearyMemoryEmptyBuffer* self)
{
	return G_STRUCT_MEMBER_P (self, GearyMemoryEmptyBuffer_private_offset);
}

GearyMemoryEmptyBuffer*
geary_memory_empty_buffer_get_instance (void)
{
	GearyMemoryEmptyBuffer* result;
	GearyMemoryEmptyBuffer* _tmp0_ = NULL;
	GearyMemoryEmptyBuffer* _tmp1_;
	_tmp1_ = geary_memory_empty_buffer__instance;
	if (_tmp1_ != NULL) {
		GearyMemoryEmptyBuffer* _tmp2_;
		_tmp2_ = geary_memory_empty_buffer__instance;
		_tmp0_ = _tmp2_;
	} else {
		GearyMemoryEmptyBuffer* _tmp3_;
		GearyMemoryEmptyBuffer* _tmp4_;
		_tmp3_ = geary_memory_empty_buffer_new ();
		_g_object_unref0 (geary_memory_empty_buffer__instance);
		geary_memory_empty_buffer__instance = _tmp3_;
		_tmp4_ = geary_memory_empty_buffer__instance;
		_tmp0_ = _tmp4_;
	}
	result = _tmp0_;
	return result;
}

static gsize
geary_memory_empty_buffer_real_get_size (GearyMemoryBuffer* base)
{
	gsize result;
	GearyMemoryEmptyBuffer* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_MEMORY_TYPE_EMPTY_BUFFER, GearyMemoryEmptyBuffer);
	result = (gsize) 0;
	return result;
}

static gsize
geary_memory_empty_buffer_real_get_allocated_size (GearyMemoryBuffer* base)
{
	gsize result;
	GearyMemoryEmptyBuffer* self;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_MEMORY_TYPE_EMPTY_BUFFER, GearyMemoryEmptyBuffer);
	result = (gsize) 0;
	return result;
}

static GearyMemoryEmptyBuffer*
geary_memory_empty_buffer_construct (GType object_type)
{
	GearyMemoryEmptyBuffer * self = NULL;
	self = (GearyMemoryEmptyBuffer*) geary_memory_buffer_construct (object_type);
	return self;
}

static GearyMemoryEmptyBuffer*
geary_memory_empty_buffer_new (void)
{
	return geary_memory_empty_buffer_construct (GEARY_MEMORY_TYPE_EMPTY_BUFFER);
}

/**
     * {@inheritDoc}
     */
static gpointer
_g_bytes_ref0 (gpointer self)
{
	return self ? g_bytes_ref (self) : NULL;
}

static GBytes*
geary_memory_empty_buffer_real_get_bytes (GearyMemoryBuffer* base)
{
	GearyMemoryEmptyBuffer * self;
	GBytes* _tmp0_;
	GBytes* _tmp1_;
	GBytes* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_MEMORY_TYPE_EMPTY_BUFFER, GearyMemoryEmptyBuffer);
	_tmp0_ = self->priv->bytes;
	_tmp1_ = _g_bytes_ref0 (_tmp0_);
	result = _tmp1_;
	return result;
}

/**
     * {@inheritDoc}
     */
static guint8*
geary_memory_empty_buffer_real_to_unowned_uint8_array (GearyMemoryUnownedBytesBuffer* base,
                                                       gint* result_length1)
{
	GearyMemoryEmptyBuffer * self;
	GBytes* _tmp0_;
	gsize _tmp1_ = 0;
	guint8* _tmp2_;
	guint8* _tmp3_;
	gint _tmp3__length1;
	guint8* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_MEMORY_TYPE_EMPTY_BUFFER, GearyMemoryEmptyBuffer);
	_tmp0_ = self->priv->bytes;
	_tmp2_ = g_bytes_get_data (_tmp0_, &_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp3__length1 = _tmp1_;
	if (result_length1) {
		*result_length1 = _tmp3__length1;
	}
	result = _tmp3_;
	return result;
}

/**
     * {@inheritDoc}
     */
static const gchar*
geary_memory_empty_buffer_real_to_unowned_string (GearyMemoryUnownedStringBuffer* base)
{
	GearyMemoryEmptyBuffer * self;
	const gchar* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_MEMORY_TYPE_EMPTY_BUFFER, GearyMemoryEmptyBuffer);
	result = "";
	return result;
}

/**
     * {@inheritDoc}
     */
static GByteArray*
geary_memory_empty_buffer_real_to_unowned_byte_array (GearyMemoryUnownedByteArrayBuffer* base)
{
	GearyMemoryEmptyBuffer * self;
	GByteArray* _tmp0_;
	GByteArray* result;
	self = G_TYPE_CHECK_INSTANCE_CAST (base, GEARY_MEMORY_TYPE_EMPTY_BUFFER, GearyMemoryEmptyBuffer);
	_tmp0_ = self->priv->byte_array;
	result = _tmp0_;
	return result;
}

static void
geary_memory_empty_buffer_class_init (GearyMemoryEmptyBufferClass * klass,
                                      gpointer klass_data)
{
	geary_memory_empty_buffer_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GearyMemoryEmptyBuffer_private_offset);
	((GearyMemoryBufferClass *) klass)->get_bytes = (GBytes* (*) (GearyMemoryBuffer*)) geary_memory_empty_buffer_real_get_bytes;
	GEARY_MEMORY_BUFFER_CLASS (klass)->get_size = geary_memory_empty_buffer_real_get_size;
	GEARY_MEMORY_BUFFER_CLASS (klass)->get_allocated_size = geary_memory_empty_buffer_real_get_allocated_size;
	G_OBJECT_CLASS (klass)->get_property = _vala_geary_memory_empty_buffer_get_property;
	G_OBJECT_CLASS (klass)->finalize = geary_memory_empty_buffer_finalize;
	/**
	     * {@inheritDoc}
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_MEMORY_EMPTY_BUFFER_SIZE_PROPERTY, geary_memory_empty_buffer_properties[GEARY_MEMORY_EMPTY_BUFFER_SIZE_PROPERTY] = g_param_spec_ulong ("size", "size", "size", 0, G_MAXULONG, 0UL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	/**
	     * {@inheritDoc}
	     */
	g_object_class_install_property (G_OBJECT_CLASS (klass), GEARY_MEMORY_EMPTY_BUFFER_ALLOCATED_SIZE_PROPERTY, geary_memory_empty_buffer_properties[GEARY_MEMORY_EMPTY_BUFFER_ALLOCATED_SIZE_PROPERTY] = g_param_spec_ulong ("allocated-size", "allocated-size", "allocated-size", 0, G_MAXULONG, 0UL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
geary_memory_empty_buffer_geary_memory_unowned_string_buffer_interface_init (GearyMemoryUnownedStringBufferIface * iface,
                                                                             gpointer iface_data)
{
	geary_memory_empty_buffer_geary_memory_unowned_string_buffer_parent_iface = g_type_interface_peek_parent (iface);
	iface->to_unowned_string = (const gchar* (*) (GearyMemoryUnownedStringBuffer*)) geary_memory_empty_buffer_real_to_unowned_string;
}

static void
geary_memory_empty_buffer_geary_memory_unowned_bytes_buffer_interface_init (GearyMemoryUnownedBytesBufferIface * iface,
                                                                            gpointer iface_data)
{
	geary_memory_empty_buffer_geary_memory_unowned_bytes_buffer_parent_iface = g_type_interface_peek_parent (iface);
	iface->to_unowned_uint8_array = (guint8* (*) (GearyMemoryUnownedBytesBuffer*, gint*)) geary_memory_empty_buffer_real_to_unowned_uint8_array;
}

static void
geary_memory_empty_buffer_geary_memory_unowned_byte_array_buffer_interface_init (GearyMemoryUnownedByteArrayBufferIface * iface,
                                                                                 gpointer iface_data)
{
	geary_memory_empty_buffer_geary_memory_unowned_byte_array_buffer_parent_iface = g_type_interface_peek_parent (iface);
	iface->to_unowned_byte_array = (GByteArray* (*) (GearyMemoryUnownedByteArrayBuffer*)) geary_memory_empty_buffer_real_to_unowned_byte_array;
}

static void
geary_memory_empty_buffer_instance_init (GearyMemoryEmptyBuffer * self,
                                         gpointer klass)
{
	guint8* _tmp0_;
	guint8* _tmp1_;
	gint _tmp1__length1;
	GBytes* _tmp2_;
	GByteArray* _tmp3_;
	self->priv = geary_memory_empty_buffer_get_instance_private (self);
	_tmp0_ = g_new0 (guint8, 0);
	_tmp1_ = _tmp0_;
	_tmp1__length1 = 0;
	_tmp2_ = g_bytes_new (_tmp1_, 0);
	self->priv->bytes = _tmp2_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	_tmp3_ = g_byte_array_new ();
	self->priv->byte_array = _tmp3_;
}

static void
geary_memory_empty_buffer_finalize (GObject * obj)
{
	GearyMemoryEmptyBuffer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GEARY_MEMORY_TYPE_EMPTY_BUFFER, GearyMemoryEmptyBuffer);
	_g_bytes_unref0 (self->priv->bytes);
	_g_byte_array_unref0 (self->priv->byte_array);
	G_OBJECT_CLASS (geary_memory_empty_buffer_parent_class)->finalize (obj);
}

/**
 * An EmptyBuffer fulfills the interface of {@link Buffer} for a zero-length block.
 *
 * Because all EmptyBuffers are the same and immutable, only a single may be used: {@link instance}.
 */
 G_GNUC_NO_INLINE static GType
geary_memory_empty_buffer_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GearyMemoryEmptyBufferClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) geary_memory_empty_buffer_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GearyMemoryEmptyBuffer), 0, (GInstanceInitFunc) geary_memory_empty_buffer_instance_init, NULL };
	static const GInterfaceInfo geary_memory_unowned_string_buffer_info = { (GInterfaceInitFunc) geary_memory_empty_buffer_geary_memory_unowned_string_buffer_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo geary_memory_unowned_bytes_buffer_info = { (GInterfaceInitFunc) geary_memory_empty_buffer_geary_memory_unowned_bytes_buffer_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	static const GInterfaceInfo geary_memory_unowned_byte_array_buffer_info = { (GInterfaceInitFunc) geary_memory_empty_buffer_geary_memory_unowned_byte_array_buffer_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType geary_memory_empty_buffer_type_id;
	geary_memory_empty_buffer_type_id = g_type_register_static (GEARY_MEMORY_TYPE_BUFFER, "GearyMemoryEmptyBuffer", &g_define_type_info, 0);
	g_type_add_interface_static (geary_memory_empty_buffer_type_id, GEARY_MEMORY_TYPE_UNOWNED_STRING_BUFFER, &geary_memory_unowned_string_buffer_info);
	g_type_add_interface_static (geary_memory_empty_buffer_type_id, GEARY_MEMORY_TYPE_UNOWNED_BYTES_BUFFER, &geary_memory_unowned_bytes_buffer_info);
	g_type_add_interface_static (geary_memory_empty_buffer_type_id, GEARY_MEMORY_TYPE_UNOWNED_BYTE_ARRAY_BUFFER, &geary_memory_unowned_byte_array_buffer_info);
	GearyMemoryEmptyBuffer_private_offset = g_type_add_instance_private (geary_memory_empty_buffer_type_id, sizeof (GearyMemoryEmptyBufferPrivate));
	return geary_memory_empty_buffer_type_id;
}

GType
geary_memory_empty_buffer_get_type (void)
{
	static gsize geary_memory_empty_buffer_type_id__once = 0;
	if (g_once_init_enter (&geary_memory_empty_buffer_type_id__once)) {
		GType geary_memory_empty_buffer_type_id;
		geary_memory_empty_buffer_type_id = geary_memory_empty_buffer_get_type_once ();
		g_once_init_leave (&geary_memory_empty_buffer_type_id__once, geary_memory_empty_buffer_type_id);
	}
	return geary_memory_empty_buffer_type_id__once;
}

static void
_vala_geary_memory_empty_buffer_get_property (GObject * object,
                                              guint property_id,
                                              GValue * value,
                                              GParamSpec * pspec)
{
	GearyMemoryEmptyBuffer * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GEARY_MEMORY_TYPE_EMPTY_BUFFER, GearyMemoryEmptyBuffer);
	switch (property_id) {
		case GEARY_MEMORY_EMPTY_BUFFER_SIZE_PROPERTY:
		g_value_set_ulong (value, geary_memory_buffer_get_size (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_MEMORY_TYPE_BUFFER, GearyMemoryBuffer)));
		break;
		case GEARY_MEMORY_EMPTY_BUFFER_ALLOCATED_SIZE_PROPERTY:
		g_value_set_ulong (value, geary_memory_buffer_get_allocated_size (G_TYPE_CHECK_INSTANCE_CAST (self, GEARY_MEMORY_TYPE_BUFFER, GearyMemoryBuffer)));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

