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

/* array.vala
 *
 * Copyright (C) 2011  Florian Brosch
 *
 * 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:
 * 	Florian Brosch <flo.brosch@gmail.com>
 */

#include "valadoc.h"
#include <glib.h>
#include <glib-object.h>
#include <vala.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

enum  {
	VALADOC_API_ARRAY_0_PROPERTY,
	VALADOC_API_ARRAY_DATA_TYPE_PROPERTY,
	VALADOC_API_ARRAY_NUM_PROPERTIES
};
static GParamSpec* valadoc_api_array_properties[VALADOC_API_ARRAY_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _valadoc_api_signature_builder_unref0(var) ((var == NULL) ? NULL : (var = (valadoc_api_signature_builder_unref (var), NULL)))

struct _ValadocApiArrayPrivate {
	ValadocApiItem* _data_type;
};

static gint ValadocApiArray_private_offset;
static gpointer valadoc_api_array_parent_class = NULL;

static inline gboolean valadoc_api_array_element_is_owned (ValadocApiArray* self);
static ValadocContentInline* valadoc_api_array_real_build_signature (ValadocApiItem* base);
static void valadoc_api_array_finalize (GObject * obj);
static GType valadoc_api_array_get_type_once (void);
static void _vala_valadoc_api_array_get_property (GObject * object,
                                           guint property_id,
                                           GValue * value,
                                           GParamSpec * pspec);
static void _vala_valadoc_api_array_set_property (GObject * object,
                                           guint property_id,
                                           const GValue * value,
                                           GParamSpec * pspec);

static inline gpointer
valadoc_api_array_get_instance_private (ValadocApiArray* self)
{
	return G_STRUCT_MEMBER_P (self, ValadocApiArray_private_offset);
}

ValadocApiItem*
valadoc_api_array_get_data_type (ValadocApiArray* self)
{
	ValadocApiItem* result;
	ValadocApiItem* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_data_type;
	result = _tmp0_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

void
valadoc_api_array_set_data_type (ValadocApiArray* self,
                                 ValadocApiItem* value)
{
	ValadocApiItem* old_value;
	g_return_if_fail (self != NULL);
	old_value = valadoc_api_array_get_data_type (self);
	if (old_value != value) {
		ValadocApiItem* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_data_type);
		self->priv->_data_type = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, valadoc_api_array_properties[VALADOC_API_ARRAY_DATA_TYPE_PROPERTY]);
	}
}

ValadocApiArray*
valadoc_api_array_construct (GType object_type,
                             ValadocApiItem* parent,
                             ValaArrayType* data)
{
	ValadocApiArray * self = NULL;
	g_return_val_if_fail (parent != NULL, NULL);
	g_return_val_if_fail (data != NULL, NULL);
	self = (ValadocApiArray*) valadoc_api_item_construct (object_type, (ValaCodeNode*) data);
	valadoc_api_item_set_parent ((ValadocApiItem*) self, parent);
	return self;
}

ValadocApiArray*
valadoc_api_array_new (ValadocApiItem* parent,
                       ValaArrayType* data)
{
	return valadoc_api_array_construct (VALADOC_API_TYPE_ARRAY, parent, data);
}

static inline gboolean
valadoc_api_array_element_is_owned (ValadocApiArray* self)
{
	ValadocApiTypeReference* reference = NULL;
	ValadocApiItem* _tmp0_;
	ValadocApiTypeReference* _tmp1_;
	ValadocApiTypeReference* _tmp2_;
	gboolean _tmp3_ = FALSE;
	ValadocApiTypeReference* _tmp4_;
	gboolean _tmp5_;
	gboolean _tmp6_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_data_type;
	_tmp1_ = _g_object_ref0 (VALADOC_API_IS_TYPEREFERENCE (_tmp0_) ? ((ValadocApiTypeReference*) _tmp0_) : NULL);
	reference = _tmp1_;
	_tmp2_ = reference;
	if (_tmp2_ == NULL) {
		result = TRUE;
		_g_object_unref0 (reference);
		return result;
	}
	_tmp4_ = reference;
	_tmp5_ = valadoc_api_typereference_get_is_unowned (_tmp4_);
	_tmp6_ = _tmp5_;
	if (!_tmp6_) {
		ValadocApiTypeReference* _tmp7_;
		gboolean _tmp8_;
		gboolean _tmp9_;
		_tmp7_ = reference;
		_tmp8_ = valadoc_api_typereference_get_is_weak (_tmp7_);
		_tmp9_ = _tmp8_;
		_tmp3_ = !_tmp9_;
	} else {
		_tmp3_ = FALSE;
	}
	result = _tmp3_;
	_g_object_unref0 (reference);
	return result;
}

/**
 * {@inheritDoc}
 */
