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


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_MENU_MODEL (menu_model_get_type ())
#define MENU_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MENU_MODEL, MenuModel))
#define MENU_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MENU_MODEL, MenuModelClass))
#define IS_MENU_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MENU_MODEL))
#define IS_MENU_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MENU_MODEL))
#define MENU_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MENU_MODEL, MenuModelClass))

typedef struct _MenuModel MenuModel;
typedef struct _MenuModelClass MenuModelClass;
typedef struct _MenuModelPrivate MenuModelPrivate;

#define TYPE_PROVIDERS (providers_get_type ())
#define PROVIDERS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_PROVIDERS, Providers))
#define PROVIDERS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_PROVIDERS, ProvidersClass))
#define IS_PROVIDERS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_PROVIDERS))
#define IS_PROVIDERS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_PROVIDERS))
#define PROVIDERS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_PROVIDERS, ProvidersClass))

typedef struct _Providers Providers;
typedef struct _ProvidersClass ProvidersClass;

#define TYPE_EXPRESSION_CACHE (expression_cache_get_type ())
#define EXPRESSION_CACHE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_EXPRESSION_CACHE, ExpressionCache))
#define EXPRESSION_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_EXPRESSION_CACHE, ExpressionCacheClass))
#define IS_EXPRESSION_CACHE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_EXPRESSION_CACHE))
#define IS_EXPRESSION_CACHE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_EXPRESSION_CACHE))
#define EXPRESSION_CACHE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_EXPRESSION_CACHE, ExpressionCacheClass))

typedef struct _ExpressionCache ExpressionCache;
typedef struct _ExpressionCacheClass ExpressionCacheClass;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _MenuModel {
	GObject parent_instance;
	MenuModelPrivate * priv;
};

struct _MenuModelClass {
	GObjectClass parent_class;
};

struct _MenuModelPrivate {
	Providers* providers;
	ExpressionCache** caches;
	gint caches_length1;
	gint _caches_size_;
	gchar** _expressions;
	gint _expressions_length1;
	gint __expressions_size_;
};


static gpointer menu_model_parent_class = NULL;

GType menu_model_get_type (void) G_GNUC_CONST;
GType providers_get_type (void) G_GNUC_CONST;
GType expression_cache_get_type (void) G_GNUC_CONST;
#define MENU_MODEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_MENU_MODEL, MenuModelPrivate))
enum  {
	MENU_MODEL_DUMMY_PROPERTY,
	MENU_MODEL_EXPRESSIONS
};
MenuModel* menu_model_new (Providers* providers);
MenuModel* menu_model_construct (GType object_type, Providers* providers);
void menu_model_update (MenuModel* self);
void expression_cache_update (ExpressionCache* self);
ExpressionCache* menu_model_expression (MenuModel* self, guint index);
gchar** menu_model_get_expressions (MenuModel* self, int* result_length1);
void menu_model_set_expressions (MenuModel* self, gchar** value, int value_length1);
static gchar** _vala_array_dup20 (gchar** self, int length);
static GObject * menu_model_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static void _menu_model___lambda6_ (MenuModel* self);
ExpressionCache* expression_cache_new (Providers* providers, const gchar* expression);
ExpressionCache* expression_cache_construct (GType object_type, Providers* providers, const gchar* expression);
static void __menu_model___lambda6__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self);
static void menu_model_finalize (GObject* obj);
static void _vala_menu_model_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_menu_model_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);


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


MenuModel* menu_model_construct (GType object_type, Providers* providers) {
	MenuModel * self = NULL;
	Providers* _tmp0_ = NULL;
	Providers* _tmp1_ = NULL;
	g_return_val_if_fail (IS_PROVIDERS (providers), NULL);
	self = (MenuModel*) g_object_new (object_type, NULL);
	_tmp0_ = providers;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->providers);
	self->priv->providers = _tmp1_;
	return self;
}


MenuModel* menu_model_new (Providers* providers) {
	return menu_model_construct (TYPE_MENU_MODEL, providers);
}


