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

/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* SerializableBool.vala
 *
 * Copyright (C) 2015  Daniel Espinosa <esodan@gmail.com>
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *      Daniel Espinosa <esodan@gmail.com>
 */

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gee.h>
#include <gio/gio.h>


#define GXML_TYPE_SERIALIZABLE_PROPERTY (gxml_serializable_property_get_type ())
#define GXML_SERIALIZABLE_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_SERIALIZABLE_PROPERTY, GXmlSerializableProperty))
#define GXML_IS_SERIALIZABLE_PROPERTY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_SERIALIZABLE_PROPERTY))
#define GXML_SERIALIZABLE_PROPERTY_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_SERIALIZABLE_PROPERTY, GXmlSerializablePropertyIface))

typedef struct _GXmlSerializableProperty GXmlSerializableProperty;
typedef struct _GXmlSerializablePropertyIface GXmlSerializablePropertyIface;

#define GXML_TYPE_NODE (gxml_node_get_type ())
#define GXML_NODE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_NODE, GXmlNode))
#define GXML_IS_NODE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_NODE))
#define GXML_NODE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_NODE, GXmlNodeIface))

typedef struct _GXmlNode GXmlNode;
typedef struct _GXmlNodeIface GXmlNodeIface;

#define GXML_TYPE_ELEMENT_LIST (gxml_element_list_get_type ())
#define GXML_ELEMENT_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_ELEMENT_LIST, GXmlElementList))
#define GXML_ELEMENT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GXML_TYPE_ELEMENT_LIST, GXmlElementListClass))
#define GXML_IS_ELEMENT_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_ELEMENT_LIST))
#define GXML_IS_ELEMENT_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GXML_TYPE_ELEMENT_LIST))
#define GXML_ELEMENT_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GXML_TYPE_ELEMENT_LIST, GXmlElementListClass))

typedef struct _GXmlElementList GXmlElementList;
typedef struct _GXmlElementListClass GXmlElementListClass;

#define GXML_TYPE_NAMESPACE (gxml_namespace_get_type ())
#define GXML_NAMESPACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_NAMESPACE, GXmlNamespace))
#define GXML_IS_NAMESPACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_NAMESPACE))
#define GXML_NAMESPACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_NAMESPACE, GXmlNamespaceIface))

typedef struct _GXmlNamespace GXmlNamespace;
typedef struct _GXmlNamespaceIface GXmlNamespaceIface;

#define GXML_TYPE_NODE_TYPE (gxml_node_type_get_type ())

#define GXML_TYPE_DOCUMENT (gxml_document_get_type ())
#define GXML_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_DOCUMENT, GXmlDocument))
#define GXML_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_DOCUMENT))
#define GXML_DOCUMENT_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GXML_TYPE_DOCUMENT, GXmlDocumentIface))

typedef struct _GXmlDocument GXmlDocument;
typedef struct _GXmlDocumentIface GXmlDocumentIface;

#define GXML_TYPE_SERIALIZABLE_BOOL (gxml_serializable_bool_get_type ())
#define GXML_SERIALIZABLE_BOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_SERIALIZABLE_BOOL, GXmlSerializableBool))
#define GXML_SERIALIZABLE_BOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GXML_TYPE_SERIALIZABLE_BOOL, GXmlSerializableBoolClass))
#define GXML_IS_SERIALIZABLE_BOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_SERIALIZABLE_BOOL))
#define GXML_IS_SERIALIZABLE_BOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GXML_TYPE_SERIALIZABLE_BOOL))
#define GXML_SERIALIZABLE_BOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GXML_TYPE_SERIALIZABLE_BOOL, GXmlSerializableBoolClass))

typedef struct _GXmlSerializableBool GXmlSerializableBool;
typedef struct _GXmlSerializableBoolClass GXmlSerializableBoolClass;
typedef struct _GXmlSerializableBoolPrivate GXmlSerializableBoolPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))

struct _GXmlNamespaceIface {
	GTypeInterface parent_iface;
	gchar* (*get_uri) (GXmlNamespace* self);
	gchar* (*get_prefix) (GXmlNamespace* self);
};