static ValadocContentInline*
valadoc_api_array_real_build_signature (ValadocApiItem* base)
{
	ValadocApiArray * self;
	ValadocApiSignatureBuilder* builder = NULL;
	ValadocApiSignatureBuilder* _tmp0_;
	ValadocApiSignatureBuilder* _tmp11_;
	ValadocApiSignatureBuilder* _tmp12_;
	ValadocContentRun* _tmp13_;
	ValadocContentInline* result;
	self = (ValadocApiArray*) base;
	_tmp0_ = valadoc_api_signature_builder_new ();
	builder = _tmp0_;
	if (valadoc_api_array_element_is_owned (self)) {
		ValadocApiSignatureBuilder* _tmp1_;
		ValadocApiItem* _tmp2_;
		ValadocContentInline* _tmp3_;
		ValadocContentInline* _tmp4_;
		_tmp1_ = builder;
		_tmp2_ = self->priv->_data_type;
		_tmp3_ = valadoc_api_item_get_signature (_tmp2_);
		_tmp4_ = _tmp3_;
		valadoc_api_signature_builder_append_content (_tmp1_, _tmp4_, TRUE);
	} else {
		ValadocApiSignatureBuilder* _tmp5_;
		ValadocApiSignatureBuilder* _tmp6_;
		ValadocApiItem* _tmp7_;
		ValadocContentInline* _tmp8_;
		ValadocContentInline* _tmp9_;
		ValadocApiSignatureBuilder* _tmp10_;
		_tmp5_ = builder;
		valadoc_api_signature_builder_append (_tmp5_, "(", FALSE);
		_tmp6_ = builder;
		_tmp7_ = self->priv->_data_type;
		_tmp8_ = valadoc_api_item_get_signature (_tmp7_);
		_tmp9_ = _tmp8_;
		valadoc_api_signature_builder_append_content (_tmp6_, _tmp9_, FALSE);
		_tmp10_ = builder;
		valadoc_api_signature_builder_append (_tmp10_, ")", FALSE);
	}
	_tmp11_ = builder;
	valadoc_api_signature_builder_append (_tmp11_, "[]", FALSE);
	_tmp12_ = builder;
	_tmp13_ = valadoc_api_signature_builder_get (_tmp12_);
	result = (ValadocContentInline*) _tmp13_;
	_valadoc_api_signature_builder_unref0 (builder);
	return result;
}

static void
valadoc_api_array_class_init (ValadocApiArrayClass * klass,
                              gpointer klass_data)
{
	valadoc_api_array_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &ValadocApiArray_private_offset);
	((ValadocApiItemClass *) klass)->build_signature = (ValadocContentInline* (*) (ValadocApiItem*)) valadoc_api_array_real_build_signature;
	G_OBJECT_CLASS (klass)->get_property = _vala_valadoc_api_array_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_valadoc_api_array_set_property;
	G_OBJECT_CLASS (klass)->finalize = valadoc_api_array_finalize;
	/**
	 * The element type.
	 */
	g_object_class_install_property (G_OBJECT_CLASS (klass), VALADOC_API_ARRAY_DATA_TYPE_PROPERTY, valadoc_api_array_properties[VALADOC_API_ARRAY_DATA_TYPE_PROPERTY] = g_param_spec_object ("data-type", "data-type", "data-type", VALADOC_API_TYPE_ITEM, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
}

static void
valadoc_api_array_instance_init (ValadocApiArray * self,
                                 gpointer klass)
{
	self->priv = valadoc_api_array_get_instance_private (self);
}

static void
valadoc_api_array_finalize (GObject * obj)
{
	ValadocApiArray * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALADOC_API_TYPE_ARRAY, ValadocApiArray);
	_g_object_unref0 (self->priv->_data_type);
	G_OBJECT_CLASS (valadoc_api_array_parent_class)->finalize (obj);
}

/**
 * Represents an array declaration.
 */
static GType
valadoc_api_array_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (ValadocApiArrayClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) valadoc_api_array_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValadocApiArray), 0, (GInstanceInitFunc) valadoc_api_array_instance_init, NULL };
	GType valadoc_api_array_type_id;
	valadoc_api_array_type_id = g_type_register_static (VALADOC_API_TYPE_ITEM, "ValadocApiArray", &g_define_type_info, 0);
	ValadocApiArray_private_offset = g_type_add_instance_private (valadoc_api_array_type_id, sizeof (ValadocApiArrayPrivate));
	return valadoc_api_array_type_id;
}

GType
valadoc_api_array_get_type (void)
{
	static volatile gsize valadoc_api_array_type_id__once = 0;
	if (g_once_init_enter (&valadoc_api_array_type_id__once)) {
		GType valadoc_api_array_type_id;
		valadoc_api_array_type_id = valadoc_api_array_get_type_once ();
		g_once_init_leave (&valadoc_api_array_type_id__once, valadoc_api_array_type_id);
	}
	return valadoc_api_array_type_id__once;
}

static void
_vala_valadoc_api_array_get_property (GObject * object,
                                      guint property_id,
                                      GValue * value,
                                      GParamSpec * pspec)
{
	ValadocApiArray * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, VALADOC_API_TYPE_ARRAY, ValadocApiArray);
	switch (property_id) {
		case VALADOC_API_ARRAY_DATA_TYPE_PROPERTY:
		g_value_set_object (value, valadoc_api_array_get_data_type (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_valadoc_api_array_set_property (GObject * object,
                                      guint property_id,
                                      const GValue * value,
                                      GParamSpec * pspec)
{
	ValadocApiArray * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, VALADOC_API_TYPE_ARRAY, ValadocApiArray);
	switch (property_id) {
		case VALADOC_API_ARRAY_DATA_TYPE_PROPERTY:
		valadoc_api_array_set_data_type (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

