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

/* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* SerializableInt.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>
#include <float.h>
#include <math.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_DOUBLE (gxml_serializable_double_get_type ())
#define GXML_SERIALIZABLE_DOUBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_SERIALIZABLE_DOUBLE, GXmlSerializableDouble))
#define GXML_SERIALIZABLE_DOUBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GXML_TYPE_SERIALIZABLE_DOUBLE, GXmlSerializableDoubleClass))
#define GXML_IS_SERIALIZABLE_DOUBLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_SERIALIZABLE_DOUBLE))
#define GXML_IS_SERIALIZABLE_DOUBLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GXML_TYPE_SERIALIZABLE_DOUBLE))
#define GXML_SERIALIZABLE_DOUBLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GXML_TYPE_SERIALIZABLE_DOUBLE, GXmlSerializableDoubleClass))

typedef struct _GXmlSerializableDouble GXmlSerializableDouble;
typedef struct _GXmlSerializableDoubleClass GXmlSerializableDoubleClass;
typedef struct _GXmlSerializableDoublePrivate GXmlSerializableDoublePrivate;

#define GXML_TYPE_SERIALIZABLE_FLOAT (gxml_serializable_float_get_type ())
#define GXML_SERIALIZABLE_FLOAT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GXML_TYPE_SERIALIZABLE_FLOAT, GXmlSerializableFloat))
#define GXML_SERIALIZABLE_FLOAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GXML_TYPE_SERIALIZABLE_FLOAT, GXmlSerializableFloatClass))
#define GXML_IS_SERIALIZABLE_FLOAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GXML_TYPE_SERIALIZABLE_FLOAT))
#define GXML_IS_SERIALIZABLE_FLOAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GXML_TYPE_SERIALIZABLE_FLOAT))
#define GXML_SERIALIZABLE_FLOAT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GXML_TYPE_SERIALIZABLE_FLOAT, GXmlSerializableFloatClass))

typedef struct _GXmlSerializableFloat GXmlSerializableFloat;
typedef struct _GXmlSerializableFloatClass GXmlSerializableFloatClass;
typedef struct _GXmlSerializableFloatPrivate GXmlSerializableFloatPrivate;
#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_INVALID = 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);
	GXmlElementList* (*get_elements_by_name) (GXmlNode* self, const gchar* name);
	GXmlElementList* (*get_elements_by_name_ns) (GXmlNode* self, const gchar* name, const gchar* ns);
	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_children_nodes) (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 _GXmlSerializableDouble {
	GObject parent_instance;
	GXmlSerializableDoublePrivate * priv;
	gchar* _val;
	gint _fraction;
};

struct _GXmlSerializableDoubleClass {
	GObjectClass parent_class;
};

struct _GXmlSerializableFloat {
	GXmlSerializableDouble parent_instance;
	GXmlSerializableFloatPrivate * priv;
};

struct _GXmlSerializableFloatClass {
	GXmlSerializableDoubleClass parent_class;
};


static gpointer gxml_serializable_float_parent_class = 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_double_get_type (void) G_GNUC_CONST;
GType gxml_serializable_float_get_type (void) G_GNUC_CONST;
enum  {
	GXML_SERIALIZABLE_FLOAT_DUMMY_PROPERTY
};
gfloat gxml_serializable_float_get_value (GXmlSerializableFloat* self);
void gxml_serializable_float_set_value (GXmlSerializableFloat* self, gfloat val);
GXmlSerializableFloat* gxml_serializable_float_new (void);
GXmlSerializableFloat* gxml_serializable_float_construct (GType object_type);
GXmlSerializableDouble* gxml_serializable_double_new (void);
GXmlSerializableDouble* gxml_serializable_double_construct (GType object_type);


/**
   * Parse the stored value, from the XML property, to a {@link int}. This parsing
   * may is different from the actual stored string.
   *
   * The stored value, is parsed using to double value and then
   * casted to an float before return, this make flexible on stored values
   * in XML and parsed without errors, but they could defere from the value
   * returned by this method.
   */
static gdouble double_parse (const gchar* str) {
	gdouble result = 0.0;
	const gchar* _tmp0_ = NULL;
	gdouble _tmp1_ = 0.0;
	g_return_val_if_fail (str != NULL, 0.0);
	_tmp0_ = str;
	_tmp1_ = g_ascii_strtod (_tmp0_, NULL);
	result = _tmp1_;
	return result;
}


gfloat gxml_serializable_float_get_value (GXmlSerializableFloat* self) {
	gfloat result = 0.0F;
	const gchar* _tmp0_ = NULL;
	gdouble _tmp1_ = 0.0;
	g_return_val_if_fail (self != NULL, 0.0F);
	_tmp0_ = ((GXmlSerializableDouble*) self)->_val;
	_tmp1_ = double_parse (_tmp0_);
	result = (gfloat) _tmp1_;
	return result;
}


/**
   * Given float number is parsed to string and then stored.
   */
void gxml_serializable_float_set_value (GXmlSerializableFloat* self, gfloat val) {
	gfloat _tmp0_ = 0.0F;
	gchar* _tmp1_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = val;
	_tmp1_ = g_strdup_printf ("%g", _tmp0_);
	_g_free0 (((GXmlSerializableDouble*) self)->_val);
	((GXmlSerializableDouble*) self)->_val = _tmp1_;
}


GXmlSerializableFloat* gxml_serializable_float_construct (GType object_type) {
	GXmlSerializableFloat * self = NULL;
	self = (GXmlSerializableFloat*) gxml_serializable_double_construct (object_type);
	return self;
}


GXmlSerializableFloat* gxml_serializable_float_new (void) {
	return gxml_serializable_float_construct (GXML_TYPE_SERIALIZABLE_FLOAT);
}


static void gxml_serializable_float_class_init (GXmlSerializableFloatClass * klass) {
	gxml_serializable_float_parent_class = g_type_class_peek_parent (klass);
}


static void gxml_serializable_float_instance_init (GXmlSerializableFloat * self) {
}


/**
 * Represent any float property to be added as a {@link GXml.Attribute} to a {@link GXml.Element}
 *
 * This object can be used when the property could be removed from serialization, specially if missing
 * on XML have some missing and avoidable.
 */
GType gxml_serializable_float_get_type (void) {
	static volatile gsize gxml_serializable_float_type_id__volatile = 0;
	if (g_once_init_enter (&gxml_serializable_float_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (GXmlSerializableFloatClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) gxml_serializable_float_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GXmlSerializableFloat), 0, (GInstanceInitFunc) gxml_serializable_float_instance_init, NULL };
		GType gxml_serializable_float_type_id;
		gxml_serializable_float_type_id = g_type_register_static (GXML_TYPE_SERIALIZABLE_DOUBLE, "GXmlSerializableFloat", &g_define_type_info, 0);
		g_once_init_leave (&gxml_serializable_float_type_id__volatile, gxml_serializable_float_type_id);
	}
	return gxml_serializable_float_type_id__volatile;
}



