/* sourceitem.c generated by valac 0.12.1.1-323029-dirty, the Vala compiler
 * generated from sourceitem.vala, do not modify */

/* sourceitem.vala
 *
 * Copyright (C) 2010  Andrea Del Signore
 *
 * This library 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 library 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, see <http://www.gnu.org/licenses/>.
 *
 * Author:
 * 	Andrea Del Signore <sejerpz@tin.it>
 */

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


#define AFRODITE_TYPE_SOURCE_TYPE (afrodite_source_type_get_type ())

#define AFRODITE_TYPE_SOURCE_ITEM (afrodite_source_item_get_type ())
#define AFRODITE_SOURCE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), AFRODITE_TYPE_SOURCE_ITEM, AfroditeSourceItem))
#define AFRODITE_SOURCE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), AFRODITE_TYPE_SOURCE_ITEM, AfroditeSourceItemClass))
#define AFRODITE_IS_SOURCE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AFRODITE_TYPE_SOURCE_ITEM))
#define AFRODITE_IS_SOURCE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), AFRODITE_TYPE_SOURCE_ITEM))
#define AFRODITE_SOURCE_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AFRODITE_TYPE_SOURCE_ITEM, AfroditeSourceItemClass))

typedef struct _AfroditeSourceItem AfroditeSourceItem;
typedef struct _AfroditeSourceItemClass AfroditeSourceItemClass;
typedef struct _AfroditeSourceItemPrivate AfroditeSourceItemPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_code_context_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_context_unref (var), NULL)))
#define _afrodite_source_item_unref0(var) ((var == NULL) ? NULL : (var = (afrodite_source_item_unref (var), NULL)))
typedef struct _AfroditeParamSpecSourceItem AfroditeParamSpecSourceItem;

typedef enum  {
	AFRODITE_SOURCE_TYPE_AUTO,
	AFRODITE_SOURCE_TYPE_VALA,
	AFRODITE_SOURCE_TYPE_GENIE,
	AFRODITE_SOURCE_TYPE_VAPI,
	AFRODITE_SOURCE_TYPE_UNKNOWN
} AfroditeSourceType;

struct _AfroditeSourceItem {
	GTypeInstance parent_instance;
	volatile int ref_count;
	AfroditeSourceItemPrivate * priv;
	gchar* content;
	AfroditeSourceType source_type;
	gboolean is_glib;
	ValaCodeContext* context;
};

struct _AfroditeSourceItemClass {
	GTypeClass parent_class;
	void (*finalize) (AfroditeSourceItem *self);
};

struct _AfroditeSourceItemPrivate {
	gchar* _path;
};

struct _AfroditeParamSpecSourceItem {
	GParamSpec parent_instance;
};


static gpointer afrodite_source_item_parent_class = NULL;

GType afrodite_source_type_get_type (void) G_GNUC_CONST;
gpointer afrodite_source_item_ref (gpointer instance);
void afrodite_source_item_unref (gpointer instance);
GParamSpec* afrodite_param_spec_source_item (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags);
void afrodite_value_set_source_item (GValue* value, gpointer v_object);
void afrodite_value_take_source_item (GValue* value, gpointer v_object);
gpointer afrodite_value_get_source_item (const GValue* value);
GType afrodite_source_item_get_type (void) G_GNUC_CONST;
#define AFRODITE_SOURCE_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), AFRODITE_TYPE_SOURCE_ITEM, AfroditeSourceItemPrivate))
enum  {
	AFRODITE_SOURCE_ITEM_DUMMY_PROPERTY
};
AfroditeSourceItem* afrodite_source_item_new (const gchar* path, AfroditeSourceType source_type);
AfroditeSourceItem* afrodite_source_item_construct (GType object_type, const gchar* path, AfroditeSourceType source_type);
AfroditeSourceType afrodite_source_item_get_source_type (const gchar* path);
AfroditeSourceItem* afrodite_source_item_copy (AfroditeSourceItem* self);
const gchar* afrodite_source_item_get_path (AfroditeSourceItem* self);
static void afrodite_source_item_finalize (AfroditeSourceItem* obj);


