/* document.c generated by valac 0.30.0.38-a55d, the Vala compiler
 * generated from document.vala, do not modify */

/*
 * This file is part of gnome-code-assistance.
 *
 * Copyright (C) 2013 - Jesse van den Kieboom
 *
 * gnome-code-assistance is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * gnome-code-assistance 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 gnome-code-assistance.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include "backends/vala/libvalashared.h"
#include <gobject/gvaluecollector.h>


#define TYPE_DOCUMENT (document_get_type ())
#define DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DOCUMENT, Document))
#define DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT, DocumentClass))
#define IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DOCUMENT))
#define IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT))
#define DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT, DocumentClass))

typedef struct _Document Document;
typedef struct _DocumentClass DocumentClass;
typedef struct _DocumentPrivate DocumentPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
typedef struct _ParamSpecDocument ParamSpecDocument;

struct _Document {
	GTypeInstance parent_instance;
	volatile int ref_count;
	DocumentPrivate * priv;
};

struct _DocumentClass {
	GTypeClass parent_class;
	void (*finalize) (Document *self);
};

struct _DocumentPrivate {
	guint _id;
	gchar* _path;
	gchar* _data_path;
	SourceLocation _cursor;
	gchar* _client_path;
	Diagnostic* _diagnostics;
	gint _diagnostics_length1;
	gint __diagnostics_size_;
};

struct _ParamSpecDocument {
	GParamSpec parent_instance;
};


static gpointer document_parent_class = NULL;

gpointer document_ref (gpointer instance);
void document_unref (gpointer instance);
GParamSpec* param_spec_document (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void value_set_document (GValue* value, gpointer v_object);
void value_take_document (GValue* value, gpointer v_object);
gpointer value_get_document (const GValue* value);
GType document_get_type (void) G_GNUC_CONST;
#define DOCUMENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_DOCUMENT, DocumentPrivate))
enum  {
	DOCUMENT_DUMMY_PROPERTY
};
static void _vala_Diagnostic_array_free (Diagnostic* array, gint array_length);
Document* document_new (guint id, const gchar* path);
Document* document_construct (GType object_type, guint id, const gchar* path);
void document_set_id (Document* self, guint value);
void document_set_path (Document* self, const gchar* value);
guint document_get_id (Document* self);
const gchar* document_get_path (Document* self);
const gchar* document_get_data_path (Document* self);
void document_set_data_path (Document* self, const gchar* value);
void document_get_cursor (Document* self, SourceLocation* result);
void document_set_cursor (Document* self, SourceLocation* value);
const gchar* document_get_client_path (Document* self);
void document_set_client_path (Document* self, const gchar* value);
Diagnostic* document_get_diagnostics (Document* self, int* result_length1);
void document_set_diagnostics (Document* self, Diagnostic* value, int value_length1);
static Diagnostic* _vala_array_dup2 (Diagnostic* self, int length);
static void document_finalize (Document* obj);


static void _vala_Diagnostic_array_free (Diagnostic* array, gint array_length) {
	if (array != NULL) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			diagnostic_destroy (&array[i]);
		}
	}
	g_free (array);
}


Document* document_construct (GType object_type, guint id, const gchar* path) {
	Document* self = NULL;
	guint _tmp0_ = 0U;
	const gchar* _tmp1_ = NULL;
	g_return_val_if_fail (path != NULL, NULL);
	self = (Document*) g_type_create_instance (object_type);
	_tmp0_ = id;
	document_set_id (self, _tmp0_);
	_tmp1_ = path;
	document_set_path (self, _tmp1_);
	return self;
}


Document* document_new (guint id, const gchar* path) {
	return document_construct (TYPE_DOCUMENT, id, path);
}


guint document_get_id (Document* self) {
	guint result;
	guint _tmp0_ = 0U;
	g_return_val_if_fail (self != NULL, 0U);
	_tmp0_ = self->priv->_id;
	result = _tmp0_;
	return result;
}


void document_set_id (Document* self, guint value) {
	guint _tmp0_ = 0U;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	self->priv->_id = _tmp0_;
}


const gchar* document_get_path (Document* self) {
	const gchar* result;
	const gchar* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_path;
	result = _tmp0_;
	return result;
}


void document_set_path (Document* self, const gchar* value) {
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_path);
	self->priv->_path = _tmp1_;
}


const gchar* document_get_data_path (Document* self) {
	const gchar* result;
	const gchar* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_data_path;
	result = _tmp0_;
	return result;
}


void document_set_data_path (Document* self, const gchar* value) {
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_data_path);
	self->priv->_data_path = _tmp1_;
}


void document_get_cursor (Document* self, SourceLocation* result) {
	SourceLocation _tmp0_ = {0};
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_cursor;
	*result = _tmp0_;
	return;
}


void document_set_cursor (Document* self, SourceLocation* value) {
	SourceLocation _tmp0_ = {0};
	g_return_if_fail (self != NULL);
	_tmp0_ = *value;
	self->priv->_cursor = _tmp0_;
}


const gchar* document_get_client_path (Document* self) {
	const gchar* result;
	const gchar* _tmp0_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_client_path;
	result = _tmp0_;
	return result;
}


void document_set_client_path (Document* self, const gchar* value) {
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_client_path);
	self->priv->_client_path = _tmp1_;
}


Diagnostic* document_get_diagnostics (Document* self, int* result_length1) {
	Diagnostic* result;
	Diagnostic* _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	Diagnostic* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_diagnostics;
	_tmp0__length1 = self->priv->_diagnostics_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}


static Diagnostic* _vala_array_dup2 (Diagnostic* self, int length) {
	Diagnostic* result;
	int i;
	result = g_new0 (Diagnostic, length);
	for (i = 0; i < length; i++) {
		Diagnostic _tmp0_ = {0};
		diagnostic_copy (&self[i], &_tmp0_);
		result[i] = _tmp0_;
	}
	return result;
}


void document_set_diagnostics (Document* self, Diagnostic* value, int value_length1) {
	Diagnostic* _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	Diagnostic* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp0__length1 = value_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup2 (_tmp0_, _tmp0__length1) : ((gpointer) _tmp0_);
	_tmp1__length1 = _tmp0__length1;
	self->priv->_diagnostics = (_vala_Diagnostic_array_free (self->priv->_diagnostics, self->priv->_diagnostics_length1), NULL);
	self->priv->_diagnostics = _tmp1_;
	self->priv->_diagnostics_length1 = _tmp1__length1;
	self->priv->__diagnostics_size_ = self->priv->_diagnostics_length1;
}


static void value_document_init (GValue* value) {
	value->data[0].v_pointer = NULL;
}


static void value_document_free_value (GValue* value) {
	if (value->data[0].v_pointer) {
		document_unref (value->data[0].v_pointer);
	}
}


static void value_document_copy_value (const GValue* src_value, GValue* dest_value) {
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = document_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}


static gpointer value_document_peek_pointer (const GValue* value) {
	return value->data[0].v_pointer;
}


static gchar* value_document_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		Document* object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = document_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* value_document_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	Document** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = document_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* param_spec_document (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	ParamSpecDocument* spec;
	g_return_val_if_fail (g_type_is_a (object_type, TYPE_DOCUMENT), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}


gpointer value_get_document (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DOCUMENT), NULL);
	return value->data[0].v_pointer;
}


void value_set_document (GValue* value, gpointer v_object) {
	Document* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DOCUMENT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_DOCUMENT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		document_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		document_unref (old);
	}
}


void value_take_document (GValue* value, gpointer v_object) {
	Document* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_DOCUMENT));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_DOCUMENT));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		document_unref (old);
	}
}


static void document_class_init (DocumentClass * klass) {
	document_parent_class = g_type_class_peek_parent (klass);
	((DocumentClass *) klass)->finalize = document_finalize;
	g_type_class_add_private (klass, sizeof (DocumentPrivate));
}


static void document_instance_init (Document * self) {
	self->priv = DOCUMENT_GET_PRIVATE (self);
	self->ref_count = 1;
}


static void document_finalize (Document* obj) {
	Document * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_DOCUMENT, Document);
	g_signal_handlers_destroy (self);
	_g_free0 (self->priv->_path);
	_g_free0 (self->priv->_data_path);
	_g_free0 (self->priv->_client_path);
	self->priv->_diagnostics = (_vala_Diagnostic_array_free (self->priv->_diagnostics, self->priv->_diagnostics_length1), NULL);
}


GType document_get_type (void) {
	static volatile gsize document_type_id__volatile = 0;
	if (g_once_init_enter (&document_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { value_document_init, value_document_free_value, value_document_copy_value, value_document_peek_pointer, "p", value_document_collect_value, "p", value_document_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (DocumentClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) document_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Document), 0, (GInstanceInitFunc) document_instance_init, &g_define_type_value_table };
		static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
		GType document_type_id;
		document_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Document", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&document_type_id__volatile, document_type_id);
	}
	return document_type_id__volatile;
}


gpointer document_ref (gpointer instance) {
	Document* self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}


void document_unref (gpointer instance) {
	Document* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		DOCUMENT_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}



