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

/*
* Copyright (c) 2018-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 <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n-lib.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_UNDO_ITEM (undo_item_get_type ())
#define UNDO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_ITEM, UndoItem))
#define UNDO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_ITEM, UndoItemClass))
#define IS_UNDO_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_ITEM))
#define IS_UNDO_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_ITEM))
#define UNDO_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_ITEM, UndoItemClass))

typedef struct _UndoItem UndoItem;
typedef struct _UndoItemClass UndoItemClass;
typedef struct _UndoItemPrivate UndoItemPrivate;

#define TYPE_MIND_MAP (mind_map_get_type ())
#define MIND_MAP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MIND_MAP, MindMap))
#define MIND_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MIND_MAP, MindMapClass))
#define IS_MIND_MAP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_MIND_MAP))
#define IS_MIND_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_MIND_MAP))
#define MIND_MAP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_MIND_MAP, MindMapClass))

typedef struct _MindMap MindMap;
typedef struct _MindMapClass MindMapClass;

#define TYPE_UNDO_NODE_SEQUENCES (undo_node_sequences_get_type ())
#define UNDO_NODE_SEQUENCES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_UNDO_NODE_SEQUENCES, UndoNodeSequences))
#define UNDO_NODE_SEQUENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_UNDO_NODE_SEQUENCES, UndoNodeSequencesClass))
#define IS_UNDO_NODE_SEQUENCES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_UNDO_NODE_SEQUENCES))
#define IS_UNDO_NODE_SEQUENCES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_UNDO_NODE_SEQUENCES))
#define UNDO_NODE_SEQUENCES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_UNDO_NODE_SEQUENCES, UndoNodeSequencesClass))

typedef struct _UndoNodeSequences UndoNodeSequences;
typedef struct _UndoNodeSequencesClass UndoNodeSequencesClass;
typedef struct _UndoNodeSequencesPrivate UndoNodeSequencesPrivate;

#define TYPE_NODE (node_get_type ())
#define NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_NODE, Node))
#define NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_NODE, NodeClass))
#define IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_NODE))
#define IS_NODE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_NODE))
#define NODE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_NODE, NodeClass))

typedef struct _Node Node;
typedef struct _NodeClass NodeClass;
enum  {
	UNDO_NODE_SEQUENCES_0_PROPERTY,
	UNDO_NODE_SEQUENCES_NUM_PROPERTIES
};
static GParamSpec* undo_node_sequences_properties[UNDO_NODE_SEQUENCES_NUM_PROPERTIES];
#define _g_array_unref0(var) ((var == NULL) ? NULL : (var = (g_array_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _UndoItem {
	GObject parent_instance;
	UndoItemPrivate * priv;
};

struct _UndoItemClass {
	GObjectClass parent_class;
	void (*undo) (UndoItem* self, MindMap* map);
	void (*redo) (UndoItem* self, MindMap* map);
	gboolean (*matches) (UndoItem* self, UndoItem* item);
	void (*replace_with_item) (UndoItem* self, UndoItem* item);
	gchar* (*to_string) (UndoItem* self);
};

struct _UndoNodeSequences {
	UndoItem parent_instance;
	UndoNodeSequencesPrivate * priv;
};

struct _UndoNodeSequencesClass {
	UndoItemClass parent_class;
};

struct _UndoNodeSequencesPrivate {
	GArray* _nodes;
};

static gint UndoNodeSequences_private_offset;
static gpointer undo_node_sequences_parent_class = NULL;

VALA_EXTERN GType undo_item_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoItem, g_object_unref)
VALA_EXTERN gpointer mind_map_ref (gpointer instance);
VALA_EXTERN void mind_map_unref (gpointer instance);
VALA_EXTERN GParamSpec* param_spec_mind_map (const gchar* name,
                                 const gchar* nick,
                                 const gchar* blurb,
                                 GType object_type,
                                 GParamFlags flags);
VALA_EXTERN void value_set_mind_map (GValue* value,
                         gpointer v_object);
VALA_EXTERN void value_take_mind_map (GValue* value,
                          gpointer v_object);
VALA_EXTERN gpointer value_get_mind_map (const GValue* value);
VALA_EXTERN GType mind_map_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MindMap, mind_map_unref)
VALA_EXTERN GType undo_node_sequences_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (UndoNodeSequences, g_object_unref)
VALA_EXTERN GType node_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (Node, g_object_unref)
VALA_EXTERN void undo_item_undo (UndoItem* self,
                     MindMap* map);
VALA_EXTERN void undo_item_redo (UndoItem* self,
                     MindMap* map);
VALA_EXTERN UndoNodeSequences* undo_node_sequences_new (GArray* nodes);
VALA_EXTERN UndoNodeSequences* undo_node_sequences_construct (GType object_type,
                                                  GArray* nodes);
VALA_EXTERN UndoItem* undo_item_new (const gchar* name);
VALA_EXTERN UndoItem* undo_item_construct (GType object_type,
                               const gchar* name);
static void undo_node_sequences_update (UndoNodeSequences* self,
                                 MindMap* map);
VALA_EXTERN gboolean node_get_sequence (Node* self);
VALA_EXTERN void node_set_sequence (Node* self,
                        gboolean value);
VALA_EXTERN void mind_map_queue_draw (MindMap* self);
VALA_EXTERN void mind_map_auto_save (MindMap* self);
static void undo_node_sequences_real_undo (UndoItem* base,
                                    MindMap* map);
static void undo_node_sequences_real_redo (UndoItem* base,
                                    MindMap* map);
static void undo_node_sequences_finalize (GObject * obj);
static GType undo_node_sequences_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
undo_node_sequences_get_instance_private (UndoNodeSequences* self)
{
	return G_STRUCT_MEMBER_P (self, UndoNodeSequences_private_offset);
}

static gpointer
_g_array_ref0 (gpointer self)
{
	return self ? g_array_ref (self) : NULL;
}

UndoNodeSequences*
undo_node_sequences_construct (GType object_type,
                               GArray* nodes)
{
	UndoNodeSequences * self = NULL;
	GArray* _tmp0_;
	g_return_val_if_fail (nodes != NULL, NULL);
	self = (UndoNodeSequences*) undo_item_construct (object_type, _ ("node sequence changes"));
	_tmp0_ = _g_array_ref0 (nodes);
	_g_array_unref0 (self->priv->_nodes);
	self->priv->_nodes = _tmp0_;
	return self;
}

UndoNodeSequences*
undo_node_sequences_new (GArray* nodes)
{
	return undo_node_sequences_construct (TYPE_UNDO_NODE_SEQUENCES, nodes);
}

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

static void
undo_node_sequences_update (UndoNodeSequences* self,
                            MindMap* map)
{
	g_return_if_fail (self != NULL);
	g_return_if_fail (map != NULL);
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp0_ = FALSE;
			_tmp0_ = TRUE;
			while (TRUE) {
				GArray* _tmp2_;
				Node* node = NULL;
				GArray* _tmp3_;
				Node* _tmp4_;
				Node* _tmp5_;
				Node* _tmp6_;
				Node* _tmp7_;
				gboolean _tmp8_;
				gboolean _tmp9_;
				if (!_tmp0_) {
					gint _tmp1_;
					_tmp1_ = i;
					i = _tmp1_ + 1;
				}
				_tmp0_ = FALSE;
				_tmp2_ = self->priv->_nodes;
				if (!(((guint) i) < _tmp2_->len)) {
					break;
				}
				_tmp3_ = self->priv->_nodes;
				_tmp4_ = g_array_index (_tmp3_, Node*, (guint) i);
				_tmp5_ = _g_object_ref0 (_tmp4_);
				node = _tmp5_;
				_tmp6_ = node;
				_tmp7_ = node;
				_tmp8_ = node_get_sequence (_tmp7_);
				_tmp9_ = _tmp8_;
				node_set_sequence (_tmp6_, !_tmp9_);
				_g_object_unref0 (node);
			}
		}
	}
	mind_map_queue_draw (map);
	g_signal_emit_by_name (map, "current-changed", map);
	mind_map_auto_save (map);
}

static void
undo_node_sequences_real_undo (UndoItem* base,
                               MindMap* map)
{
	UndoNodeSequences * self;
	self = (UndoNodeSequences*) base;
	g_return_if_fail (map != NULL);
	undo_node_sequences_update (self, map);
}

static void
undo_node_sequences_real_redo (UndoItem* base,
                               MindMap* map)
{
	UndoNodeSequences * self;
	self = (UndoNodeSequences*) base;
	g_return_if_fail (map != NULL);
	undo_node_sequences_update (self, map);
}

static void
undo_node_sequences_class_init (UndoNodeSequencesClass * klass,
                                gpointer klass_data)
{
	undo_node_sequences_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &UndoNodeSequences_private_offset);
	((UndoItemClass *) klass)->undo = (void (*) (UndoItem*, MindMap*)) undo_node_sequences_real_undo;
	((UndoItemClass *) klass)->redo = (void (*) (UndoItem*, MindMap*)) undo_node_sequences_real_redo;
	G_OBJECT_CLASS (klass)->finalize = undo_node_sequences_finalize;
}

static void
undo_node_sequences_instance_init (UndoNodeSequences * self,
                                   gpointer klass)
{
	self->priv = undo_node_sequences_get_instance_private (self);
}

static void
undo_node_sequences_finalize (GObject * obj)
{
	UndoNodeSequences * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_UNDO_NODE_SEQUENCES, UndoNodeSequences);
	_g_array_unref0 (self->priv->_nodes);
	G_OBJECT_CLASS (undo_node_sequences_parent_class)->finalize (obj);
}

static GType
undo_node_sequences_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (UndoNodeSequencesClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) undo_node_sequences_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UndoNodeSequences), 0, (GInstanceInitFunc) undo_node_sequences_instance_init, NULL };
	GType undo_node_sequences_type_id;
	undo_node_sequences_type_id = g_type_register_static (TYPE_UNDO_ITEM, "UndoNodeSequences", &g_define_type_info, 0);
	UndoNodeSequences_private_offset = g_type_add_instance_private (undo_node_sequences_type_id, sizeof (UndoNodeSequencesPrivate));
	return undo_node_sequences_type_id;
}

GType
undo_node_sequences_get_type (void)
{
	static volatile gsize undo_node_sequences_type_id__once = 0;
	if (g_once_init_enter (&undo_node_sequences_type_id__once)) {
		GType undo_node_sequences_type_id;
		undo_node_sequences_type_id = undo_node_sequences_get_type_once ();
		g_once_init_leave (&undo_node_sequences_type_id__once, undo_node_sequences_type_id);
	}
	return undo_node_sequences_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;
}