GType afrodite_source_type_get_type (void) {
	static volatile gsize afrodite_source_type_type_id__volatile = 0;
	if (g_once_init_enter (&afrodite_source_type_type_id__volatile)) {
		static const GEnumValue values[] = {{AFRODITE_SOURCE_TYPE_AUTO, "AFRODITE_SOURCE_TYPE_AUTO", "auto"}, {AFRODITE_SOURCE_TYPE_VALA, "AFRODITE_SOURCE_TYPE_VALA", "vala"}, {AFRODITE_SOURCE_TYPE_GENIE, "AFRODITE_SOURCE_TYPE_GENIE", "genie"}, {AFRODITE_SOURCE_TYPE_VAPI, "AFRODITE_SOURCE_TYPE_VAPI", "vapi"}, {AFRODITE_SOURCE_TYPE_UNKNOWN, "AFRODITE_SOURCE_TYPE_UNKNOWN", "unknown"}, {0, NULL, NULL}};
		GType afrodite_source_type_type_id;
		afrodite_source_type_type_id = g_enum_register_static ("AfroditeSourceType", values);
		g_once_init_leave (&afrodite_source_type_type_id__volatile, afrodite_source_type_type_id);
	}
	return afrodite_source_type_type_id__volatile;
}


AfroditeSourceItem* afrodite_source_item_construct (GType object_type, const gchar* path, AfroditeSourceType source_type) {
	AfroditeSourceItem* self = NULL;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp1_;
	self = (AfroditeSourceItem*) g_type_create_instance (object_type);
	if (path == NULL) {
		_tmp0_ = source_type == AFRODITE_SOURCE_TYPE_AUTO;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		g_critical ("sourceitem.vala:54: You have to specified either a path or a source_ty" \
"pe");
	}
	_tmp1_ = g_strdup (path);
	_g_free0 (self->priv->_path);
	self->priv->_path = _tmp1_;
	if (source_type == AFRODITE_SOURCE_TYPE_AUTO) {
		AfroditeSourceType _tmp2_;
		_tmp2_ = afrodite_source_item_get_source_type (self->priv->_path);
		self->source_type = _tmp2_;
		if (self->source_type == AFRODITE_SOURCE_TYPE_UNKNOWN) {
			g_critical ("sourceitem.vala:61: Cannot determine the source type");
		}
	} else {
		self->source_type = source_type;
	}
	return self;
}


AfroditeSourceItem* afrodite_source_item_new (const gchar* path, AfroditeSourceType source_type) {
	return afrodite_source_item_construct (AFRODITE_TYPE_SOURCE_ITEM, path, source_type);
}


AfroditeSourceItem* afrodite_source_item_copy (AfroditeSourceItem* self) {
	AfroditeSourceItem* result = NULL;
	const gchar* _tmp0_ = NULL;
	AfroditeSourceItem* _tmp1_ = NULL;
	AfroditeSourceItem* item;
	gchar* _tmp2_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = afrodite_source_item_get_path (self);
	_tmp1_ = afrodite_source_item_new (_tmp0_, self->source_type);
	item = _tmp1_;
	_tmp2_ = g_strdup (self->content);
	_g_free0 (item->content);
	item->content = _tmp2_;
	item->is_glib = self->is_glib;
	result = item;
	return result;
}


AfroditeSourceType afrodite_source_item_get_source_type (const gchar* path) {
	AfroditeSourceType result = 0;
	AfroditeSourceType _result_ = 0;
	gboolean _tmp0_;
	g_return_val_if_fail (path != NULL, 0);
	_tmp0_ = g_str_has_suffix (path, ".vapi");
	if (_tmp0_) {
		_result_ = AFRODITE_SOURCE_TYPE_VAPI;
	} else {
		gboolean _tmp1_;
		_tmp1_ = g_str_has_suffix (path, ".gs");
		if (_tmp1_) {
			_result_ = AFRODITE_SOURCE_TYPE_GENIE;
		} else {
			gboolean _tmp2_;
			_tmp2_ = g_str_has_suffix (path, ".vala");
			if (_tmp2_) {
				_result_ = AFRODITE_SOURCE_TYPE_VALA;
			} else {
				_result_ = AFRODITE_SOURCE_TYPE_UNKNOWN;
			}
		}
	}
	result = _result_;
	return result;
}


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


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


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


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


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


