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

/* chart.vala
 *
 * Copyright (C) 2008  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 <glib.h>
#include <glib-object.h>
#include "valadoc.h"
#include <graphviz/gvc.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

enum  {
	VALADOC_CHARTS_CHART_0_PROPERTY,
	VALADOC_CHARTS_CHART_NUM_PROPERTIES
};
static GParamSpec* valadoc_charts_chart_properties[VALADOC_CHARTS_CHART_NUM_PROPERTIES];
#define _gvFreeContext0(var) ((var == NULL) ? NULL : (var = (gvFreeContext (var), NULL)))
#define _agclose0(var) ((var == NULL) ? NULL : (var = (agclose (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))


static gpointer valadoc_charts_chart_parent_class = NULL;

void valadoc_compat_gvc_init (void);
static void valadoc_charts_chart_finalize (GObject * obj);


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


ValadocChartsChart* valadoc_charts_chart_construct (GType object_type, ValadocChartsFactory* factory, ValadocApiNode* node) {
	ValadocChartsChart * self = NULL;
	ValadocChartsFactory* _tmp0_;
	ValadocApiNode* _tmp1_;
	Agraph_t* _tmp2_;
	ValadocChartsFactory* _tmp3_;
	ValadocChartsFactory* _tmp4_;
	ValadocApiNode* _tmp5_;
	g_return_val_if_fail (factory != NULL, NULL);
	g_return_val_if_fail (node != NULL, NULL);
	self = (ValadocChartsChart*) valadoc_api_visitor_construct (object_type);
	_tmp0_ = factory;
	_tmp1_ = node;
	_tmp2_ = valadoc_charts_factory_create_graph (_tmp0_, _tmp1_);
	_agclose0 (self->graph);
	self->graph = _tmp2_;
	_tmp3_ = factory;
	_tmp4_ = _g_object_ref0 (_tmp3_);
	_g_object_unref0 (self->factory);
	self->factory = _tmp4_;
	_tmp5_ = node;
	valadoc_api_node_accept (_tmp5_, (ValadocApiVisitor*) self);
	return self;
}


ValadocChartsChart* valadoc_charts_chart_new (ValadocChartsFactory* factory, ValadocApiNode* node) {
	return valadoc_charts_chart_construct (VALADOC_CHARTS_TYPE_CHART, factory, node);
}


void valadoc_charts_chart_save (ValadocChartsChart* self, const gchar* file_name, const gchar* file_type) {
	GVC_t* _tmp0_;
	GVC_t* _tmp4_;
	Agraph_t* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file_name != NULL);
	g_return_if_fail (file_type != NULL);
	_tmp0_ = self->context;
	if (_tmp0_ == NULL) {
		ValadocChartsFactory* _tmp1_;
		Agraph_t* _tmp2_;
		GVC_t* _tmp3_;
		_tmp1_ = self->factory;
		_tmp2_ = self->graph;
		_tmp3_ = valadoc_charts_factory_create_context (_tmp1_, _tmp2_);
		_gvFreeContext0 (self->context);
		self->context = _tmp3_;
	}
	_tmp4_ = self->context;
	_tmp5_ = self->graph;
	_tmp6_ = file_type;
	_tmp7_ = file_name;
	gvRenderFilename (_tmp4_, _tmp5_, (char*) _tmp6_, (char*) _tmp7_);
}


void valadoc_charts_chart_write (ValadocChartsChart* self, FILE* file, const gchar* file_type) {
	GVC_t* _tmp0_;
	GVC_t* _tmp4_;
	Agraph_t* _tmp5_;
	const gchar* _tmp6_;
	FILE* _tmp7_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (file != NULL);
	g_return_if_fail (file_type != NULL);
	_tmp0_ = self->context;
	if (_tmp0_ == NULL) {
		ValadocChartsFactory* _tmp1_;
		Agraph_t* _tmp2_;
		GVC_t* _tmp3_;
		_tmp1_ = self->factory;
		_tmp2_ = self->graph;
		_tmp3_ = valadoc_charts_factory_create_context (_tmp1_, _tmp2_);
		_gvFreeContext0 (self->context);
		self->context = _tmp3_;
	}
	_tmp4_ = self->context;
	_tmp5_ = self->graph;
	_tmp6_ = file_type;
	_tmp7_ = file;
	gvRender (_tmp4_, _tmp5_, (char*) _tmp6_, _tmp7_);
}


guint8* valadoc_charts_chart_write_buffer (ValadocChartsChart* self, const gchar* file_type, int* result_length1) {
	guint8* result = NULL;
	GVC_t* _tmp0_;
	guint8* data = NULL;
	gint data_length1 = 0;
	gint _data_size_ = 0;
	GVC_t* _tmp4_;
	Agraph_t* _tmp5_;
	const gchar* _tmp6_;
	guint8* _tmp7_ = NULL;
	gint _tmp8_;
	guint8* _tmp9_;
	gint _tmp9__length1;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (file_type != NULL, NULL);
	_tmp0_ = self->context;
	if (_tmp0_ == NULL) {
		ValadocChartsFactory* _tmp1_;
		Agraph_t* _tmp2_;
		GVC_t* _tmp3_;
		_tmp1_ = self->factory;
		_tmp2_ = self->graph;
		_tmp3_ = valadoc_charts_factory_create_context (_tmp1_, _tmp2_);
		_gvFreeContext0 (self->context);
		self->context = _tmp3_;
	}
	_tmp4_ = self->context;
	_tmp5_ = self->graph;
	_tmp6_ = file_type;
	gvRenderData (_tmp4_, _tmp5_, (char*) _tmp6_, (char**) (&_tmp7_), &_tmp8_);
	data = (g_free (data), NULL);
	data = _tmp7_;
	data_length1 = _tmp8_;
	_data_size_ = data_length1;
	_tmp9_ = data;
	_tmp9__length1 = data_length1;
	if (result_length1) {
		*result_length1 = _tmp9__length1;
	}
	result = _tmp9_;
	return result;
}


static void valadoc_charts_chart_class_init (ValadocChartsChartClass * klass) {
	valadoc_charts_chart_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = valadoc_charts_chart_finalize;
	valadoc_compat_gvc_init ();
}


static void valadoc_charts_chart_instance_init (ValadocChartsChart * self) {
}


static void valadoc_charts_chart_finalize (GObject * obj) {
	ValadocChartsChart * self;
	GVC_t* _tmp0_;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALADOC_CHARTS_TYPE_CHART, ValadocChartsChart);
	_tmp0_ = self->context;
	if (_tmp0_ != NULL) {
		GVC_t* _tmp1_;
		Agraph_t* _tmp2_;
		_tmp1_ = self->context;
		_tmp2_ = self->graph;
		gvFreeLayout (_tmp1_, _tmp2_);
	}
	_gvFreeContext0 (self->context);
	_agclose0 (self->graph);
	_g_object_unref0 (self->factory);
	G_OBJECT_CLASS (valadoc_charts_chart_parent_class)->finalize (obj);
}


GType valadoc_charts_chart_get_type (void) {
	static volatile gsize valadoc_charts_chart_type_id__volatile = 0;
	if (g_once_init_enter (&valadoc_charts_chart_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ValadocChartsChartClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) valadoc_charts_chart_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValadocChartsChart), 0, (GInstanceInitFunc) valadoc_charts_chart_instance_init, NULL };
		GType valadoc_charts_chart_type_id;
		valadoc_charts_chart_type_id = g_type_register_static (VALADOC_API_TYPE_VISITOR, "ValadocChartsChart", &g_define_type_info, 0);
		g_once_init_leave (&valadoc_charts_chart_type_id__volatile, valadoc_charts_chart_type_id);
	}
	return valadoc_charts_chart_type_id__volatile;
}



