summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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