static gchar* afrodite_value_source_item_collect_value (GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	if (collect_values[0].v_pointer) {
		AfroditeSourceItem* 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 = afrodite_source_item_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}


static gchar* afrodite_value_source_item_lcopy_value (const GValue* value, guint n_collect_values, GTypeCValue* collect_values, guint collect_flags) {
	AfroditeSourceItem** 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 = afrodite_source_item_ref (value->data[0].v_pointer);
	}
	return NULL;
}


GParamSpec* afrodite_param_spec_source_item (const gchar* name, const gchar* nick, const gchar* blurb, GType object_type, GParamFlags flags) {
	AfroditeParamSpecSourceItem* spec;
	g_return_val_if_fail (g_type_is_a (object_type, AFRODITE_TYPE_SOURCE_ITEM), 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 afrodite_value_get_source_item (const GValue* value) {
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, AFRODITE_TYPE_SOURCE_ITEM), NULL);
	return value->data[0].v_pointer;
}


void afrodite_value_set_source_item (GValue* value, gpointer v_object) {
	AfroditeSourceItem* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, AFRODITE_TYPE_SOURCE_ITEM));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, AFRODITE_TYPE_SOURCE_ITEM));
		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;
		afrodite_source_item_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		afrodite_source_item_unref (old);
	}
}


void afrodite_value_take_source_item (GValue* value, gpointer v_object) {
	AfroditeSourceItem* old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, AFRODITE_TYPE_SOURCE_ITEM));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, AFRODITE_TYPE_SOURCE_ITEM));
		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) {
		afrodite_source_item_unref (old);
	}
}


static void afrodite_source_item_class_init (AfroditeSourceItemClass * klass) {
	afrodite_source_item_parent_class = g_type_class_peek_parent (klass);
	AFRODITE_SOURCE_ITEM_CLASS (klass)->finalize = afrodite_source_item_finalize;
	g_type_class_add_private (klass, sizeof (AfroditeSourceItemPrivate));
}


static void afrodite_source_item_instance_init (AfroditeSourceItem * self) {
	self->priv = AFRODITE_SOURCE_ITEM_GET_PRIVATE (self);
	self->source_type = AFRODITE_SOURCE_TYPE_AUTO;
	self->is_glib = FALSE;
	self->context = NULL;
	self->ref_count = 1;
}


static void afrodite_source_item_finalize (AfroditeSourceItem* obj) {
	AfroditeSourceItem * self;
	self = AFRODITE_SOURCE_ITEM (obj);
	_g_free0 (self->priv->_path);
	_g_free0 (self->content);
	_vala_code_context_unref0 (self->context);
}


GType afrodite_source_item_get_type (void) {
	static volatile gsize afrodite_source_item_type_id__volatile = 0;
	if (g_once_init_enter (&afrodite_source_item_type_id__volatile)) {
		static const GTypeValueTable g_define_type_value_table = { afrodite_value_source_item_init, afrodite_value_source_item_free_value, afrodite_value_source_item_copy_value, afrodite_value_source_item_peek_pointer, "p", afrodite_value_source_item_collect_value, "p", afrodite_value_source_item_lcopy_value };
		static const GTypeInfo g_define_type_info = { sizeof (AfroditeSourceItemClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) afrodite_source_item_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (AfroditeSourceItem), 0, (GInstanceInitFunc) afrodite_source_item_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 afrodite_source_item_type_id;
		afrodite_source_item_type_id = g_type_register_fundamental (g_type_fundamental_next (), "AfroditeSourceItem", &g_define_type_info, &g_define_type_fundamental_info, 0);
		g_once_init_leave (&afrodite_source_item_type_id__volatile, afrodite_source_item_type_id);
	}
	return afrodite_source_item_type_id__volatile;
}


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


void afrodite_source_item_unref (gpointer instance) {
	AfroditeSourceItem* self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		AFRODITE_SOURCE_ITEM_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}



