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


#include <glib.h>
#include <glib-object.h>
#include <gdk/gdk.h>
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>


#define TYPE_TRACE_MODEL (trace_model_get_type ())
#define TRACE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TRACE_MODEL, TraceModel))
#define TRACE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TRACE_MODEL, TraceModelClass))
#define IS_TRACE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TRACE_MODEL))
#define IS_TRACE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TRACE_MODEL))
#define TRACE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TRACE_MODEL, TraceModelClass))

typedef struct _TraceModel TraceModel;
typedef struct _TraceModelClass TraceModelClass;
typedef struct _TraceModelPrivate TraceModelPrivate;

#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)))

#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;

struct _TraceModel {
	GObject parent_instance;
	TraceModelPrivate * priv;
};

struct _TraceModelClass {
	GObjectClass parent_class;
};

struct _TraceModelPrivate {
	ExpressionCache* _expression;
	GdkRGBA _rgba;
	gboolean _enabled;
	gdouble* _values;
	gint _values_length1;
	gint __values_size_;
};


static gpointer trace_model_parent_class = NULL;

GType trace_model_get_type (void) G_GNUC_CONST;
GType expression_cache_get_type (void) G_GNUC_CONST;
#define TRACE_MODEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_TRACE_MODEL, TraceModelPrivate))
enum  {
	TRACE_MODEL_DUMMY_PROPERTY,
	TRACE_MODEL_EXPRESSION,
	TRACE_MODEL_RGBA,
	TRACE_MODEL_ENABLED
};
GType providers_get_type (void) G_GNUC_CONST;
TraceModel* trace_model_new (Providers* providers);
TraceModel* trace_model_construct (GType object_type, Providers* providers);
ExpressionCache* expression_cache_new (Providers* providers, const gchar* expression);
ExpressionCache* expression_cache_construct (GType object_type, Providers* providers, const gchar* expression);
void trace_model_set_values_length (TraceModel* self, guint length);
static gdouble* _vala_array_dup28 (gdouble* self, int length);
static gdouble* _vala_array_dup29 (gdouble* self, int length);
void trace_model_add_value (TraceModel* self, gdouble value);
ExpressionCache* trace_model_get_expression (TraceModel* self);
static void trace_model_set_expression (TraceModel* self, ExpressionCache* value);
void trace_model_get_rgba (TraceModel* self, GdkRGBA* result);
void trace_model_set_rgba (TraceModel* self, GdkRGBA* value);
gboolean trace_model_get_enabled (TraceModel* self);
void trace_model_set_enabled (TraceModel* self, gboolean value);
gdouble* trace_model_get_values (TraceModel* self, int* result_length1);
static void trace_model_set_values (TraceModel* self, gdouble* value, int value_length1);
static gdouble* _vala_array_dup30 (gdouble* self, int length);
static void trace_model_finalize (GObject* obj);
static void _vala_trace_model_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_trace_model_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);


TraceModel* trace_model_construct (GType object_type, Providers* providers) {
	TraceModel * self = NULL;
	Providers* _tmp0_ = NULL;
	ExpressionCache* _tmp1_ = NULL;
	ExpressionCache* _tmp2_ = NULL;
	g_return_val_if_fail (IS_PROVIDERS (providers), NULL);
	_tmp0_ = providers;
	_tmp1_ = expression_cache_new (_tmp0_, "");
	_tmp2_ = _tmp1_;
	self = (TraceModel*) g_object_new (object_type, "expression", _tmp2_, NULL);
	_g_object_unref0 (_tmp2_);
	return self;
}


TraceModel* trace_model_new (Providers* providers) {
	return trace_model_construct (TYPE_TRACE_MODEL, providers);
}


static gdouble* _vala_array_dup28 (gdouble* self, int length) {
	return g_memdup (self, length * sizeof (gdouble));
}


static gdouble* _vala_array_dup29 (gdouble* self, int length) {
	return g_memdup (self, length * sizeof (gdouble));
}