void menu_model_update (MenuModel* self) {
	ExpressionCache** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	g_return_if_fail (IS_MENU_MODEL (self));
	_tmp0_ = self->priv->caches;
	_tmp0__length1 = self->priv->caches_length1;
	{
		ExpressionCache** cache_collection = NULL;
		gint cache_collection_length1 = 0;
		gint _cache_collection_size_ = 0;
		gint cache_it = 0;
		cache_collection = _tmp0_;
		cache_collection_length1 = _tmp0__length1;
		for (cache_it = 0; cache_it < _tmp0__length1; cache_it = cache_it + 1) {
			ExpressionCache* _tmp1_ = NULL;
			ExpressionCache* cache = NULL;
			_tmp1_ = _g_object_ref0 (cache_collection[cache_it]);
			cache = _tmp1_;
			{
				ExpressionCache* _tmp2_ = NULL;
				_tmp2_ = cache;
				expression_cache_update (_tmp2_);
				_g_object_unref0 (cache);
			}
		}
	}
}


ExpressionCache* menu_model_expression (MenuModel* self, guint index) {
	ExpressionCache* result = NULL;
	guint _tmp0_ = 0U;
	ExpressionCache** _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	ExpressionCache** _tmp2_ = NULL;
	gint _tmp2__length1 = 0;
	guint _tmp3_ = 0U;
	ExpressionCache* _tmp4_ = NULL;
	ExpressionCache* _tmp5_ = NULL;
	g_return_val_if_fail (IS_MENU_MODEL (self), NULL);
	_tmp0_ = index;
	_tmp1_ = self->priv->caches;
	_tmp1__length1 = self->priv->caches_length1;
	g_return_val_if_fail (_tmp0_ < ((guint) _tmp1__length1), NULL);
	_tmp2_ = self->priv->caches;
	_tmp2__length1 = self->priv->caches_length1;
	_tmp3_ = index;
	_tmp4_ = _tmp2_[_tmp3_];
	_tmp5_ = _g_object_ref0 (_tmp4_);
	result = _tmp5_;
	return result;
}


gchar** menu_model_get_expressions (MenuModel* self, int* result_length1) {
	gchar** result;
	gchar** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gchar** _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	g_return_val_if_fail (IS_MENU_MODEL (self), NULL);
	_tmp0_ = self->priv->_expressions;
	_tmp0__length1 = self->priv->_expressions_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}


static gchar** _vala_array_dup20 (gchar** self, int length) {
	gchar** result;
	int i;
	result = g_new0 (gchar*, length + 1);
	for (i = 0; i < length; i++) {
		gchar* _tmp0_ = NULL;
		_tmp0_ = g_strdup (self[i]);
		result[i] = _tmp0_;
	}
	return result;
}


void menu_model_set_expressions (MenuModel* self, gchar** value, int value_length1) {
	gchar** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gchar** _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	g_return_if_fail (IS_MENU_MODEL (self));
	_tmp0_ = value;
	_tmp0__length1 = value_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup20 (_tmp0_, _tmp0__length1) : ((gpointer) _tmp0_);
	_tmp1__length1 = _tmp0__length1;
	self->priv->_expressions = (_vala_array_free (self->priv->_expressions, self->priv->_expressions_length1, (GDestroyNotify) g_free), NULL);
	self->priv->_expressions = _tmp1_;
	self->priv->_expressions_length1 = _tmp1__length1;
	self->priv->__expressions_size_ = self->priv->_expressions_length1;
	g_object_notify ((GObject *) self, "expressions");
}


static void _menu_model___lambda6_ (MenuModel* self) {
	gchar** _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	ExpressionCache** _tmp1_ = NULL;
	_tmp0_ = self->priv->_expressions;
	_tmp0__length1 = self->priv->_expressions_length1;
	_tmp1_ = g_new0 (ExpressionCache*, _tmp0__length1 + 1);
	self->priv->caches = (_vala_array_free (self->priv->caches, self->priv->caches_length1, (GDestroyNotify) g_object_unref), NULL);
	self->priv->caches = _tmp1_;
	self->priv->caches_length1 = _tmp0__length1;
	self->priv->_caches_size_ = self->priv->caches_length1;
	{
		guint i = 0U;
		guint isize = 0U;
		ExpressionCache** _tmp2_ = NULL;
		gint _tmp2__length1 = 0;
		i = (guint) 0;
		_tmp2_ = self->priv->caches;
		_tmp2__length1 = self->priv->caches_length1;
		isize = (guint) _tmp2__length1;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				gboolean _tmp4_ = FALSE;
				guint _tmp6_ = 0U;
				guint _tmp7_ = 0U;
				ExpressionCache** _tmp8_ = NULL;
				gint _tmp8__length1 = 0;
				guint _tmp9_ = 0U;
				Providers* _tmp10_ = NULL;
				gchar** _tmp11_ = NULL;
				gint _tmp11__length1 = 0;
				guint _tmp12_ = 0U;
				const gchar* _tmp13_ = NULL;
				ExpressionCache* _tmp14_ = NULL;
				ExpressionCache* _tmp15_ = NULL;
				_tmp4_ = _tmp3_;
				if (!_tmp4_) {
					guint _tmp5_ = 0U;
					_tmp5_ = i;
					i = _tmp5_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp6_ = i;
				_tmp7_ = isize;
				if (!(_tmp6_ < _tmp7_)) {
					break;
				}
				_tmp8_ = self->priv->caches;
				_tmp8__length1 = self->priv->caches_length1;
				_tmp9_ = i;
				_tmp10_ = self->priv->providers;
				_tmp11_ = self->priv->_expressions;
				_tmp11__length1 = self->priv->_expressions_length1;
				_tmp12_ = i;
				_tmp13_ = _tmp11_[_tmp12_];
				_tmp14_ = expression_cache_new (_tmp10_, _tmp13_);
				_g_object_unref0 (_tmp8_[_tmp9_]);
				_tmp8_[_tmp9_] = _tmp14_;
				_tmp15_ = _tmp8_[_tmp9_];
			}
		}
	}
}


