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

/* SPDX-License-Identifier: GPL-3.0-or-later*/

#include "graphs.h"
#include <gio/gio.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <stdlib.h>
#include <string.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

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))

static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

GListModel*
graphs_get_mplstyle_file_filters (void)
{
	GtkFileFilter* filter = NULL;
	GtkFileFilter* _tmp0_;
	GListStore* _tmp1_;
	GListModel* result;
	_tmp0_ = graphs_tools_create_file_filter (C_ ("file-filter", "Matplotlib Style File"), "mplstyle", NULL);
	filter = _tmp0_;
	_tmp1_ = graphs_tools_create_file_filters (FALSE, filter, NULL);
	result = (GListModel*) _tmp1_;
	_g_object_unref0 (filter);
	return result;
}

gchar*
graphs_xposition_friendly_string (GraphsXPosition self)
{
	gchar* result;
	switch (self) {
		case GRAPHS_XPOSITION_BOTTOM:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("bottom");
			result = _tmp0_;
			return result;
		}
		case GRAPHS_XPOSITION_TOP:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("top");
			result = _tmp1_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

static GType
graphs_xposition_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_XPOSITION_BOTTOM, "GRAPHS_XPOSITION_BOTTOM", "bottom"}, {GRAPHS_XPOSITION_TOP, "GRAPHS_XPOSITION_TOP", "top"}, {0, NULL, NULL}};
	GType graphs_xposition_type_id;
	graphs_xposition_type_id = g_enum_register_static ("GraphsXPosition", values);
	return graphs_xposition_type_id;
}

GType
graphs_xposition_get_type (void)
{
	static volatile gsize graphs_xposition_type_id__once = 0;
	if (g_once_init_enter (&graphs_xposition_type_id__once)) {
		GType graphs_xposition_type_id;
		graphs_xposition_type_id = graphs_xposition_get_type_once ();
		g_once_init_leave (&graphs_xposition_type_id__once, graphs_xposition_type_id);
	}
	return graphs_xposition_type_id__once;
}

gchar*
graphs_yposition_friendly_string (GraphsYPosition self)
{
	gchar* result;
	switch (self) {
		case GRAPHS_YPOSITION_LEFT:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("left");
			result = _tmp0_;
			return result;
		}
		case GRAPHS_YPOSITION_RIGHT:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("right");
			result = _tmp1_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

static GType
graphs_yposition_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_YPOSITION_LEFT, "GRAPHS_YPOSITION_LEFT", "left"}, {GRAPHS_YPOSITION_RIGHT, "GRAPHS_YPOSITION_RIGHT", "right"}, {0, NULL, NULL}};
	GType graphs_yposition_type_id;
	graphs_yposition_type_id = g_enum_register_static ("GraphsYPosition", values);
	return graphs_yposition_type_id;
}

GType
graphs_yposition_get_type (void)
{
	static volatile gsize graphs_yposition_type_id__once = 0;
	if (g_once_init_enter (&graphs_yposition_type_id__once)) {
		GType graphs_yposition_type_id;
		graphs_yposition_type_id = graphs_yposition_get_type_once ();
		g_once_init_leave (&graphs_yposition_type_id__once, graphs_yposition_type_id);
	}
	return graphs_yposition_type_id__once;
}

GraphsScale
graphs_scale_from_string (const gchar* str)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	static GQuark _tmp1_label5 = 0;
	GraphsScale result;
	g_return_val_if_fail (str != NULL, 0);
	_tmp0_ = str;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("linear")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_SCALE_LINEAR;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("log")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_SCALE_LOG;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("log2")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_SCALE_LOG2;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("radians")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_SCALE_RADIANS;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("squareroot")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_SCALE_SQUAREROOT;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("inverse")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_SCALE_INVERSE;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				g_assert_not_reached ();
			}
		}
	}
}

static GType
graphs_scale_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_SCALE_LINEAR, "GRAPHS_SCALE_LINEAR", "linear"}, {GRAPHS_SCALE_LOG, "GRAPHS_SCALE_LOG", "log"}, {GRAPHS_SCALE_LOG2, "GRAPHS_SCALE_LOG2", "log2"}, {GRAPHS_SCALE_RADIANS, "GRAPHS_SCALE_RADIANS", "radians"}, {GRAPHS_SCALE_SQUAREROOT, "GRAPHS_SCALE_SQUAREROOT", "squareroot"}, {GRAPHS_SCALE_INVERSE, "GRAPHS_SCALE_INVERSE", "inverse"}, {0, NULL, NULL}};
	GType graphs_scale_type_id;
	graphs_scale_type_id = g_enum_register_static ("GraphsScale", values);
	return graphs_scale_type_id;
}

GType
graphs_scale_get_type (void)
{
	static volatile gsize graphs_scale_type_id__once = 0;
	if (g_once_init_enter (&graphs_scale_type_id__once)) {
		GType graphs_scale_type_id;
		graphs_scale_type_id = graphs_scale_get_type_once ();
		g_once_init_leave (&graphs_scale_type_id__once, graphs_scale_type_id);
	}
	return graphs_scale_type_id__once;
}

