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

/*
* Copyright (c) 2025-2026 (https://github.com/phase1geo/Minder)
*
* 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 2 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
*
* Authored by: Trevor Williams <phase1geo@gmail.com>
*/

#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <libxml/tree.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
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_TEMPLATE (template_get_type ())
#define TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TEMPLATE, Template))
#define TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TEMPLATE, TemplateClass))
#define IS_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TEMPLATE))
#define IS_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TEMPLATE))
#define TEMPLATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TEMPLATE, TemplateClass))

typedef struct _Template Template;
typedef struct _TemplateClass TemplateClass;
typedef struct _TemplatePrivate TemplatePrivate;

#define TYPE_STYLE_TEMPLATE (style_template_get_type ())
#define STYLE_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_STYLE_TEMPLATE, StyleTemplate))
#define STYLE_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_STYLE_TEMPLATE, StyleTemplateClass))
#define IS_STYLE_TEMPLATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_STYLE_TEMPLATE))
#define IS_STYLE_TEMPLATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_STYLE_TEMPLATE))
#define STYLE_TEMPLATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_STYLE_TEMPLATE, StyleTemplateClass))

typedef struct _StyleTemplate StyleTemplate;
typedef struct _StyleTemplateClass StyleTemplateClass;
typedef struct _StyleTemplatePrivate StyleTemplatePrivate;

#define TYPE_STYLE (style_get_type ())
#define STYLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_STYLE, Style))
#define STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_STYLE, StyleClass))
#define IS_STYLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_STYLE))
#define IS_STYLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_STYLE))
#define STYLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_STYLE, StyleClass))

typedef struct _Style Style;
typedef struct _StyleClass StyleClass;
#define _style_unref0(var) ((var == NULL) ? NULL : (var = (style_unref (var), NULL)))
typedef enum  {
	TEMPLATE_TYPE_STYLE_GENERAL,
	TEMPLATE_TYPE_STYLE_NODE,
	TEMPLATE_TYPE_STYLE_CONNECTION,
	TEMPLATE_TYPE_STYLE_CALLOUT,
	TEMPLATE_TYPE_STYLE_OPTION_BRANCH,
	TEMPLATE_TYPE_STYLE_OPTION_LINK,
	TEMPLATE_TYPE_STYLE_OPTION_NODE,
	TEMPLATE_TYPE_STYLE_OPTION_CONNECTION,
	TEMPLATE_TYPE_STYLE_OPTION_CALLOUT,
	TEMPLATE_TYPE_NUM
} TemplateType;

#define TYPE_TEMPLATE_TYPE (template_type_get_type ())

struct _Template {
	GTypeInstance parent_instance;
	volatile int ref_count;
	TemplatePrivate * priv;
};

struct _TemplateClass {
	GTypeClass parent_class;
	void (*finalize) (Template *self);
	xmlNode* (*save) (Template* self, const gchar* node_name);
	void (*load) (Template* self, xmlNode* node);
};

struct _StyleTemplate {
	Template parent_instance;
	StyleTemplatePrivate * priv;
};

struct _StyleTemplateClass {
	TemplateClass parent_class;
};

struct _StyleTemplatePrivate {
	Style* _style;
};

static gint StyleTemplate_private_offset;
static gpointer style_template_parent_class = NULL;

VALA_EXTERN gpointer template_ref (gpointer instance);
VALA_EXTERN void template_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_template (const gchar* name,
                                 const gchar* nick,
                                 const gchar* blurb,
                                 GType object_type,
                                 GParamFlags flags);
VALA_EXTERN void value_set_template (GValue* value,
                         gpointer v_object);
VALA_EXTERN void value_take_template (GValue* value,
                          gpointer v_object);
VALA_EXTERN gpointer value_get_template (const GValue* value);
VALA_EXTERN GType template_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Template, template_unref)
VALA_EXTERN GType style_template_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (StyleTemplate, template_unref)
VALA_EXTERN gpointer style_ref (gpointer instance);
VALA_EXTERN void style_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_style (const gchar* name,
                              const gchar* nick,
                              const gchar* blurb,
                              GType object_type,
                              GParamFlags flags);
VALA_EXTERN void value_set_style (GValue* value,
                      gpointer v_object);
VALA_EXTERN void value_take_style (GValue* value,
                       gpointer v_object);