void trace_model_set_values_length (TraceModel* self, guint length) {
	guint _tmp0_ = 0U;
	gdouble* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	g_return_if_fail (IS_TRACE_MODEL (self));
	_tmp0_ = length;
	_tmp1_ = self->priv->_values;
	_tmp1__length1 = self->priv->_values_length1;
	if (_tmp0_ > ((guint) _tmp1__length1)) {
		gdouble* newvalues = NULL;
		guint _tmp2_ = 0U;
		gdouble* _tmp3_ = NULL;
		gint newvalues_length1 = 0;
		gint _newvalues_size_ = 0;
		guint offset = 0U;
		guint _tmp4_ = 0U;
		gdouble* _tmp5_ = NULL;
		gint _tmp5__length1 = 0;
		gdouble* _tmp19_ = NULL;
		gint _tmp19__length1 = 0;
		gdouble* _tmp20_ = NULL;
		gint _tmp20__length1 = 0;
		_tmp2_ = length;
		_tmp3_ = g_new0 (gdouble, _tmp2_);
		newvalues = _tmp3_;
		newvalues_length1 = _tmp2_;
		_newvalues_size_ = newvalues_length1;
		_tmp4_ = length;
		_tmp5_ = self->priv->_values;
		_tmp5__length1 = self->priv->_values_length1;
		offset = _tmp4_ - _tmp5__length1;
		{
			guint i = 0U;
			guint isize = 0U;
			gdouble* _tmp6_ = NULL;
			gint _tmp6__length1 = 0;
			i = (guint) 0;
			_tmp6_ = self->priv->_values;
			_tmp6__length1 = self->priv->_values_length1;
			isize = (guint) _tmp6__length1;
			{
				gboolean _tmp7_ = FALSE;
				_tmp7_ = TRUE;
				while (TRUE) {
					gboolean _tmp8_ = FALSE;
					guint _tmp10_ = 0U;
					guint _tmp11_ = 0U;
					gdouble* _tmp12_ = NULL;
					gint _tmp12__length1 = 0;
					guint _tmp13_ = 0U;
					guint _tmp14_ = 0U;
					gdouble* _tmp15_ = NULL;
					gint _tmp15__length1 = 0;
					guint _tmp16_ = 0U;
					gdouble _tmp17_ = 0.0;
					gdouble _tmp18_ = 0.0;
					_tmp8_ = _tmp7_;
					if (!_tmp8_) {
						guint _tmp9_ = 0U;
						_tmp9_ = i;
						i = _tmp9_ + 1;
					}
					_tmp7_ = FALSE;
					_tmp10_ = i;
					_tmp11_ = isize;
					if (!(_tmp10_ < _tmp11_)) {
						break;
					}
					_tmp12_ = newvalues;
					_tmp12__length1 = newvalues_length1;
					_tmp13_ = offset;
					_tmp14_ = i;
					_tmp15_ = self->priv->_values;
					_tmp15__length1 = self->priv->_values_length1;
					_tmp16_ = i;
					_tmp17_ = _tmp15_[_tmp16_];
					_tmp12_[_tmp13_ + _tmp14_] = _tmp17_;
					_tmp18_ = _tmp12_[_tmp13_ + _tmp14_];
				}
			}
		}
		_tmp19_ = newvalues;
		_tmp19__length1 = newvalues_length1;
		_tmp20_ = (_tmp19_ != NULL) ? _vala_array_dup28 (_tmp19_, _tmp19__length1) : ((gpointer) _tmp19_);
		_tmp20__length1 = _tmp19__length1;
		self->priv->_values = (g_free (self->priv->_values), NULL);
		self->priv->_values = _tmp20_;
		self->priv->_values_length1 = _tmp20__length1;
		self->priv->__values_size_ = self->priv->_values_length1;
		newvalues = (g_free (newvalues), NULL);
	} else {
		guint _tmp21_ = 0U;
		gdouble* _tmp22_ = NULL;
		gint _tmp22__length1 = 0;
		_tmp21_ = length;
		_tmp22_ = self->priv->_values;
		_tmp22__length1 = self->priv->_values_length1;
		if (_tmp21_ < ((guint) _tmp22__length1)) {
			gdouble* _tmp23_ = NULL;
			gint _tmp23__length1 = 0;
			gdouble* _tmp24_ = NULL;
			gint _tmp24__length1 = 0;
			guint _tmp25_ = 0U;
			gdouble* _tmp26_ = NULL;
			gint _tmp26__length1 = 0;
			gdouble* _tmp27_ = NULL;
			gint _tmp27__length1 = 0;
			_tmp23_ = self->priv->_values;
			_tmp23__length1 = self->priv->_values_length1;
			_tmp24_ = self->priv->_values;
			_tmp24__length1 = self->priv->_values_length1;
			_tmp25_ = length;
			_tmp26_ = self->priv->_values;
			_tmp26__length1 = self->priv->_values_length1;
			_tmp27_ = ((_tmp23_ + ((gint) (_tmp24__length1 - _tmp25_))) != NULL) ? _vala_array_dup29 (_tmp23_ + ((gint) (_tmp24__length1 - _tmp25_)), _tmp26__length1 - ((gint) (_tmp24__length1 - _tmp25_))) : ((gpointer) (_tmp23_ + ((gint) (_tmp24__length1 - _tmp25_))));
			_tmp27__length1 = _tmp26__length1 - ((gint) (_tmp24__length1 - _tmp25_));
			self->priv->_values = (g_free (self->priv->_values), NULL);
			self->priv->_values = _tmp27_;
			self->priv->_values_length1 = _tmp27__length1;
			self->priv->__values_size_ = self->priv->_values_length1;
		}
	}
}


