/* 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 "valadoc.h"
#include <gvc.h>
#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.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_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 GType valadoc_charts_chart_get_type_once (void);

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;
	Agraph_t* _tmp0_;
	ValadocChartsFactory* _tmp1_;
	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_ = valadoc_charts_factory_create_graph (factory, node);
	_agclose0 (self->graph);
	self->graph = _tmp0_;
	_tmp1_ = _g_object_ref0 (factory);
	_g_object_unref0 (self->factory);
	self->factory = _tmp1_;
	valadoc_api_node_accept (node, (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_;
	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;
	gvRenderFilename (_tmp4_, _tmp5_, (char*) file_type, (char*) file_name);
}

void
valadoc_charts_chart_write (ValadocChartsChart* self,
                            FILE* file,
                            const gchar* file_type)
{
	GVC_t* _tmp0_;
	GVC_t* _tmp4_;
	Agraph_t* _tmp5_;
	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;
	gvRender (_tmp4_, _tmp5_, (char*) file_type, file);
}

guint8*
valadoc_charts_chart_write_buffer (ValadocChartsChart* self,
                                   const gchar* file_type,
                                   gint* result_length1)
{
	GVC_t* _tmp0_;
	guint8* data = NULL;
	gint data_length1 = 0;
	gint _data_size_ = 0;
	GVC_t* _tmp4_;
	Agraph_t* _tmp5_;
	guint8* _tmp6_ = NULL;
	unsigned int _tmp7_ = 0;
	guint8* _tmp8_;
	gint _tmp8__length1;
	guint8* result;
	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;
	gvRenderData (_tmp4_, _tmp5_, (char*) file_type, (char**) (&_tmp6_), &_tmp7_);
	data = (g_free (data), NULL);
	data = _tmp6_;
	data_length1 = _tmp7_;
	_data_size_ = data_length1;
	_tmp8_ = data;
	_tmp8__length1 = data_length1;
	if (result_length1) {
		*result_length1 = _tmp8__length1;
	}
	result = _tmp8_;
	return result;
}

static void
valadoc_charts_chart_class_init (ValadocChartsChartClass * klass,
                                 gpointer klass_data)
{
	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,
                                    gpointer klass)
{
}

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);
}

static GType
valadoc_charts_chart_get_type_once (void)
{
	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);
	return valadoc_charts_chart_type_id;
}

GType
valadoc_charts_chart_get_type (void)
{
	static volatile gsize valadoc_charts_chart_type_id__once = 0;
	if (g_once_init_enter (&valadoc_charts_chart_type_id__once)) {
		GType valadoc_charts_chart_type_id;
		valadoc_charts_chart_type_id = valadoc_charts_chart_get_type_once ();
		g_once_init_leave (&valadoc_charts_chart_type_id__once, valadoc_charts_chart_type_id);
	}
	return valadoc_charts_chart_type_id__once;
}