static gchar*
string_slice (const gchar* self,
              glong start,
              glong end)
{
	glong string_length = 0L;
	gint _tmp0_;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	gchar* _tmp4_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = strlen (self);
	_tmp1_ = _tmp0_;
	string_length = (glong) _tmp1_;
	if (start < ((glong) 0)) {
		start = string_length + start;
	}
	if (end < ((glong) 0)) {
		end = string_length + end;
	}
	if (start >= ((glong) 0)) {
		_tmp2_ = start <= string_length;
	} else {
		_tmp2_ = FALSE;
	}
	g_return_val_if_fail (_tmp2_, NULL);
	if (end >= ((glong) 0)) {
		_tmp3_ = end <= string_length;
	} else {
		_tmp3_ = FALSE;
	}
	g_return_val_if_fail (_tmp3_, NULL);
	g_return_val_if_fail (start <= end, NULL);
	_tmp4_ = g_strndup (((gchar*) self) + start, (gsize) (end - start));
	result = _tmp4_;
	return result;
}

gchar*
graphs_scale_to_string (GraphsScale scale)
{
	GEnumValue* _tmp0_;
	GEnumValue* _tmp1_;
	gint _tmp2_;
	gint _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	gchar* _tmp7_;
	gchar* result;
	_tmp0_ = g_enum_get_value (g_type_class_ref (GRAPHS_TYPE_SCALE), scale);
	_tmp1_ = g_enum_get_value (g_type_class_ref (GRAPHS_TYPE_SCALE), scale);
	_tmp2_ = strlen ((_tmp1_ != NULL) ? _tmp1_->value_name : NULL);
	_tmp3_ = _tmp2_;
	_tmp4_ = string_slice ((_tmp1_ != NULL) ? _tmp1_->value_name : NULL, (glong) 13, (glong) _tmp3_);
	_tmp5_ = _tmp4_;
	_tmp6_ = g_utf8_strdown (_tmp5_, (gssize) -1);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	result = _tmp7_;
	return result;
}

GraphsLegendPosition
graphs_legend_position_from_string (const gchar* str)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	static GQuark _tmp1_label4 = 0;
	static GQuark _tmp1_label5 = 0;
	static GQuark _tmp1_label6 = 0;
	static GQuark _tmp1_label7 = 0;
	static GQuark _tmp1_label8 = 0;
	static GQuark _tmp1_label9 = 0;
	GraphsLegendPosition result;
	g_return_val_if_fail (str != NULL, 0);
	_tmp0_ = str;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("best")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_BEST;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("upper right")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_UPPER_RIGHT;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("upper left")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_UPPER_LEFT;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("lower left")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_LOWER_LEFT;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label4) ? _tmp1_label4 : (_tmp1_label4 = g_quark_from_static_string ("lower right")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_LOWER_RIGHT;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label5) ? _tmp1_label5 : (_tmp1_label5 = g_quark_from_static_string ("center left")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_CENTER_LEFT;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label6) ? _tmp1_label6 : (_tmp1_label6 = g_quark_from_static_string ("center right")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_CENTER_RIGHT;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label7) ? _tmp1_label7 : (_tmp1_label7 = g_quark_from_static_string ("lower center")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_LOWER_CENTER;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label8) ? _tmp1_label8 : (_tmp1_label8 = g_quark_from_static_string ("upper center")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_UPPER_CENTER;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label9) ? _tmp1_label9 : (_tmp1_label9 = g_quark_from_static_string ("center")))) {
		switch (0) {
			default:
			{
				result = GRAPHS_LEGEND_POSITION_CENTER;
				return result;
			}
		}
	} else {
		switch (0) {
			default:
			{
				g_assert_not_reached ();
			}
		}
	}
}