static void __menu_model___lambda6__g_object_notify (GObject* _sender, GParamSpec* pspec, gpointer self) {
	_menu_model___lambda6_ (self);
}


static GObject * menu_model_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	MenuModel * self;
	parent_class = G_OBJECT_CLASS (menu_model_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MENU_MODEL, MenuModel);
	g_signal_connect_object (G_TYPE_CHECK_INSTANCE_CAST (self, G_TYPE_OBJECT, GObject), "notify::expressions", (GCallback) __menu_model___lambda6__g_object_notify, self, 0);
	return obj;
}


static void menu_model_class_init (MenuModelClass * klass) {
	menu_model_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (MenuModelPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_menu_model_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_menu_model_set_property;
	G_OBJECT_CLASS (klass)->constructor = menu_model_constructor;
	G_OBJECT_CLASS (klass)->finalize = menu_model_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), MENU_MODEL_EXPRESSIONS, g_param_spec_boxed ("expressions", "expressions", "expressions", G_TYPE_STRV, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void menu_model_instance_init (MenuModel * self) {
	self->priv = MENU_MODEL_GET_PRIVATE (self);
}


static void menu_model_finalize (GObject* obj) {
	MenuModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_MENU_MODEL, MenuModel);
	_g_object_unref0 (self->priv->providers);
	self->priv->caches = (_vala_array_free (self->priv->caches, self->priv->caches_length1, (GDestroyNotify) g_object_unref), NULL);
	self->priv->_expressions = (_vala_array_free (self->priv->_expressions, self->priv->_expressions_length1, (GDestroyNotify) g_free), NULL);
	G_OBJECT_CLASS (menu_model_parent_class)->finalize (obj);
}


/******************************************************************************
 * Copyright (C) 2011-2013  Michael Hofmann <mh21@mh21.de>                    *
 *                                                                            *
 * This program 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.                                        *
 *                                                                            *
 * This program 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 this program; if not, write to the Free Software Foundation, Inc.,    *
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.                *
 ******************************************************************************/
GType menu_model_get_type (void) {
	static volatile gsize menu_model_type_id__volatile = 0;
	if (g_once_init_enter (&menu_model_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (MenuModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) menu_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (MenuModel), 0, (GInstanceInitFunc) menu_model_instance_init, NULL };
		GType menu_model_type_id;
		menu_model_type_id = g_type_register_static (G_TYPE_OBJECT, "MenuModel", &g_define_type_info, 0);
		g_once_init_leave (&menu_model_type_id__volatile, menu_model_type_id);
	}
	return menu_model_type_id__volatile;
}


static void _vala_menu_model_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	MenuModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_MENU_MODEL, MenuModel);
	switch (property_id) {
		case MENU_MODEL_EXPRESSIONS:
		{
			int length;
			g_value_set_boxed (value, menu_model_get_expressions (self, &length));
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_menu_model_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	MenuModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_MENU_MODEL, MenuModel);
	switch (property_id) {
		case MENU_MODEL_EXPRESSIONS:
		{
			gpointer boxed;
			boxed = g_value_get_boxed (value);
			menu_model_set_expressions (self, boxed, g_strv_length (boxed));
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_array_destroy (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}