VALA_EXTERN gpointer value_get_style (const GValue* value);
VALA_EXTERN GType style_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Style, style_unref)
VALA_EXTERN xmlNode* template_save (Template* self,
                        const gchar* node_name);
VALA_EXTERN void template_load (Template* self,
                    xmlNode* node);
VALA_EXTERN Style* style_new (void);
VALA_EXTERN Style* style_construct (GType object_type);
VALA_EXTERN GType template_type_get_type (void) G_GNUC_CONST ;
VALA_EXTERN StyleTemplate* style_template_new (TemplateType ttype,
                                   const gchar* name);
VALA_EXTERN StyleTemplate* style_template_construct (GType object_type,
                                         TemplateType ttype,
                                         const gchar* name);
VALA_EXTERN Template* template_new (TemplateType ttype,
                        const gchar* name);
VALA_EXTERN Template* template_construct (GType object_type,
                              TemplateType ttype,
                              const gchar* name);
VALA_EXTERN void style_template_update_from_style (StyleTemplate* self,
                                       Style* s);
VALA_EXTERN TemplateType template_get_ttype (Template* self);
VALA_EXTERN Style* style_template_get_style (StyleTemplate* self);
VALA_EXTERN gboolean style_copy_node_branch (Style* self,
                                 Style* s);
VALA_EXTERN gboolean style_copy_node_link (Style* self,
                               Style* s);
VALA_EXTERN gboolean style_copy_node_body (Style* self,
                               Style* s);
VALA_EXTERN gboolean style_copy_connection (Style* self,
                                Style* s);
VALA_EXTERN gboolean style_copy_callout (Style* self,
                             Style* s);
VALA_EXTERN void style_template_update_to_style (StyleTemplate* self,
                                     Style* to_style);
VALA_EXTERN gboolean style_copy (Style* self,
                     Style* s);
static xmlNode* style_template_real_save (Template* base,
                                   const gchar* node_name);
VALA_EXTERN void style_save_node_in_node (Style* self,
                              xmlNode* n);
VALA_EXTERN void style_save_connection_in_node (Style* self,
                                    xmlNode* n);
VALA_EXTERN void style_save_callout_in_node (Style* self,
                                 xmlNode* n);
static void style_template_real_load (Template* base,
                               xmlNode* node);
VALA_EXTERN void style_load_node (Style* self,
                      xmlNode* node);
VALA_EXTERN void style_load_connection (Style* self,
                            xmlNode* node);
VALA_EXTERN void style_load_callout (Style* self,
                         xmlNode* node);
static void style_template_finalize (Template * obj);
static GType style_template_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
style_template_get_instance_private (StyleTemplate* self)
{
	return G_STRUCT_MEMBER_P (self, StyleTemplate_private_offset);
}

StyleTemplate*
style_template_construct (GType object_type,
                          TemplateType ttype,
                          const gchar* name)
{
	StyleTemplate* self = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	self = (StyleTemplate*) template_construct (object_type, ttype, name);
	return self;
}

StyleTemplate*
style_template_new (TemplateType ttype,
                    const gchar* name)
{
	return style_template_construct (TYPE_STYLE_TEMPLATE, ttype, name);
}