typedef enum  {
	GXML_NODE_TYPE_X_UNKNOWN = 0,
	GXML_NODE_TYPE_ELEMENT = 1,
	GXML_NODE_TYPE_ATTRIBUTE,
	GXML_NODE_TYPE_TEXT,
	GXML_NODE_TYPE_CDATA_SECTION,
	GXML_NODE_TYPE_ENTITY_REFERENCE,
	GXML_NODE_TYPE_ENTITY,
	GXML_NODE_TYPE_PROCESSING_INSTRUCTION,
	GXML_NODE_TYPE_COMMENT,
	GXML_NODE_TYPE_DOCUMENT,
	GXML_NODE_TYPE_DOCUMENT_TYPE,
	GXML_NODE_TYPE_DOCUMENT_FRAGMENT,
	GXML_NODE_TYPE_NOTATION
} GXmlNodeType;

struct _GXmlDocumentIface {
	GTypeInterface parent_iface;
	GXmlNode* (*create_element) (GXmlDocument* self, const gchar* name, GError** error);
	GXmlNode* (*create_text) (GXmlDocument* self, const gchar* text);
	GXmlNode* (*create_comment) (GXmlDocument* self, const gchar* text);
	GXmlNode* (*create_cdata) (GXmlDocument* self, const gchar* text);
	GXmlNode* (*create_pi) (GXmlDocument* self, const gchar* target, const gchar* data);
	gboolean (*save) (GXmlDocument* self, GCancellable* cancellable, GError** error);
	gboolean (*save_as) (GXmlDocument* self, GFile* f, GCancellable* cancellable, GError** error);
	gboolean (*get_indent) (GXmlDocument* self);
	void (*set_indent) (GXmlDocument* self, gboolean value);
	gboolean (*get_ns_top) (GXmlDocument* self);
	void (*set_ns_top) (GXmlDocument* self, gboolean value);
	gboolean (*get_prefix_default_ns) (GXmlDocument* self);
	void (*set_prefix_default_ns) (GXmlDocument* self, gboolean value);
	gboolean (*get_backup) (GXmlDocument* self);
	void (*set_backup) (GXmlDocument* self, gboolean value);
	GXmlNode* (*get_root) (GXmlDocument* self);
	GFile* (*get_file) (GXmlDocument* self);
	void (*set_file) (GXmlDocument* self, GFile* value);
};

struct _GXmlNodeIface {
	GTypeInterface parent_iface;
	GXmlNode* (*get) (GXmlNode* self, const gchar* key);
	GXmlElementList* (*get_elements_by_property_value) (GXmlNode* self, const gchar* property, const gchar* value);
	gchar* (*to_string) (GXmlNode* self);
	gboolean (*set_namespace) (GXmlNode* self, const gchar* uri, const gchar* prefix);
	gchar* (*ns_prefix) (GXmlNode* self);
	gchar* (*ns_uri) (GXmlNode* self);
	GeeList* (*get_namespaces) (GXmlNode* self);
	GeeBidirList* (*get_childs) (GXmlNode* self);
	GeeBidirList* (*get_children) (GXmlNode* self);
	GeeMap* (*get_attrs) (GXmlNode* self);
	gchar* (*get_name) (GXmlNode* self);
	gchar* (*get_value) (GXmlNode* self);
	void (*set_value) (GXmlNode* self, const gchar* value);
	GXmlNodeType (*get_type_node) (GXmlNode* self);
	GXmlDocument* (*get_document) (GXmlNode* self);
	GXmlNode* (*get_parent) (GXmlNode* self);
};

struct _GXmlSerializablePropertyIface {
	GTypeInterface parent_iface;
	gchar* (*get_serializable_property_value) (GXmlSerializableProperty* self);
	void (*set_serializable_property_value) (GXmlSerializableProperty* self, const gchar* val);
	gboolean (*deserialize_property) (GXmlSerializableProperty* self, GXmlNode* property_node, GParamSpec* prop, gboolean nick, GError** error);
	GXmlNode* (*serialize_property) (GXmlSerializableProperty* self, GXmlNode* property_node, GParamSpec* prop, gboolean nick, GError** error);
};

struct _GXmlSerializableBool {
	GObject parent_instance;
	GXmlSerializableBoolPrivate * priv;
};

