summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-11-23 06:14:56 +0000
committerDavid Robillard <d@drobilla.net>2012-11-23 06:14:56 +0000
commitd457446041b634e650d95539ad44f553c1eee6e1 (patch)
tree50a53592f935258a67116b258dda8a495b9df57f
parent897d87d03ff35a9b6846364cd1a1cbf6104db6f1 (diff)
downloadlilv-d457446041b634e650d95539ad44f553c1eee6e1.tar.gz
lilv-d457446041b634e650d95539ad44f553c1eee6e1.tar.bz2
lilv-d457446041b634e650d95539ad44f553c1eee6e1.zip
Add lilv_world_ask() for simply checking if a statement exists.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@4862 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--NEWS1
-rw-r--r--lilv/lilv.h17
-rw-r--r--src/world.c11
-rw-r--r--test/lilv_test.c8
4 files changed, 37 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 90f05a8..3ee9bee 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
lilv (0.15.0) unstable;
+ * Add lilv_world_ask() for simply checking if a statement exists.
* Add lilv_nodes_merge().
* Support atom:supports in lilv_port_supports_event().
* Add va_list variant of lilv_plugin_get_num_ports_of_class().
diff --git a/lilv/lilv.h b/lilv/lilv.h
index 1d05883..52e3576 100644
--- a/lilv/lilv.h
+++ b/lilv/lilv.h
@@ -650,6 +650,23 @@ lilv_world_find_nodes(LilvWorld* world,
const LilvNode* object);
/**
+ Return true iff a statement matching a certain pattern exists.
+
+ This is useful for checking if particular statement exists without having to
+ bother with collections and memory management.
+
+ @param subject Subject of statement, or NULL for anything.
+ @param predicate Predicate (key) of statement, or NULL for anything.
+ @param object Object (value) of statement, or NULL for anything.
+*/
+LILV_API
+bool
+lilv_world_ask(LilvWorld* world,
+ const LilvNode* subject,
+ const LilvNode* predicate,
+ const LilvNode* object);
+
+/**
@}
@name Plugin
@{
diff --git a/src/world.c b/src/world.c
index 773a864..a3f59ed 100644
--- a/src/world.c
+++ b/src/world.c
@@ -219,6 +219,17 @@ lilv_world_ask_internal(LilvWorld* world,
return sord_ask(world->model, subject, predicate, object, NULL);
}
+LILV_API
+bool
+lilv_world_ask(LilvWorld* world,
+ const LilvNode* subject,
+ const LilvNode* predicate,
+ const LilvNode* object)
+{
+ return sord_ask(
+ world->model, subject->node, predicate->node, object->node, NULL);
+}
+
LilvNodes*
lilv_world_find_nodes_internal(LilvWorld* world,
const SordNode* subject,
diff --git a/test/lilv_test.c b/test/lilv_test.c
index 0fade61..48fafa5 100644
--- a/test/lilv_test.c
+++ b/test/lilv_test.c
@@ -562,6 +562,14 @@ test_plugin(void)
TEST_ASSERT(!strcmp(lilv_node_as_string(klass_uri),
"http://lv2plug.in/ns/lv2core#CompressorPlugin"));
+ LilvNode* rdf_type = lilv_new_uri(
+ world, "http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
+ TEST_ASSERT(lilv_world_ask(world,
+ lilv_plugin_get_uri(plug),
+ rdf_type,
+ klass_uri));
+ lilv_node_free(rdf_type);
+
const LilvNode* plug_bundle_uri = lilv_plugin_get_bundle_uri(plug);
TEST_ASSERT(!strcmp(lilv_node_as_string(plug_bundle_uri), bundle_dir_uri));