void trace_model_add_value (TraceModel* self, gdouble value) {
	gdouble* _tmp12_ = NULL;
	gint _tmp12__length1 = 0;
	gdouble* _tmp13_ = NULL;
	gint _tmp13__length1 = 0;
	gdouble _tmp14_ = 0.0;
	gdouble _tmp15_ = 0.0;
	g_return_if_fail (IS_TRACE_MODEL (self));
	{
		guint i = 0U;
		guint isize = 0U;
		gdouble* _tmp0_ = NULL;
		gint _tmp0__length1 = 0;
		i = (guint) 0;
		_tmp0_ = self->priv->_values;
		_tmp0__length1 = self->priv->_values_length1;
		isize = (guint) _tmp0__length1;
		{
			gboolean _tmp1_ = FALSE;
			_tmp1_ = TRUE;
			while (TRUE) {
				gboolean _tmp2_ = FALSE;
				guint _tmp4_ = 0U;
				guint _tmp5_ = 0U;
				gdouble* _tmp6_ = NULL;
				gint _tmp6__length1 = 0;
				guint _tmp7_ = 0U;
				gdouble* _tmp8_ = NULL;
				gint _tmp8__length1 = 0;
				guint _tmp9_ = 0U;
				gdouble _tmp10_ = 0.0;
				gdouble _tmp11_ = 0.0;
				_tmp2_ = _tmp1_;
				if (!_tmp2_) {
					guint _tmp3_ = 0U;
					_tmp3_ = i;
					i = _tmp3_ + 1;
				}
				_tmp1_ = FALSE;
				_tmp4_ = i;
				_tmp5_ = isize;
				if (!((_tmp4_ + 1) < _tmp5_)) {
					break;
				}
				_tmp6_ = self->priv->_values;
				_tmp6__length1 = self->priv->_values_length1;
				_tmp7_ = i;
				_tmp8_ = self->priv->_values;
				_tmp8__length1 = self->priv->_values_length1;
				_tmp9_ = i;
				_tmp10_ = _tmp8_[_tmp9_ + 1];
				_tmp6_[_tmp7_] = _tmp10_;
				_tmp11_ = _tmp6_[_tmp7_];
			}
		}
	}
	_tmp12_ = self->priv->_values;
	_tmp12__length1 = self->priv->_values_length1;
	_tmp13_ = self->priv->_values;
	_tmp13__length1 = self->priv->_values_length1;
	_tmp14_ = value;
	_tmp12_[_tmp13__length1 - 1] = _tmp14_;
	_tmp15_ = _tmp12_[_tmp13__length1 - 1];
}


ExpressionCache* trace_model_get_expression (TraceModel* self) {
	ExpressionCache* result;
	ExpressionCache* _tmp0_ = NULL;
	g_return_val_if_fail (IS_TRACE_MODEL (self), NULL);
	_tmp0_ = self->priv->_expression;
	result = _tmp0_;
	return result;
}


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


static void trace_model_set_expression (TraceModel* self, ExpressionCache* value) {
	ExpressionCache* _tmp0_ = NULL;
	ExpressionCache* _tmp1_ = NULL;
	g_return_if_fail (IS_TRACE_MODEL (self));
	_tmp0_ = value;
	_tmp1_ = _g_object_ref0 (_tmp0_);
	_g_object_unref0 (self->priv->_expression);
	self->priv->_expression = _tmp1_;
	g_object_notify ((GObject *) self, "expression");
}


void trace_model_get_rgba (TraceModel* self, GdkRGBA* result) {
	GdkRGBA _tmp0_ = {0};
	g_return_if_fail (IS_TRACE_MODEL (self));
	_tmp0_ = self->priv->_rgba;
	*result = _tmp0_;
	return;
}


void trace_model_set_rgba (TraceModel* self, GdkRGBA* value) {
	GdkRGBA _tmp0_ = {0};
	g_return_if_fail (IS_TRACE_MODEL (self));
	_tmp0_ = *value;
	self->priv->_rgba = _tmp0_;
	g_object_notify ((GObject *) self, "rgba");
}


