summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-30 22:18:41 +0000
committerDavid Robillard <d@drobilla.net>2011-01-30 22:18:41 +0000
commitd136e0bbd0f0d30a1a6d519462f4ad7bee4812b1 (patch)
treee526472cf21ba671e7ec675033b8b70669724459
parentd2ca87e3f2b8e38222f9c2a9f3235e4d270528c7 (diff)
downloadlilv-d136e0bbd0f0d30a1a6d519462f4ad7bee4812b1.tar.gz
lilv-d136e0bbd0f0d30a1a6d519462f4ad7bee4812b1.tar.bz2
lilv-d136e0bbd0f0d30a1a6d519462f4ad7bee4812b1.zip
Completely abstract away use of librdf_stream for statement matching.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2876 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/plugin.c42
-rw-r--r--src/port.c36
-rw-r--r--src/query.c13
-rw-r--r--src/slv2_internal.h24
-rw-r--r--src/world.c76
5 files changed, 95 insertions, 96 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 6f68102..9f3248b 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -114,10 +114,10 @@ static SLV2Values
slv2_plugin_query_node(SLV2Plugin p, librdf_node* subject, librdf_node* predicate)
{
// <subject> <predicate> ?value
- librdf_stream* results = slv2_plugin_find_statements(
+ SLV2Matches results = slv2_plugin_find_statements(
p, subject, predicate, NULL);
- if (librdf_stream_end(results)) {
+ if (slv2_matches_end(results)) {
return NULL;
}
@@ -173,7 +173,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
p->ports = malloc(sizeof(SLV2Port*));
p->ports[0] = NULL;
- librdf_stream* ports = slv2_plugin_find_statements(
+ SLV2Matches ports = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
librdf_new_node_from_node(p->world->lv2_port_node),
@@ -222,7 +222,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
p->ports[this_index] = this_port;
}
- librdf_stream* types = slv2_plugin_find_statements(
+ SLV2Matches types = slv2_plugin_find_statements(
p,
librdf_new_node_from_node(port),
librdf_new_node_from_node(p->world->rdf_a_node),
@@ -337,7 +337,7 @@ slv2_plugin_get_library_uri(SLV2Plugin p)
slv2_plugin_load_if_necessary(p);
if (!p->binary_uri) {
// <plugin> lv2:binary ?binary
- librdf_stream* results = slv2_plugin_find_statements(
+ SLV2Matches results = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
librdf_new_node_from_node(p->world->lv2_binary_node),
@@ -370,7 +370,7 @@ slv2_plugin_get_class(SLV2Plugin p)
slv2_plugin_load_if_necessary(p);
if (!p->plugin_class) {
// <plugin> a ?class
- librdf_stream* results = slv2_plugin_find_statements(
+ SLV2Matches results = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
librdf_new_node_from_node(p->world->rdf_a_node),
@@ -504,7 +504,7 @@ slv2_plugin_get_value_by_qname_i18n(SLV2Plugin p,
librdf_node* pred_node = librdf_new_node_from_uri_string(
p->world->world, (const uint8_t*)pred_uri);
- librdf_stream* results = slv2_plugin_find_statements(
+ SLV2Matches results = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
pred_node,
@@ -613,7 +613,7 @@ slv2_plugin_get_num_ports_of_class(SLV2Plugin p,
bool
slv2_plugin_has_latency(SLV2Plugin p)
{
- librdf_stream* ports = slv2_plugin_find_statements(
+ SLV2Matches ports = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
librdf_new_node_from_node(p->world->lv2_port_node),
@@ -621,15 +621,15 @@ slv2_plugin_has_latency(SLV2Plugin p)
bool ret = false;
FOREACH_MATCH(ports) {
- librdf_node* port = MATCH_OBJECT(ports);
- librdf_stream* reports_latency = slv2_plugin_find_statements(
+ librdf_node* port = MATCH_OBJECT(ports);
+ SLV2Matches reports_latency = slv2_plugin_find_statements(
p,
librdf_new_node_from_node(port),
librdf_new_node_from_node(p->world->lv2_portproperty_node),
librdf_new_node_from_uri_string(p->world->world,
SLV2_NS_LV2 "reportsLatency"));
- if (!librdf_stream_end(reports_latency)) {
+ if (!slv2_matches_end(reports_latency)) {
ret = true;
break;
}
@@ -645,7 +645,7 @@ slv2_plugin_has_latency(SLV2Plugin p)
uint32_t
slv2_plugin_get_latency_port_index(SLV2Plugin p)
{
- librdf_stream* ports = slv2_plugin_find_statements(
+ SLV2Matches ports = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
librdf_new_node_from_node(p->world->lv2_port_node),
@@ -653,15 +653,15 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p)
uint32_t ret = 0;
FOREACH_MATCH(ports) {
- librdf_node* port = MATCH_OBJECT(ports);
- librdf_stream* reports_latency = slv2_plugin_find_statements(
+ librdf_node* port = MATCH_OBJECT(ports);
+ SLV2Matches reports_latency = slv2_plugin_find_statements(
p,
librdf_new_node_from_node(port),
librdf_new_node_from_node(p->world->lv2_portproperty_node),
librdf_new_node_from_uri_string(p->world->world,
SLV2_NS_LV2 "reportsLatency"));
- if (!librdf_stream_end(reports_latency)) {
+ if (!slv2_matches_end(reports_latency)) {
SLV2Value index = slv2_plugin_get_unique(
p,
librdf_new_node_from_node(port),
@@ -758,19 +758,17 @@ slv2_plugin_get_port_by_symbol(SLV2Plugin p,
static librdf_node*
slv2_plugin_get_author(SLV2Plugin p)
{
-
- librdf_stream* maintainers = slv2_plugin_find_statements(
+ SLV2Matches maintainers = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
librdf_new_node_from_uri_string(p->world->world, NS_DOAP "maintainer"),
NULL);
- if (librdf_stream_end(maintainers)) {
+ if (slv2_matches_end(maintainers)) {
return NULL;
}
- librdf_node* author = librdf_new_node_from_node(
- librdf_statement_get_object(librdf_stream_get_object(maintainers)));
+ librdf_node* author = librdf_new_node_from_node(MATCH_OBJECT(maintainers));
librdf_free_stream(maintainers);
return author;
@@ -821,8 +819,8 @@ slv2_plugin_get_uis(SLV2Plugin p)
{
#define NS_UI (const uint8_t*)"http://lv2plug.in/ns/extensions/ui#"
- SLV2UIs result = slv2_uis_new();
- librdf_stream* uis = slv2_plugin_find_statements(
+ SLV2UIs result = slv2_uis_new();
+ SLV2Matches uis = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
librdf_new_node_from_uri_string(p->world->world, NS_UI "ui"),
diff --git a/src/port.c b/src/port.c
index f8f2c10..28a5036 100644
--- a/src/port.c
+++ b/src/port.c
@@ -68,7 +68,7 @@ static librdf_node*
slv2_port_get_node(SLV2Plugin p,
SLV2Port port)
{
- librdf_stream* ports = slv2_plugin_find_statements(
+ SLV2Matches ports = slv2_plugin_find_statements(
p,
librdf_new_node_from_uri(p->world->world, p->plugin_uri->val.uri_val),
librdf_new_node_from_node(p->world->lv2_port_node),
@@ -98,14 +98,14 @@ slv2_port_has_property(SLV2Plugin p,
SLV2Value property)
{
assert(property);
- librdf_node* port_node = slv2_port_get_node(p, port);
- librdf_stream* results = slv2_plugin_find_statements(
+ librdf_node* port_node = slv2_port_get_node(p, port);
+ SLV2Matches results = slv2_plugin_find_statements(
p,
port_node,
librdf_new_node_from_uri_string(p->world->world, SLV2_NS_LV2 "portProperty"),
librdf_new_node_from_uri(p->world->world, slv2_value_as_librdf_uri(property)));
- const bool ret = !librdf_stream_end(results);
+ const bool ret = !slv2_matches_end(results);
librdf_free_stream(results);
return ret;
}
@@ -119,23 +119,23 @@ slv2_port_supports_event(SLV2Plugin p,
#define NS_EV (const uint8_t*)"http://lv2plug.in/ns/ext/event#"
assert(event);
- librdf_node* port_node = slv2_port_get_node(p, port);
- librdf_stream* results = slv2_plugin_find_statements(
+ librdf_node* port_node = slv2_port_get_node(p, port);
+ SLV2Matches results = slv2_plugin_find_statements(
p,
port_node,
librdf_new_node_from_uri_string(p->world->world, NS_EV "supportsEvent"),
librdf_new_node_from_uri(p->world->world, slv2_value_as_librdf_uri(event)));
- const bool ret = !librdf_stream_end(results);
+ const bool ret = !slv2_matches_end(results);
librdf_free_stream(results);
return ret;
}
static SLV2Values
-slv2_values_from_stream_objects(SLV2Plugin p, librdf_stream* stream)
+slv2_values_from_stream_objects(SLV2Plugin p, SLV2Matches stream)
{
- if (librdf_stream_end(stream)) {
+ if (slv2_matches_end(stream)) {
return NULL;
}
@@ -163,8 +163,8 @@ slv2_port_get_value_by_qname(SLV2Plugin p,
return NULL;
}
- librdf_node* port_node = slv2_port_get_node(p, port);
- librdf_stream* results = slv2_plugin_find_statements(
+ librdf_node* port_node = slv2_port_get_node(p, port);
+ SLV2Matches results = slv2_plugin_find_statements(
p,
port_node,
librdf_new_node_from_uri_string(p->world->world, (const uint8_t*)pred_uri),
@@ -181,8 +181,8 @@ slv2_port_get_value_by_node(SLV2Plugin p,
{
assert(librdf_node_is_resource(predicate));
- librdf_node* port_node = slv2_port_get_node(p, port);
- librdf_stream* results = slv2_plugin_find_statements(
+ librdf_node* port_node = slv2_port_get_node(p, port);
+ SLV2Matches results = slv2_plugin_find_statements(
p,
port_node,
predicate,
@@ -220,8 +220,8 @@ slv2_port_get_value_by_qname_i18n(SLV2Plugin p,
return NULL;
}
- librdf_node* port_node = slv2_port_get_node(p, port);
- librdf_stream* results = slv2_plugin_find_statements(
+ librdf_node* port_node = slv2_port_get_node(p, port);
+ SLV2Matches results = slv2_plugin_find_statements(
p,
port_node,
librdf_new_node_from_uri_string(p->world->world, (const uint8_t*)pred_uri),
@@ -306,15 +306,15 @@ SLV2ScalePoints
slv2_port_get_scale_points(SLV2Plugin p,
SLV2Port port)
{
- librdf_node* port_node = slv2_port_get_node(p, port);
- librdf_stream* points = slv2_plugin_find_statements(
+ librdf_node* port_node = slv2_port_get_node(p, port);
+ SLV2Matches points = slv2_plugin_find_statements(
p,
port_node,
librdf_new_node_from_uri_string(p->world->world, SLV2_NS_LV2 "scalePoint"),
NULL);
SLV2ScalePoints ret = NULL;
- if (!librdf_stream_end(points))
+ if (!slv2_matches_end(points))
ret = slv2_scale_points_new();
FOREACH_MATCH(points) {
diff --git a/src/query.c b/src/query.c
index 187bf5d..ac49ece 100644
--- a/src/query.c
+++ b/src/query.c
@@ -29,7 +29,7 @@
#include "slv2_internal.h"
-librdf_stream*
+SLV2Matches
slv2_plugin_find_statements(SLV2Plugin plugin,
librdf_node* subject,
librdf_node* predicate,
@@ -45,14 +45,13 @@ slv2_plugin_find_statements(SLV2Plugin plugin,
SLV2Values
-slv2_values_from_stream_i18n(SLV2Plugin p,
- librdf_stream* stream)
+slv2_values_from_stream_i18n(SLV2Plugin p,
+ SLV2Matches stream)
{
SLV2Values values = slv2_values_new();
librdf_node* nolang = NULL;
- for (; !librdf_stream_end(stream); librdf_stream_next(stream)) {
- librdf_statement* s = librdf_stream_get_object(stream);
- librdf_node* value = librdf_statement_get_object(s);
+ FOREACH_MATCH(stream) {
+ librdf_node* value = MATCH_OBJECT(stream);
if (librdf_node_is_literal(value)) {
const char* lang = librdf_node_get_literal_value_language(value);
if (lang) {
@@ -67,7 +66,7 @@ slv2_values_from_stream_i18n(SLV2Plugin p,
}
break;
}
- librdf_free_stream(stream);
+ END_MATCH(stream);
if (slv2_values_size(values) == 0) {
// No value with a matching language, use untranslated default
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index 35a8f12..2d161cb 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -95,11 +95,6 @@ void slv2_plugin_load_if_necessary(SLV2Plugin p);
void slv2_plugin_load_ports_if_necessary(SLV2Plugin p);
void slv2_plugin_free(SLV2Plugin plugin);
-librdf_stream* slv2_plugin_find_statements(SLV2Plugin plugin,
- librdf_node* subject,
- librdf_node* predicate,
- librdf_node* object);
-
SLV2Value
slv2_plugin_get_unique(SLV2Plugin p,
librdf_node* subject,
@@ -279,8 +274,23 @@ void slv2_scale_point_free(SLV2ScalePoint point);
/* ********* Query Results********* */
-SLV2Values slv2_values_from_stream_i18n(SLV2Plugin p,
- librdf_stream* stream);
+typedef librdf_stream* SLV2Matches;
+
+SLV2Matches slv2_plugin_find_statements(SLV2Plugin plugin,
+ librdf_node* subject,
+ librdf_node* predicate,
+ librdf_node* object);
+
+static inline bool slv2_matches_next(SLV2Matches matches) {
+ return librdf_stream_next(matches);
+}
+
+static inline bool slv2_matches_end(SLV2Matches matches) {
+ return librdf_stream_end(matches);
+}
+
+SLV2Values slv2_values_from_stream_i18n(SLV2Plugin p,
+ SLV2Matches stream);
/* ********* Utilities ********* */
diff --git a/src/world.c b/src/world.c
index ace5de3..01d05cd 100644
--- a/src/world.c
+++ b/src/world.c
@@ -220,7 +220,7 @@ slv2_world_load_file(SLV2World world, librdf_uri* file_uri)
librdf_parser_parse_into_model(world->parser, file_uri, file_uri, world->model);
}
-static librdf_stream*
+static SLV2Matches
slv2_world_find_statements(SLV2World world,
librdf_model* model,
librdf_node* subject,
@@ -229,7 +229,7 @@ slv2_world_find_statements(SLV2World world,
{
librdf_statement* q = librdf_new_statement_from_nodes(
world->world, subject, predicate, object);
- librdf_stream* results = librdf_model_find_statements(model, q);
+ SLV2Matches results = librdf_model_find_statements(model, q);
librdf_free_statement(q);
return results;
}
@@ -257,28 +257,26 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
typedef void* LV2_Dyn_Manifest_Handle;
LV2_Dyn_Manifest_Handle handle = NULL;
- librdf_stream* dmanifests = slv2_world_find_statements(
+ SLV2Matches dmanifests = slv2_world_find_statements(
world, world->model,
NULL,
librdf_new_node_from_node(world->rdf_a_node),
librdf_new_node_from_node(world->dyn_manifest_node));
FOREACH_MATCH(dmanifests) {
- librdf_node* dmanifest = MATCH_SUBJECT(dmanifests);
- librdf_stream* binaries = slv2_world_find_statements(
+ librdf_node* dmanifest = MATCH_SUBJECT(dmanifests);
+ SLV2Matches binaries = slv2_world_find_statements(
world, world->model,
librdf_new_node_from_node(dmanifest),
librdf_new_node_from_node(world->lv2_binary_node),
NULL);
- if (librdf_stream_end(binaries)) {
- librdf_free_stream(binaries);
+ if (slv2_matches_end(binaries)) {
+ END_MATCH(binaries);
SLV2_ERRORF("Dynamic manifest in <%s> has no binaries, ignored\n",
slv2_value_as_uri(bundle_uri));
continue;
}
- librdf_node* binary_node = librdf_new_node_from_node(
- librdf_statement_get_object(
- librdf_stream_get_object(binaries)));
+ librdf_node* binary_node = librdf_new_node_from_node(MATCH_OBJECT(binaries));
librdf_uri* binary_uri = librdf_node_get_uri(binary_node);
const uint8_t* lib_uri = librdf_uri_as_string(binary_uri);
@@ -315,7 +313,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
fclose(fd);
// ?plugin a lv2:Plugin
- librdf_stream* dyn_plugins = slv2_world_find_statements(
+ SLV2Matches dyn_plugins = slv2_world_find_statements(
world, dyn_manifest_model,
NULL,
librdf_new_node_from_node(world->rdf_a_node),
@@ -342,7 +340,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
#endif // SLV2_DYN_MANIFEST
// ?plugin a lv2:Plugin
- librdf_stream* results = slv2_world_find_statements(
+ SLV2Matches results = slv2_world_find_statements(
world, manifest_model,
NULL,
librdf_new_node_from_node(world->rdf_a_node),
@@ -486,7 +484,7 @@ slv2_plugin_class_compare_by_uri(const void* a, const void* b)
void
slv2_world_load_specifications(SLV2World world)
{
- librdf_stream* specs = slv2_world_find_statements(
+ SLV2Matches specs = slv2_world_find_statements(
world, world->model,
NULL,
librdf_new_node_from_node(world->rdf_a_node),
@@ -494,7 +492,7 @@ slv2_world_load_specifications(SLV2World world)
FOREACH_MATCH(specs) {
librdf_node* spec_node = MATCH_SUBJECT(specs);
- librdf_stream* files = slv2_world_find_statements(
+ SLV2Matches files = slv2_world_find_statements(
world, world->model,
librdf_new_node_from_node(spec_node),
librdf_new_node_from_node(world->rdfs_seealso_node),
@@ -520,7 +518,7 @@ slv2_world_load_plugin_classes(SLV2World world)
a menu), they won't be seen anyway...
*/
- librdf_stream* classes = slv2_world_find_statements(
+ SLV2Matches classes = slv2_world_find_statements(
world, world->model,
NULL,
librdf_new_node_from_node(world->rdf_a_node),
@@ -530,39 +528,35 @@ slv2_world_load_plugin_classes(SLV2World world)
librdf_uri* class_uri = librdf_node_get_uri(class_node);
// Get parents (superclasses)
- librdf_stream* parents = slv2_world_find_statements(
+ SLV2Matches parents = slv2_world_find_statements(
world, world->model,
librdf_new_node_from_node(class_node),
librdf_new_node_from_node(world->rdfs_subclassof_node),
NULL);
- if (librdf_stream_end(parents)) {
- librdf_free_stream(parents);
+ if (slv2_matches_end(parents)) {
+ END_MATCH(parents);
continue;
}
- librdf_node* parent_node = librdf_new_node_from_node(
- librdf_statement_get_object(
- librdf_stream_get_object(parents)));
- librdf_uri* parent_uri = librdf_node_get_uri(parent_node);
+ librdf_node* parent_node = librdf_new_node_from_node(MATCH_OBJECT(parents));
+ librdf_uri* parent_uri = librdf_node_get_uri(parent_node);
librdf_free_stream(parents);
// Get labels
- librdf_stream* labels = slv2_world_find_statements(
+ SLV2Matches labels = slv2_world_find_statements(
world, world->model,
librdf_new_node_from_node(class_node),
librdf_new_node_from_node(world->rdfs_label_node),
NULL);
- if (librdf_stream_end(labels)) {
+ if (slv2_matches_end(labels)) {
librdf_free_stream(labels);
continue;
}
- librdf_node* label_node = librdf_new_node_from_node(
- librdf_statement_get_object(
- librdf_stream_get_object(labels)));
- const uint8_t* label = librdf_node_get_literal_value(label_node);
+ librdf_node* label_node = librdf_new_node_from_node(MATCH_OBJECT(labels));
+ const uint8_t* label = librdf_node_get_literal_value(label_node);
librdf_free_stream(labels);
SLV2PluginClasses classes = world->plugin_classes;
@@ -638,7 +632,7 @@ slv2_world_load_all(SLV2World world)
slv2_world_load_plugin_classes(world);
- librdf_stream* plugins = slv2_world_find_statements(
+ SLV2Matches plugins = slv2_world_find_statements(
world, world->model,
NULL,
librdf_new_node_from_node(world->rdf_a_node),
@@ -647,27 +641,25 @@ slv2_world_load_all(SLV2World world)
librdf_node* plugin_node = MATCH_SUBJECT(plugins);
librdf_uri* plugin_uri = librdf_node_get_uri(plugin_node);
- librdf_stream* bundles = slv2_world_find_statements(
+ SLV2Matches bundles = slv2_world_find_statements(
world, world->model,
librdf_new_node_from_node(plugin_node),
librdf_new_node_from_node(world->slv2_bundleuri_node),
NULL);
- if (librdf_stream_end(bundles)) {
- librdf_free_stream(bundles);
+ if (slv2_matches_end(bundles)) {
+ END_MATCH(bundles);
SLV2_ERRORF("Plugin <%s> somehow has no bundle, ignored\n",
librdf_uri_as_string(plugin_uri));
continue;
}
- librdf_node* bundle_node = librdf_new_node_from_node(
- librdf_statement_get_object(
- librdf_stream_get_object(bundles)));
- librdf_uri* bundle_uri = librdf_node_get_uri(bundle_node);
-
- librdf_stream_next(bundles);
- if (!librdf_stream_end(bundles)) {
- librdf_free_stream(bundles);
+ librdf_node* bundle_node = librdf_new_node_from_node(MATCH_OBJECT(bundles));
+ librdf_uri* bundle_uri = librdf_node_get_uri(bundle_node);
+
+ slv2_matches_next(bundles);
+ if (!slv2_matches_end(bundles)) {
+ END_MATCH(bundles);
SLV2_ERRORF("Plugin <%s> found in several bundles, ignored\n",
librdf_uri_as_string(plugin_uri));
continue;
@@ -693,7 +685,7 @@ slv2_world_load_all(SLV2World world)
#ifdef SLV2_DYN_MANIFEST
{
- librdf_stream* dmanifests = slv2_world_find_statements(
+ SLV2Matches dmanifests = slv2_world_find_statements(
world, world->model,
librdf_new_node_from_node(plugin_node),
librdf_new_node_from_node(world->slv2_dmanifest_node),
@@ -711,7 +703,7 @@ slv2_world_load_all(SLV2World world)
END_MATCH(dmanifests);
}
#endif
- librdf_stream* files = slv2_world_find_statements(
+ SLV2Matches files = slv2_world_find_statements(
world, world->model,
librdf_new_node_from_node(plugin_node),
librdf_new_node_from_node(world->rdfs_seealso_node),