summaryrefslogtreecommitdiff
path: root/src/xml-parser.h
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2014-09-13 20:37:57 +0200
committerTomas Bzatek <tbzatek@users.sourceforge.net>2014-09-13 20:37:57 +0200
commitdc32c58499caa8b1ec4e975afad75ca0d862e990 (patch)
tree91322afabcb457406ab512d20163f0dd73ce2c5a /src/xml-parser.h
parent302127b03d44277c829642468561ac9e518b7a21 (diff)
downloadcataract-dc32c58499caa8b1ec4e975afad75ca0d862e990.tar.xz
Introduce properties table
This is a new internal properties storage for attributes that can be defined both in the item and album scope, with the item scope taking priority. The big advantage is a better distinguishment from an undefined, default value. It also makes easier to retrieve attributes with properly defined scope priorities.
Diffstat (limited to 'src/xml-parser.h')
-rw-r--r--src/xml-parser.h61
1 files changed, 58 insertions, 3 deletions
diff --git a/src/xml-parser.h b/src/xml-parser.h
index 3ea3e90..27e8d83 100644
--- a/src/xml-parser.h
+++ b/src/xml-parser.h
@@ -23,6 +23,8 @@
#include <libxml/xmlmemory.h>
#include <libxml/xpath.h>
+#include "properties-table.h"
+
G_BEGIN_DECLS
@@ -57,11 +59,22 @@ gchar * xml_file_get_node_value_with_default (TXMLFile *file, const gchar *x_pat
/*
* xml_file_get_node_attribute: retrieve attribute value from XPath node
+ * - returns NULL if node is not present
*/
gchar * xml_file_get_node_attribute (TXMLFile *file, const gchar *x_path, const gchar *attr);
-long int xml_file_get_node_attribute_long (TXMLFile *file, const gchar *x_path, const gchar *attr, const int _default);
-gboolean xml_file_get_node_attribute_boolean (TXMLFile *file, const gchar *x_path, const gchar *attr, const gboolean _default);
-double xml_file_get_node_attribute_double (TXMLFile *file, const gchar *x_path, const gchar *attr, const double _default);
+gchar * xml_file_get_node_attribute_with_default (TXMLFile *file, const gchar *x_path, const gchar *attr, const gchar *_default);
+
+/*
+ * xml_file_get_node_attribute_*: retrieve attribute value from XPath node, storing it in *value, returning TRUE if value has been set.
+ */
+gboolean xml_file_get_node_attribute_long (TXMLFile *file, const gchar *x_path, const gchar *attr, long int *value);
+long int xml_file_get_node_attribute_long_with_default (TXMLFile *file, const gchar *x_path, const gchar *attr, const long int _default);
+
+gboolean xml_file_get_node_attribute_boolean (TXMLFile *file, const gchar *x_path, const gchar *attr, gboolean *value);
+gboolean xml_file_get_node_attribute_boolean_with_default (TXMLFile *file, const gchar *x_path, const gchar *attr, const gboolean _default);
+
+gboolean xml_file_get_node_attribute_double (TXMLFile *file, const gchar *x_path, const gchar *attr, double *value);
+double xml_file_get_node_attribute_double_with_default (TXMLFile *file, const gchar *x_path, const gchar *attr, const double _default);
/*
* xml_file_get_node_present: existency test of the XPath node
@@ -74,6 +87,48 @@ gboolean xml_file_get_node_present (TXMLFile *file, const gchar *x_path);
int xml_file_node_get_children_count (TXMLFile *file, const gchar *x_path);
+/*
+ * prop_xml_attr_*: retrieve data from the XML file and set the property if suceeded
+ * prop_xml_attr_*def: retrieve data from the XML file and set the property or default value on failure
+ */
+#define prop_xml_attr(t, n, xml, x_path, attr) { \
+ gchar *xxxs = xml_file_get_node_attribute (xml, x_path, attr); \
+ if (xxxs != NULL) \
+ properties_table_add_string (t, n, xxxs); \
+ g_free (xxxs); \
+ }
+#define prop_xml_attr_def(t, n, xml, x_path, attr, _default) { \
+ gchar *xxxs = xml_file_get_node_attribute_with_default (xml, x_path, attr, _default); \
+ properties_table_add_string (t, n, xxxs); \
+ g_free (xxxs); \
+ }
+
+#define prop_xml_attr_long(t, n, xml, x_path, attr) { \
+ long int xxxi; \
+ if (xml_file_get_node_attribute_long (xml, x_path, attr, &xxxi)) \
+ properties_table_add_int (t, n, xxxi); \
+ }
+#define prop_xml_attr_long_def(t, n, xml, x_path, attr, _default) \
+ properties_table_add_int (t, n, xml_file_get_node_attribute_long_with_default (xml, x_path, attr, _default))
+
+#define prop_xml_attr_bool(t, n, xml, x_path, attr) { \
+ gboolean xxxb; \
+ if (xml_file_get_node_attribute_boolean (xml, x_path, attr, &xxxb)) \
+ properties_table_add_bool (t, n, xxxb); \
+ }
+#define prop_xml_attr_bool_def(t, n, xml, x_path, attr, _default) \
+ properties_table_add_bool (t, n, xml_file_get_node_attribute_boolean_with_default (xml, x_path, attr, _default))
+
+#define prop_xml_attr_double(t, n, xml, x_path, attr) { \
+ double xxxd; \
+ if (xml_file_get_node_attribute_double (xml, x_path, attr, &xxxd)) \
+ properties_table_add_double (t, n, xxxd); \
+ }
+#define prop_xml_attr_double_def(t, n, xml, x_path, attr, _default) \
+ properties_table_add_double (t, n, xml_file_get_node_attribute_double_with_default (xml, x_path, attr, _default))
+
+
+
G_END_DECLS
#endif /* __CGG__XML_PARSER_H__ */