summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-09-08 01:11:31 +0000
committerDavid Robillard <d@drobilla.net>2007-09-08 01:11:31 +0000
commitb1d0c86db891dabb77fbc9655e7e5d5740ccf701 (patch)
tree8662547873719a803438efbd9958abd7f788d2d8
parenta6eadd534d1a3971cac14a1073ad6e29a3d88751 (diff)
downloadraul-b1d0c86db891dabb77fbc9655e7e5d5740ccf701.tar.gz
raul-b1d0c86db891dabb77fbc9655e7e5d5740ccf701.tar.bz2
raul-b1d0c86db891dabb77fbc9655e7e5d5740ccf701.zip
Pretty RDF boolean reading.
git-svn-id: http://svn.drobilla.net/lad/raul@699 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--raul/RDFNode.hpp3
-rw-r--r--src/RDFNode.cpp23
2 files changed, 26 insertions, 0 deletions
diff --git a/raul/RDFNode.hpp b/raul/RDFNode.hpp
index 8a09699..13326f7 100644
--- a/raul/RDFNode.hpp
+++ b/raul/RDFNode.hpp
@@ -67,6 +67,9 @@ public:
bool is_float();
float to_float();
+
+ bool is_bool();
+ float to_bool();
private:
librdf_node* _node;
diff --git a/src/RDFNode.cpp b/src/RDFNode.cpp
index afba06c..a4c672f 100644
--- a/src/RDFNode.cpp
+++ b/src/RDFNode.cpp
@@ -134,6 +134,29 @@ Node::to_float()
return strtod((const char*)librdf_node_get_literal_value(_node), NULL);
}
+bool
+Node::is_bool()
+{
+ if (_node && librdf_node_get_type(_node) == LIBRDF_NODE_TYPE_LITERAL) {
+ librdf_uri* datatype_uri = librdf_node_get_literal_value_datatype_uri(_node);
+ if (datatype_uri && !strcmp((const char*)librdf_uri_as_string(datatype_uri),
+ "http://www.w3.org/2001/XMLSchema#boolean"))
+ return true;
+ }
+ return false;
+}
+
+
+float
+Node::to_bool()
+{
+ assert(is_bool());
+ if (!strcmp((const char*)librdf_node_get_literal_value(_node), "true"))
+ return true;
+ else
+ return false;
+}
+
} // namespace RDF
} // namespace Raul