gchar*
graphs_legend_position_friendly_string (GraphsLegendPosition self)
{
	gchar* result;
	switch (self) {
		case GRAPHS_LEGEND_POSITION_BEST:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("best");
			result = _tmp0_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_UPPER_RIGHT:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("upper right");
			result = _tmp1_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_UPPER_LEFT:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("upper left");
			result = _tmp2_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_LOWER_LEFT:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("lower left");
			result = _tmp3_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_LOWER_RIGHT:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("lower right");
			result = _tmp4_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_CENTER_LEFT:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup ("center left");
			result = _tmp5_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_CENTER_RIGHT:
		{
			gchar* _tmp6_;
			_tmp6_ = g_strdup ("center right");
			result = _tmp6_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_LOWER_CENTER:
		{
			gchar* _tmp7_;
			_tmp7_ = g_strdup ("lower center");
			result = _tmp7_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_UPPER_CENTER:
		{
			gchar* _tmp8_;
			_tmp8_ = g_strdup ("upper center");
			result = _tmp8_;
			return result;
		}
		case GRAPHS_LEGEND_POSITION_CENTER:
		{
			gchar* _tmp9_;
			_tmp9_ = g_strdup ("center");
			result = _tmp9_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

static GType
graphs_legend_position_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_LEGEND_POSITION_BEST, "GRAPHS_LEGEND_POSITION_BEST", "best"}, {GRAPHS_LEGEND_POSITION_UPPER_RIGHT, "GRAPHS_LEGEND_POSITION_UPPER_RIGHT", "upper-right"}, {GRAPHS_LEGEND_POSITION_UPPER_LEFT, "GRAPHS_LEGEND_POSITION_UPPER_LEFT", "upper-left"}, {GRAPHS_LEGEND_POSITION_LOWER_LEFT, "GRAPHS_LEGEND_POSITION_LOWER_LEFT", "lower-left"}, {GRAPHS_LEGEND_POSITION_LOWER_RIGHT, "GRAPHS_LEGEND_POSITION_LOWER_RIGHT", "lower-right"}, {GRAPHS_LEGEND_POSITION_CENTER_LEFT, "GRAPHS_LEGEND_POSITION_CENTER_LEFT", "center-left"}, {GRAPHS_LEGEND_POSITION_CENTER_RIGHT, "GRAPHS_LEGEND_POSITION_CENTER_RIGHT", "center-right"}, {GRAPHS_LEGEND_POSITION_LOWER_CENTER, "GRAPHS_LEGEND_POSITION_LOWER_CENTER", "lower-center"}, {GRAPHS_LEGEND_POSITION_UPPER_CENTER, "GRAPHS_LEGEND_POSITION_UPPER_CENTER", "upper-center"}, {GRAPHS_LEGEND_POSITION_CENTER, "GRAPHS_LEGEND_POSITION_CENTER", "center"}, {0, NULL, NULL}};
	GType graphs_legend_position_type_id;
	graphs_legend_position_type_id = g_enum_register_static ("GraphsLegendPosition", values);
	return graphs_legend_position_type_id;
}

GType
graphs_legend_position_get_type (void)
{
	static volatile gsize graphs_legend_position_type_id__once = 0;
	if (g_once_init_enter (&graphs_legend_position_type_id__once)) {
		GType graphs_legend_position_type_id;
		graphs_legend_position_type_id = graphs_legend_position_get_type_once ();
		g_once_init_leave (&graphs_legend_position_type_id__once, graphs_legend_position_type_id);
	}
	return graphs_legend_position_type_id__once;
}

gchar*
graphs_legend_position_to_string (GraphsLegendPosition pos)
{
	gchar* _tmp0_;
	gchar* result;
	_tmp0_ = graphs_legend_position_friendly_string (pos);
	result = _tmp0_;
	return result;
}

static GType
graphs_change_type_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_CHANGE_TYPE_ITEM_PROPERTY_CHANGED, "GRAPHS_CHANGE_TYPE_ITEM_PROPERTY_CHANGED", "item-property-changed"}, {GRAPHS_CHANGE_TYPE_ITEM_ADDED, "GRAPHS_CHANGE_TYPE_ITEM_ADDED", "item-added"}, {GRAPHS_CHANGE_TYPE_ITEM_REMOVED, "GRAPHS_CHANGE_TYPE_ITEM_REMOVED", "item-removed"}, {GRAPHS_CHANGE_TYPE_ITEMS_SWAPPED, "GRAPHS_CHANGE_TYPE_ITEMS_SWAPPED", "items-swapped"}, {GRAPHS_CHANGE_TYPE_FIGURE_SETTINGS_CHANGED, "GRAPHS_CHANGE_TYPE_FIGURE_SETTINGS_CHANGED", "figure-settings-changed"}, {0, NULL, NULL}};
	GType graphs_change_type_type_id;
	graphs_change_type_type_id = g_enum_register_static ("GraphsChangeType", values);
	return graphs_change_type_type_id;
}

GType
graphs_change_type_get_type (void)
{
	static volatile gsize graphs_change_type_type_id__once = 0;
	if (g_once_init_enter (&graphs_change_type_type_id__once)) {
		GType graphs_change_type_type_id;
		graphs_change_type_type_id = graphs_change_type_get_type_once ();
		g_once_init_leave (&graphs_change_type_type_id__once, graphs_change_type_type_id);
	}
	return graphs_change_type_type_id__once;
}

static GType
graphs_mode_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_MODE_PAN, "GRAPHS_MODE_PAN", "pan"}, {GRAPHS_MODE_ZOOM, "GRAPHS_MODE_ZOOM", "zoom"}, {GRAPHS_MODE_SELECT, "GRAPHS_MODE_SELECT", "select"}, {0, NULL, NULL}};
	GType graphs_mode_type_id;
	graphs_mode_type_id = g_enum_register_static ("GraphsMode", values);
	return graphs_mode_type_id;
}

GType
graphs_mode_get_type (void)
{
	static volatile gsize graphs_mode_type_id__once = 0;
	if (g_once_init_enter (&graphs_mode_type_id__once)) {
		GType graphs_mode_type_id;
		graphs_mode_type_id = graphs_mode_get_type_once ();
		g_once_init_leave (&graphs_mode_type_id__once, graphs_mode_type_id);
	}
	return graphs_mode_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