struct _GXmlSerializableBoolClass {
	GObjectClass parent_class;
};

struct _GXmlSerializableBoolPrivate {
	gchar* _val;
};


static gpointer gxml_serializable_bool_parent_class = NULL;
static GXmlSerializablePropertyIface* gxml_serializable_bool_gxml_serializable_property_parent_iface = NULL;

GType gxml_element_list_get_type (void) G_GNUC_CONST;
GType gxml_namespace_get_type (void) G_GNUC_CONST;
GType gxml_node_type_get_type (void) G_GNUC_CONST;
GType gxml_document_get_type (void) G_GNUC_CONST;
GType gxml_node_get_type (void) G_GNUC_CONST;
GType gxml_serializable_property_get_type (void) G_GNUC_CONST;
GType gxml_serializable_bool_get_type (void) G_GNUC_CONST;
#define GXML_SERIALIZABLE_BOOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GXML_TYPE_SERIALIZABLE_BOOL, GXmlSerializableBoolPrivate))
enum  {
	GXML_SERIALIZABLE_BOOL_DUMMY_PROPERTY
};
gboolean gxml_serializable_bool_get_value (GXmlSerializableBool* self);
void gxml_serializable_bool_set_value (GXmlSerializableBool* self, gboolean val);
static gchar* gxml_serializable_bool_real_get_serializable_property_value (GXmlSerializableProperty* base);
static void gxml_serializable_bool_real_set_serializable_property_value (GXmlSerializableProperty* base, const gchar* val);
gchar* gxml_serializable_bool_to_string (GXmlSerializableBool* self);
GXmlSerializableBool* gxml_serializable_bool_new (void);
GXmlSerializableBool* gxml_serializable_bool_construct (GType object_type);
static GObject * gxml_serializable_bool_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
void gxml_init_init (void);
static void gxml_serializable_bool_finalize (GObject* obj);


/**
   * Parse the stored value, from the XML property, to a {@link int}. This parsing
   * may is different from the actual stored string. If can't be parsed to a valid
   * boolean, this method will always return false.
   */
gboolean gxml_serializable_bool_get_value (GXmlSerializableBool* self) {
	gboolean result = FALSE;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	gchar* _tmp2_ = NULL;
	gboolean _tmp3_ = FALSE;
	const gchar* _tmp4_ = NULL;
	gchar* _tmp5_ = NULL;
	gchar* _tmp6_ = NULL;
	gboolean _tmp7_ = FALSE;
	g_return_val_if_fail (self != NULL, FALSE);
	_tmp0_ = self->priv->_val;
	_tmp1_ = g_utf8_strdown (_tmp0_, (gssize) (-1));
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strcmp0 (_tmp2_, "true") == 0;
	_g_free0 (_tmp2_);
	if (_tmp3_) {
		result = TRUE;
		return result;
	}
	_tmp4_ = self->priv->_val;
	_tmp5_ = g_utf8_strdown (_tmp4_, (gssize) (-1));
	_tmp6_ = _tmp5_;
	_tmp7_ = g_strcmp0 (_tmp6_, "false") == 0;
	_g_free0 (_tmp6_);
	if (_tmp7_) {
		result = FALSE;
		return result;
	}
	result = FALSE;
	return result;
}


/**
   * Given boolean value is parsed to string and then stored.
   */
static gchar* bool_to_string (gboolean self) {
	gchar* result = NULL;
	if (self) {
		gchar* _tmp0_ = NULL;
		_tmp0_ = g_strdup ("true");
		result = _tmp0_;
		return result;
	} else {
		gchar* _tmp1_ = NULL;
		_tmp1_ = g_strdup ("false");
		result = _tmp1_;
		return result;
	}
}


void gxml_serializable_bool_set_value (GXmlSerializableBool* self, gboolean val) {
	gboolean _tmp0_ = FALSE;
	gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = val;
	_tmp1_ = bool_to_string (_tmp0_);
	_g_free0 (self->priv->_val);
	self->priv->_val = _tmp1_;
}