void
style_template_update_from_style (StyleTemplate* self,
                                  Style* s)
{
	gboolean _tmp0_ = FALSE;
	gboolean _tmp1_ = FALSE;
	TemplateType _tmp2_;
	TemplateType _tmp3_;
	gboolean _tmp9_ = FALSE;
	gboolean _tmp10_ = FALSE;
	TemplateType _tmp11_;
	TemplateType _tmp12_;
	gboolean _tmp18_ = FALSE;
	gboolean _tmp19_ = FALSE;
	TemplateType _tmp20_;
	TemplateType _tmp21_;
	gboolean _tmp27_ = FALSE;
	gboolean _tmp28_ = FALSE;
	TemplateType _tmp29_;
	TemplateType _tmp30_;
	gboolean _tmp36_ = FALSE;
	gboolean _tmp37_ = FALSE;
	TemplateType _tmp38_;
	TemplateType _tmp39_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (s != NULL);
	_tmp2_ = template_get_ttype ((Template*) self);
	_tmp3_ = _tmp2_;
	if (_tmp3_ == TEMPLATE_TYPE_STYLE_GENERAL) {
		_tmp1_ = TRUE;
	} else {
		TemplateType _tmp4_;
		TemplateType _tmp5_;
		_tmp4_ = template_get_ttype ((Template*) self);
		_tmp5_ = _tmp4_;
		_tmp1_ = _tmp5_ == TEMPLATE_TYPE_STYLE_NODE;
	}
	if (_tmp1_) {
		_tmp0_ = TRUE;
	} else {
		TemplateType _tmp6_;
		TemplateType _tmp7_;
		_tmp6_ = template_get_ttype ((Template*) self);
		_tmp7_ = _tmp6_;
		_tmp0_ = _tmp7_ == TEMPLATE_TYPE_STYLE_OPTION_BRANCH;
	}
	if (_tmp0_) {
		Style* _tmp8_;
		_tmp8_ = self->priv->_style;
		style_copy_node_branch (_tmp8_, s);
	}
	_tmp11_ = template_get_ttype ((Template*) self);
	_tmp12_ = _tmp11_;
	if (_tmp12_ == TEMPLATE_TYPE_STYLE_GENERAL) {
		_tmp10_ = TRUE;
	} else {
		TemplateType _tmp13_;
		TemplateType _tmp14_;
		_tmp13_ = template_get_ttype ((Template*) self);
		_tmp14_ = _tmp13_;
		_tmp10_ = _tmp14_ == TEMPLATE_TYPE_STYLE_NODE;
	}
	if (_tmp10_) {
		_tmp9_ = TRUE;
	} else {
		TemplateType _tmp15_;
		TemplateType _tmp16_;
		_tmp15_ = template_get_ttype ((Template*) self);
		_tmp16_ = _tmp15_;
		_tmp9_ = _tmp16_ == TEMPLATE_TYPE_STYLE_OPTION_LINK;
	}
	if (_tmp9_) {
		Style* _tmp17_;
		_tmp17_ = self->priv->_style;
		style_copy_node_link (_tmp17_, s);
	}
	_tmp20_ = template_get_ttype ((Template*) self);
	_tmp21_ = _tmp20_;
	if (_tmp21_ == TEMPLATE_TYPE_STYLE_GENERAL) {
		_tmp19_ = TRUE;
	} else {
		TemplateType _tmp22_;
		TemplateType _tmp23_;
		_tmp22_ = template_get_ttype ((Template*) self);
		_tmp23_ = _tmp22_;
		_tmp19_ = _tmp23_ == TEMPLATE_TYPE_STYLE_NODE;
	}
	if (_tmp19_) {
		_tmp18_ = TRUE;
	} else {
		TemplateType _tmp24_;
		TemplateType _tmp25_;
		_tmp24_ = template_get_ttype ((Template*) self);
		_tmp25_ = _tmp24_;
		_tmp18_ = _tmp25_ == TEMPLATE_TYPE_STYLE_OPTION_NODE;
	}
	if (_tmp18_) {
		Style* _tmp26_;
		_tmp26_ = self->priv->_style;
		style_copy_node_body (_tmp26_, s);
	}
	_tmp29_ = template_get_ttype ((Template*) self);
	_tmp30_ = _tmp29_;
	if (_tmp30_ == TEMPLATE_TYPE_STYLE_GENERAL) {
		_tmp28_ = TRUE;
	} else {
		TemplateType _tmp31_;
		TemplateType _tmp32_;
		_tmp31_ = template_get_ttype ((Template*) self);
		_tmp32_ = _tmp31_;
		_tmp28_ = _tmp32_ == TEMPLATE_TYPE_STYLE_CONNECTION;
	}
	if (_tmp28_) {
		_tmp27_ = TRUE;
	} else {
		TemplateType _tmp33_;
		TemplateType _tmp34_;
		_tmp33_ = template_get_ttype ((Template*) self);
		_tmp34_ = _tmp33_;
		_tmp27_ = _tmp34_ == TEMPLATE_TYPE_STYLE_OPTION_CONNECTION;
	}
	if (_tmp27_) {
		Style* _tmp35_;
		_tmp35_ = self->priv->_style;
		style_copy_connection (_tmp35_, s);
	}
	_tmp38_ = template_get_ttype ((Template*) self);
	_tmp39_ = _tmp38_;
	if (_tmp39_ == TEMPLATE_TYPE_STYLE_GENERAL) {
		_tmp37_ = TRUE;
	} else {
		TemplateType _tmp40_;
		TemplateType _tmp41_;
		_tmp40_ = template_get_ttype ((Template*) self);
		_tmp41_ = _tmp40_;
		_tmp37_ = _tmp41_ == TEMPLATE_TYPE_STYLE_CALLOUT;
	}
	if (_tmp37_) {
		_tmp36_ = TRUE;
	} else {
		TemplateType _tmp42_;
		TemplateType _tmp43_;
		_tmp42_ = template_get_ttype ((Template*) self);
		_tmp43_ = _tmp42_;
		_tmp36_ = _tmp43_ == TEMPLATE_TYPE_STYLE_OPTION_CALLOUT;
	}
	if (_tmp36_) {
		Style* _tmp44_;
		_tmp44_ = self->priv->_style;
		style_copy_callout (_tmp44_, s);
	}
}