gboolean trace_model_get_enabled (TraceModel* self) {
	gboolean result;
	gboolean _tmp0_ = FALSE;
	g_return_val_if_fail (IS_TRACE_MODEL (self), FALSE);
	_tmp0_ = self->priv->_enabled;
	result = _tmp0_;
	return result;
}


void trace_model_set_enabled (TraceModel* self, gboolean value) {
	gboolean _tmp0_ = FALSE;
	g_return_if_fail (IS_TRACE_MODEL (self));
	_tmp0_ = value;
	self->priv->_enabled = _tmp0_;
	g_object_notify ((GObject *) self, "enabled");
}


gdouble* trace_model_get_values (TraceModel* self, int* result_length1) {
	gdouble* result;
	gdouble* _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gdouble* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	g_return_val_if_fail (IS_TRACE_MODEL (self), NULL);
	_tmp0_ = self->priv->_values;
	_tmp0__length1 = self->priv->_values_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}


static gdouble* _vala_array_dup30 (gdouble* self, int length) {
	return g_memdup (self, length * sizeof (gdouble));
}


static void trace_model_set_values (TraceModel* self, gdouble* value, int value_length1) {
	gdouble* _tmp0_ = NULL;
	gint _tmp0__length1 = 0;
	gdouble* _tmp1_ = NULL;
	gint _tmp1__length1 = 0;
	g_return_if_fail (IS_TRACE_MODEL (self));
	_tmp0_ = value;
	_tmp0__length1 = value_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup30 (_tmp0_, _tmp0__length1) : ((gpointer) _tmp0_);
	_tmp1__length1 = _tmp0__length1;
	self->priv->_values = (g_free (self->priv->_values), NULL);
	self->priv->_values = _tmp1_;
	self->priv->_values_length1 = _tmp1__length1;
	self->priv->__values_size_ = self->priv->_values_length1;
}


static void trace_model_class_init (TraceModelClass * klass) {
	trace_model_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (TraceModelPrivate));
	G_OBJECT_CLASS (klass)->get_property = _vala_trace_model_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_trace_model_set_property;
	G_OBJECT_CLASS (klass)->finalize = trace_model_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), TRACE_MODEL_EXPRESSION, g_param_spec_object ("expression", "expression", "expression", TYPE_EXPRESSION_CACHE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TRACE_MODEL_RGBA, g_param_spec_boxed ("rgba", "rgba", "rgba", gdk_rgba_get_type (), G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), TRACE_MODEL_ENABLED, g_param_spec_boolean ("enabled", "enabled", "enabled", FALSE, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}


static void trace_model_instance_init (TraceModel * self) {
	self->priv = TRACE_MODEL_GET_PRIVATE (self);
}


static void trace_model_finalize (GObject* obj) {
	TraceModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_TRACE_MODEL, TraceModel);
	_g_object_unref0 (self->priv->_expression);
	self->priv->_values = (g_free (self->priv->_values), NULL);
	G_OBJECT_CLASS (trace_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 trace_model_get_type (void) {
	static volatile gsize trace_model_type_id__volatile = 0;
	if (g_once_init_enter (&trace_model_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (TraceModelClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) trace_model_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (TraceModel), 0, (GInstanceInitFunc) trace_model_instance_init, NULL };
		GType trace_model_type_id;
		trace_model_type_id = g_type_register_static (G_TYPE_OBJECT, "TraceModel", &g_define_type_info, 0);
		g_once_init_leave (&trace_model_type_id__volatile, trace_model_type_id);
	}
	return trace_model_type_id__volatile;
}


static void _vala_trace_model_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
	TraceModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TRACE_MODEL, TraceModel);
	switch (property_id) {
		case TRACE_MODEL_EXPRESSION:
		g_value_set_object (value, trace_model_get_expression (self));
		break;
		case TRACE_MODEL_RGBA:
		{
			GdkRGBA boxed;
			trace_model_get_rgba (self, &boxed);
			g_value_set_boxed (value, &boxed);
		}
		break;
		case TRACE_MODEL_ENABLED:
		g_value_set_boolean (value, trace_model_get_enabled (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}


static void _vala_trace_model_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
	TraceModel * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, TYPE_TRACE_MODEL, TraceModel);
	switch (property_id) {
		case TRACE_MODEL_EXPRESSION:
		trace_model_set_expression (self, g_value_get_object (value));
		break;
		case TRACE_MODEL_RGBA:
		trace_model_set_rgba (self, g_value_get_boxed (value));
		break;
		case TRACE_MODEL_ENABLED:
		trace_model_set_enabled (self, g_value_get_boolean (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}