static gchar* gxml_serializable_bool_real_get_serializable_property_value (GXmlSerializableProperty* base) {
	GXmlSerializableBool * self;
	gchar* result = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	self = (GXmlSerializableBool*) base;
	_tmp0_ = self->priv->_val;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}


static void gxml_serializable_bool_real_set_serializable_property_value (GXmlSerializableProperty* base, const gchar* val) {
	GXmlSerializableBool * self;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	self = (GXmlSerializableBool*) base;
	_tmp0_ = val;
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->priv->_val);
	self->priv->_val = _tmp1_;
}


/**
   * Parse actual stored string to a boolean and returns the result. See {@link get_value}
   */
gchar* gxml_serializable_bool_to_string (GXmlSerializableBool* self) {
	gchar* result = NULL;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = gxml_serializable_bool_get_value (self);
	_tmp1_ = bool_to_string (_tmp0_);
	result = _tmp1_;
	return result;
}


GXmlSerializableBool* gxml_serializable_bool_construct (GType object_type) {
	GXmlSerializableBool * self = NULL;
	self = (GXmlSerializableBool*) g_object_new (object_type, NULL);
	return self;
}


GXmlSerializableBool* gxml_serializable_bool_new (void) {
	return gxml_serializable_bool_construct (GXML_TYPE_SERIALIZABLE_BOOL);
}


static GObject * gxml_serializable_bool_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	GObjectClass * parent_class;
	GXmlSerializableBool * self;
	parent_class = G_OBJECT_CLASS (gxml_serializable_bool_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GXML_TYPE_SERIALIZABLE_BOOL, GXmlSerializableBool);
	gxml_init_init ();
	return obj;
}


static void gxml_serializable_bool_class_init (GXmlSerializableBoolClass * klass) {
	gxml_serializable_bool_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (GXmlSerializableBoolPrivate));
	G_OBJECT_CLASS (klass)->constructor = gxml_serializable_bool_constructor;
	G_OBJECT_CLASS (klass)->finalize = gxml_serializable_bool_finalize;
}


static void gxml_serializable_bool_gxml_serializable_property_interface_init (GXmlSerializablePropertyIface * iface) {
	gxml_serializable_bool_gxml_serializable_property_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_serializable_property_value = (gchar* (*)(GXmlSerializableProperty*)) gxml_serializable_bool_real_get_serializable_property_value;
	iface->set_serializable_property_value = (void (*)(GXmlSerializableProperty*, const gchar*)) gxml_serializable_bool_real_set_serializable_property_value;
}


static void gxml_serializable_bool_instance_init (GXmlSerializableBool * self) {
	self->priv = GXML_SERIALIZABLE_BOOL_GET_PRIVATE (self);
	self->priv->_val = NULL;
}


static void gxml_serializable_bool_finalize (GObject* obj) {
	GXmlSerializableBool * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GXML_TYPE_SERIALIZABLE_BOOL, GXmlSerializableBool);
	_g_free0 (self->priv->_val);
	G_OBJECT_CLASS (gxml_serializable_bool_parent_class)->finalize (obj);
}


/**
 * Represent any boolean property to be added as a {@link GXml.Attribute} to a {@link GXml.Element}
 *
 */
GType gxml_serializable_bool_get_type (void) {
	static volatile gsize gxml_serializable_bool_type_id__volatile = 0;
	if (g_once_init_enter (&gxml_serializable_bool_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GXmlSerializableBoolClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gxml_serializable_bool_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GXmlSerializableBool), 0, (GInstanceInitFunc) gxml_serializable_bool_instance_init, NULL };
		static const GInterfaceInfo gxml_serializable_property_info = { (GInterfaceInitFunc) gxml_serializable_bool_gxml_serializable_property_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
		GType gxml_serializable_bool_type_id;
		gxml_serializable_bool_type_id = g_type_register_static (G_TYPE_OBJECT, "GXmlSerializableBool", &g_define_type_info, 0);
		g_type_add_interface_static (gxml_serializable_bool_type_id, GXML_TYPE_SERIALIZABLE_PROPERTY, &gxml_serializable_property_info);
		g_once_init_leave (&gxml_serializable_bool_type_id__volatile, gxml_serializable_bool_type_id);
	}
	return gxml_serializable_bool_type_id__volatile;
}