void
style_template_update_to_style (StyleTemplate* self,
                                Style* to_style)
{
	Style* _tmp0_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (to_style != NULL);
	_tmp0_ = self->priv->_style;
	style_copy (to_style, _tmp0_);
}

static xmlNode*
style_template_real_save (Template* base,
                          const gchar* node_name)
{
	StyleTemplate * self;
	xmlNode* node = NULL;
	xmlNode* _tmp0_;
	Style* _tmp1_;
	Style* _tmp2_;
	Style* _tmp3_;
	xmlNode* result;
	self = (StyleTemplate*) base;
	_tmp0_ = TEMPLATE_CLASS (style_template_parent_class)->save (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_TEMPLATE, Template), node_name);
	node = _tmp0_;
	_tmp1_ = self->priv->_style;
	style_save_node_in_node (_tmp1_, node);
	_tmp2_ = self->priv->_style;
	style_save_connection_in_node (_tmp2_, node);
	_tmp3_ = self->priv->_style;
	style_save_callout_in_node (_tmp3_, node);
	result = node;
	return result;
}

static void
style_template_real_load (Template* base,
                          xmlNode* node)
{
	StyleTemplate * self;
	Style* _tmp0_;
	Style* _tmp1_;
	Style* _tmp2_;
	self = (StyleTemplate*) base;
	TEMPLATE_CLASS (style_template_parent_class)->load (G_TYPE_CHECK_INSTANCE_CAST (self, TYPE_TEMPLATE, Template), node);
	_tmp0_ = self->priv->_style;
	style_load_node (_tmp0_, node);
	_tmp1_ = self->priv->_style;
	style_load_connection (_tmp1_, node);
	_tmp2_ = self->priv->_style;
	style_load_callout (_tmp2_, node);
}

Style*
style_template_get_style (StyleTemplate* self)
{
	Style* result;
	Style* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_style;
	result = _tmp0_;
	return result;
}

static void
style_template_class_init (StyleTemplateClass * klass,
                           gpointer klass_data)
{
	style_template_parent_class = g_type_class_peek_parent (klass);
	((TemplateClass *) klass)->finalize = style_template_finalize;
	g_type_class_adjust_private_offset (klass, &StyleTemplate_private_offset);
	((TemplateClass *) klass)->save = (xmlNode* (*) (Template*, const gchar*)) style_template_real_save;
	((TemplateClass *) klass)->load = (void (*) (Template*, xmlNode*)) style_template_real_load;
}

static void
style_template_instance_init (StyleTemplate * self,
                              gpointer klass)
{
	Style* _tmp0_;
	self->priv = style_template_get_instance_private (self);
	_tmp0_ = style_new ();
	self->priv->_style = _tmp0_;
}

static void
style_template_finalize (Template * obj)
{
	StyleTemplate * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_STYLE_TEMPLATE, StyleTemplate);
	_style_unref0 (self->priv->_style);
	TEMPLATE_CLASS (style_template_parent_class)->finalize (obj);
}

static GType
style_template_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (StyleTemplateClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) style_template_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (StyleTemplate), 0, (GInstanceInitFunc) style_template_instance_init, NULL };
	GType style_template_type_id;
	style_template_type_id = g_type_register_static (TYPE_TEMPLATE, "StyleTemplate", &g_define_type_info, 0);
	StyleTemplate_private_offset = g_type_add_instance_private (style_template_type_id, sizeof (StyleTemplatePrivate));
	return style_template_type_id;
}

GType
style_template_get_type (void)
{
	static volatile gsize style_template_type_id__once = 0;
	if (g_once_init_enter (&style_template_type_id__once)) {
		GType style_template_type_id;
		style_template_type_id = style_template_get_type_once ();
		g_once_init_leave (&style_template_type_id__once, style_template_type_id);
	}
	return style_template_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;
}

