From d457446041b634e650d95539ad44f553c1eee6e1 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 23 Nov 2012 06:14:56 +0000 Subject: 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 --- NEWS | 1 + lilv/lilv.h | 17 +++++++++++++++++ src/world.c | 11 +++++++++++ test/lilv_test.c | 8 ++++++++ 4 files changed, 37 insertions(+) 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 @@ -649,6 +649,23 @@ lilv_world_find_nodes(LilvWorld* world, const LilvNode* predicate, 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)); -- cgit v1.2.1