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

/* valaattribute.vala
 *
 * Copyright (C) 2006-2008  Jürg Billeter
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 */

#include <glib.h>
#include <glib-object.h>
#include "vala.h"
#include <stdlib.h>
#include <string.h>
#include <valagee.h>
#include <float.h>
#include <math.h>

#define _g_free0(var) (var = (g_free (var), NULL))
#define _vala_map_unref0(var) ((var == NULL) ? NULL : (var = (vala_map_unref (var), NULL)))
#define _vala_code_context_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_context_unref (var), NULL)))

struct _ValaAttributePrivate {
	gchar* _name;
};


static gpointer vala_attribute_parent_class = NULL;

#define VALA_ATTRIBUTE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VALA_TYPE_ATTRIBUTE, ValaAttributePrivate))
static void vala_attribute_finalize (ValaCodeNode * obj);


/**
 * Creates a new attribute.
 *
 * @param name             attribute type name
 * @param source_reference reference to source code
 * @return                 newly created attribute
 */
ValaAttribute* vala_attribute_construct (GType object_type, const gchar* name, ValaSourceReference* source_reference) {
	ValaAttribute* self = NULL;
	const gchar* _tmp0_;
	ValaSourceReference* _tmp1_;
	ValaCodeContext* _tmp2_;
	ValaCodeContext* _tmp3_;
	gboolean _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	g_return_val_if_fail (name != NULL, NULL);
	self = (ValaAttribute*) vala_code_node_construct (object_type);
	_tmp0_ = name;
	vala_attribute_set_name (self, _tmp0_);
	_tmp1_ = source_reference;
	vala_code_node_set_source_reference ((ValaCodeNode*) self, _tmp1_);
	_tmp2_ = vala_code_context_get ();
	_tmp3_ = _tmp2_;
	_tmp4_ = vala_code_context_get_deprecated (_tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = !_tmp5_;
	_vala_code_context_unref0 (_tmp3_);
	if (_tmp6_) {
		const gchar* _tmp7_;
		_tmp7_ = name;
		if (g_strcmp0 (_tmp7_, "Deprecated") == 0) {
			ValaSourceReference* _tmp8_;
			_tmp8_ = source_reference;
			vala_report_deprecated (_tmp8_, "[Deprecated] is deprecated. Use [Version (deprecated = true, deprecate" \
"d_since = \"\", replacement = \"\")]");
		} else {
			const gchar* _tmp9_;
			_tmp9_ = name;
			if (g_strcmp0 (_tmp9_, "Experimental") == 0) {
				ValaSourceReference* _tmp10_;
				_tmp10_ = source_reference;
				vala_report_deprecated (_tmp10_, "[Experimental] is deprecated. Use [Version (experimental = true, exper" \
"imental_until = \"\")]");
			}
		}
	}
	return self;
}


ValaAttribute* vala_attribute_new (const gchar* name, ValaSourceReference* source_reference) {
	return vala_attribute_construct (VALA_TYPE_ATTRIBUTE, name, source_reference);
}


/**
 * Adds an attribute argument.
 *
 * @param key    argument name
 * @param value  argument value
 */
void vala_attribute_add_argument (ValaAttribute* self, const gchar* key, const gchar* value) {
	ValaMap* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (key != NULL);
	g_return_if_fail (value != NULL);
	_tmp0_ = self->args;
	_tmp1_ = key;
	_tmp2_ = value;
	vala_map_set (_tmp0_, _tmp1_, _tmp2_);
}


/**
 * Returns whether this attribute has the specified named argument.
 *
 * @param name argument name
 * @return     true if the argument has been found, false otherwise
 */
gboolean vala_attribute_has_argument (ValaAttribute* self, const gchar* name) {
	gboolean result = FALSE;
	ValaMap* _tmp0_;
	const gchar* _tmp1_;
	gboolean _tmp2_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (name != NULL, FALSE);
	_tmp0_ = self->args;
	_tmp1_ = name;
	_tmp2_ = vala_map_contains (_tmp0_, _tmp1_);
	result = _tmp2_;
	return result;
}


/**
 * Returns the string value of the specified named argument.
 *
 * @param name argument name
 * @return     string value
 */
static glong string_strnlen (gchar* str, glong maxlen) {
	glong result = 0L;
	gchar* end = NULL;
	gchar* _tmp0_;
	glong _tmp1_;
	gchar* _tmp2_;
	gchar* _tmp3_;
	_tmp0_ = str;
	_tmp1_ = maxlen;
	_tmp2_ = memchr (_tmp0_, 0, (gsize) _tmp1_);
	end = _tmp2_;
	_tmp3_ = end;
	if (_tmp3_ == NULL) {
		glong _tmp4_;
		_tmp4_ = maxlen;
		result = _tmp4_;
		return result;
	} else {
		gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp5_ = end;
		_tmp6_ = str;
		result = (glong) (_tmp5_ - _tmp6_);
		return result;
	}
}


static gchar* string_substring (const gchar* self, glong offset, glong len) {
	gchar* result = NULL;
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	glong _tmp1_;
	glong _tmp8_;
	glong _tmp14_;
	glong _tmp17_;
	glong _tmp18_;
	glong _tmp19_;
	glong _tmp20_;
	glong _tmp21_;
	gchar* _tmp22_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = offset;
	if (_tmp1_ >= ((glong) 0)) {
		glong _tmp2_;
		_tmp2_ = len;
		_tmp0_ = _tmp2_ >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		glong _tmp3_;
		glong _tmp4_;
		glong _tmp5_;
		_tmp3_ = offset;
		_tmp4_ = len;
		_tmp5_ = string_strnlen ((gchar*) self, _tmp3_ + _tmp4_);
		string_length = _tmp5_;
	} else {
		gint _tmp6_;
		gint _tmp7_;
		_tmp6_ = strlen (self);
		_tmp7_ = _tmp6_;
		string_length = (glong) _tmp7_;
	}
	_tmp8_ = offset;
	if (_tmp8_ < ((glong) 0)) {
		glong _tmp9_;
		glong _tmp10_;
		glong _tmp11_;
		_tmp9_ = string_length;
		_tmp10_ = offset;
		offset = _tmp9_ + _tmp10_;
		_tmp11_ = offset;
		g_return_val_if_fail (_tmp11_ >= ((glong) 0), NULL);
	} else {
		glong _tmp12_;
		glong _tmp13_;
		_tmp12_ = offset;
		_tmp13_ = string_length;
		g_return_val_if_fail (_tmp12_ <= _tmp13_, NULL);
	}
	_tmp14_ = len;
	if (_tmp14_ < ((glong) 0)) {
		glong _tmp15_;
		glong _tmp16_;
		_tmp15_ = string_length;
		_tmp16_ = offset;
		len = _tmp15_ - _tmp16_;
	}
	_tmp17_ = offset;
	_tmp18_ = len;
	_tmp19_ = string_length;
	g_return_val_if_fail ((_tmp17_ + _tmp18_) <= _tmp19_, NULL);
	_tmp20_ = offset;
	_tmp21_ = len;
	_tmp22_ = g_strndup (((gchar*) self) + _tmp20_, (gsize) _tmp21_);
	result = _tmp22_;
	return result;
}


gchar* vala_attribute_get_string (ValaAttribute* self, const gchar* name, const gchar* default_value) {
	gchar* result = NULL;
	gchar* value = NULL;
	ValaMap* _tmp0_;
	const gchar* _tmp1_;
	gpointer _tmp2_;
	const gchar* _tmp3_;
	gchar* noquotes = NULL;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gint _tmp8_;
	gint _tmp9_;
	gchar* _tmp10_;
	const gchar* _tmp11_;
	gchar* _tmp12_;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	_tmp0_ = self->args;
	_tmp1_ = name;
	_tmp2_ = vala_map_get (_tmp0_, _tmp1_);
	value = (gchar*) _tmp2_;
	_tmp3_ = value;
	if (_tmp3_ == NULL) {
		const gchar* _tmp4_;
		gchar* _tmp5_;
		_tmp4_ = default_value;
		_tmp5_ = g_strdup (_tmp4_);
		result = _tmp5_;
		_g_free0 (value);
		return result;
	}
	_tmp6_ = value;
	_tmp7_ = value;
	_tmp8_ = strlen (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = string_substring (_tmp6_, (glong) 1, (glong) ((guint) (_tmp9_ - 2)));
	noquotes = _tmp10_;
	_tmp11_ = noquotes;
	_tmp12_ = g_strcompress (_tmp11_);
	result = _tmp12_;
	_g_free0 (noquotes);
	_g_free0 (value);
	return result;
}


/**
 * Returns the integer value of the specified named argument.
 *
 * @param name argument name
 * @return     integer value
 */
gint vala_attribute_get_integer (ValaAttribute* self, const gchar* name, gint default_value) {
	gint result = 0;
	gchar* value = NULL;
	ValaMap* _tmp0_;
	const gchar* _tmp1_;
	gpointer _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp5_;
	gint _tmp6_;
	g_return_val_if_fail (self != NULL, 0);
	g_return_val_if_fail (name != NULL, 0);
	_tmp0_ = self->args;
	_tmp1_ = name;
	_tmp2_ = vala_map_get (_tmp0_, _tmp1_);
	value = (gchar*) _tmp2_;
	_tmp3_ = value;
	if (_tmp3_ == NULL) {
		gint _tmp4_;
		_tmp4_ = default_value;
		result = _tmp4_;
		_g_free0 (value);
		return result;
	}
	_tmp5_ = value;
	_tmp6_ = atoi (_tmp5_);
	result = _tmp6_;
	_g_free0 (value);
	return result;
}


/**
 * Returns the double value of the specified named argument.
 *
 * @param name argument name
 * @return     double value
 */
static gdouble double_parse (const gchar* str) {
	gdouble result = 0.0;
	const gchar* _tmp0_;
	gdouble _tmp1_;
	g_return_val_if_fail (str != NULL, 0.0);
	_tmp0_ = str;
	_tmp1_ = g_ascii_strtod (_tmp0_, NULL);
	result = _tmp1_;
	return result;
}


gdouble vala_attribute_get_double (ValaAttribute* self, const gchar* name, gdouble default_value) {
	gdouble result = 0.0;
	gchar* value = NULL;
	ValaMap* _tmp0_;
	const gchar* _tmp1_;
	gpointer _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp5_;
	gdouble _tmp6_;
	g_return_val_if_fail (self != NULL, 0.0);
	g_return_val_if_fail (name != NULL, 0.0);
	_tmp0_ = self->args;
	_tmp1_ = name;
	_tmp2_ = vala_map_get (_tmp0_, _tmp1_);
	value = (gchar*) _tmp2_;
	_tmp3_ = value;
	if (_tmp3_ == NULL) {
		gdouble _tmp4_;
		_tmp4_ = default_value;
		result = _tmp4_;
		_g_free0 (value);
		return result;
	}
	_tmp5_ = value;
	_tmp6_ = double_parse (_tmp5_);
	result = _tmp6_;
	_g_free0 (value);
	return result;
}


/**
 * Returns the boolean value of the specified named argument.
 *
 * @param name argument name
 * @return     boolean value
 */
static gboolean bool_parse (const gchar* str) {
	gboolean result = FALSE;
	const gchar* _tmp0_;
	g_return_val_if_fail (str != NULL, FALSE);
	_tmp0_ = str;
	if (g_strcmp0 (_tmp0_, "true") == 0) {
		result = TRUE;
		return result;
	} else {
		result = FALSE;
		return result;
	}
}


gboolean vala_attribute_get_bool (ValaAttribute* self, const gchar* name, gboolean default_value) {
	gboolean result = FALSE;
	gchar* value = NULL;
	ValaMap* _tmp0_;
	const gchar* _tmp1_;
	gpointer _tmp2_;
	const gchar* _tmp3_;
	const gchar* _tmp5_;
	gboolean _tmp6_;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (name != NULL, FALSE);
	_tmp0_ = self->args;
	_tmp1_ = name;
	_tmp2_ = vala_map_get (_tmp0_, _tmp1_);
	value = (gchar*) _tmp2_;
	_tmp3_ = value;
	if (_tmp3_ == NULL) {
		gboolean _tmp4_;
		_tmp4_ = default_value;
		result = _tmp4_;
		_g_free0 (value);
		return result;
	}
	_tmp5_ = value;
	_tmp6_ = bool_parse (_tmp5_);
	result = _tmp6_;
	_g_free0 (value);
	return result;
}


const gchar* vala_attribute_get_name (ValaAttribute* self) {
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}


void vala_attribute_set_name (ValaAttribute* self, const gchar* value) {
	const gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = value;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_name);
	self->priv->_name = _tmp1_;
}


static void vala_attribute_class_init (ValaAttributeClass * klass) {
	vala_attribute_parent_class = g_type_class_peek_parent (klass);
	((ValaCodeNodeClass *) klass)->finalize = vala_attribute_finalize;
	g_type_class_add_private (klass, sizeof (ValaAttributePrivate));
}


static void vala_attribute_instance_init (ValaAttribute * self) {
	GHashFunc _tmp0_;
	GEqualFunc _tmp1_;
	GEqualFunc _tmp2_;
	ValaHashMap* _tmp3_;
	self->priv = VALA_ATTRIBUTE_GET_PRIVATE (self);
	_tmp0_ = g_str_hash;
	_tmp1_ = g_str_equal;
	_tmp2_ = g_direct_equal;
	_tmp3_ = vala_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp0_, _tmp1_, _tmp2_);
	self->args = (ValaMap*) _tmp3_;
}


static void vala_attribute_finalize (ValaCodeNode * obj) {
	ValaAttribute * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_ATTRIBUTE, ValaAttribute);
	_g_free0 (self->priv->_name);
	_vala_map_unref0 (self->args);
	VALA_CODE_NODE_CLASS (vala_attribute_parent_class)->finalize (obj);
}


/**
 * Represents an attribute specified in the source code.
 */
GType vala_attribute_get_type (void) {
	static volatile gsize vala_attribute_type_id__volatile = 0;
	if (g_once_init_enter (&vala_attribute_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValaAttributeClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_attribute_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaAttribute), 0, (GInstanceInitFunc) vala_attribute_instance_init, NULL };
		GType vala_attribute_type_id;
		vala_attribute_type_id = g_type_register_static (VALA_TYPE_CODE_NODE, "ValaAttribute", &g_define_type_info, 0);
		g_once_init_leave (&vala_attribute_type_id__volatile, vala_attribute_type_id);
	}
	return vala_attribute_type_id__volatile;
}



