summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-30 05:28:32 +0000
committerDavid Robillard <d@drobilla.net>2011-01-30 05:28:32 +0000
commitc5f3bb2fa81d443c3475c0df2b9e6f14d02f2cc8 (patch)
tree2c26bc1218d852b8b5196116d40c17e8fbd5d3a5
parent73d4c34f7756a36c078a11c639328a7eef474ecb (diff)
downloadlilv-c5f3bb2fa81d443c3475c0df2b9e6f14d02f2cc8.tar.gz
lilv-c5f3bb2fa81d443c3475c0df2b9e6f14d02f2cc8.tar.bz2
lilv-c5f3bb2fa81d443c3475c0df2b9e6f14d02f2cc8.zip
Wrap stream iteration in macros.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2869 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/plugin.c33
-rw-r--r--src/port.c11
-rw-r--r--src/slv2_internal.h5
-rw-r--r--src/world.c40
4 files changed, 48 insertions, 41 deletions
diff --git a/src/plugin.c b/src/plugin.c
index 1caf792..3e6f61d 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -123,7 +123,7 @@ slv2_plugin_query_node(SLV2Plugin p, librdf_node* subject, librdf_node* predicat
}
SLV2Values result = slv2_values_new();
- for (; !librdf_stream_end(results); librdf_stream_next(results)) {
+ FOREACH_MATCH(results) {
librdf_statement* s = librdf_stream_get_object(results);
librdf_node* value_node = librdf_statement_get_object(s);
@@ -131,8 +131,8 @@ slv2_plugin_query_node(SLV2Plugin p, librdf_node* subject, librdf_node* predicat
if (value)
raptor_sequence_push(result, value);
}
-
- librdf_free_stream(results);
+ END_MATCH(results);
+
return result;
}
@@ -182,7 +182,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
librdf_new_node_from_node(p->world->lv2_port_node),
NULL);
- for (; !librdf_stream_end(ports); librdf_stream_next(ports)) {
+ FOREACH_MATCH(ports) {
librdf_statement* s = librdf_stream_get_object(ports);
librdf_node* port = librdf_statement_get_object(s);
@@ -232,7 +232,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
librdf_new_node_from_node(port),
librdf_new_node_from_node(p->world->rdf_a_node),
NULL);
- for (; !librdf_stream_end(types); librdf_stream_next(types)) {
+ FOREACH_MATCH(types) {
librdf_node* type = librdf_statement_get_object(
librdf_stream_get_object(types));
if (librdf_node_is_resource(type)) {
@@ -243,7 +243,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
SLV2_WARN("port has non-URI rdf:type\n");
}
}
- librdf_free_stream(types);
+ END_MATCH(types);
error:
slv2_value_free(symbol);
@@ -258,7 +258,7 @@ slv2_plugin_load_ports_if_necessary(SLV2Plugin p)
break; // Invalid plugin
}
}
- librdf_free_stream(ports);
+ END_MATCH(ports);
}
}
@@ -348,7 +348,7 @@ slv2_plugin_get_library_uri(SLV2Plugin 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),
NULL);
- for (; !librdf_stream_end(results); librdf_stream_next(results)) {
+ FOREACH_MATCH(results) {
librdf_statement* s = librdf_stream_get_object(results);
librdf_node* binary_node = librdf_statement_get_object(s);
librdf_uri* binary_uri = librdf_node_get_uri(binary_node);
@@ -358,7 +358,7 @@ slv2_plugin_get_library_uri(SLV2Plugin p)
break;
}
}
- librdf_free_stream(results);
+ END_MATCH(results);
}
return p->binary_uri;
}
@@ -382,7 +382,7 @@ slv2_plugin_get_class(SLV2Plugin 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),
NULL);
- for (; !librdf_stream_end(results); librdf_stream_next(results)) {
+ FOREACH_MATCH(results) {
librdf_statement* s = librdf_stream_get_object(results);
librdf_node* class_node = librdf_new_node_from_node(librdf_statement_get_object(s));
librdf_uri* class_uri = librdf_node_get_uri(class_node);
@@ -409,11 +409,10 @@ slv2_plugin_get_class(SLV2Plugin p)
slv2_value_free(class);
}
+ END_MATCH(results);
if (p->plugin_class == NULL)
p->plugin_class = p->world->lv2_plugin_class;
-
- librdf_free_stream(results);
}
return p->plugin_class;
}
@@ -639,7 +638,7 @@ slv2_plugin_has_latency(SLV2Plugin p)
NULL);
bool ret = false;
- for (; !librdf_stream_end(ports); librdf_stream_next(ports)) {
+ FOREACH_MATCH(ports) {
librdf_statement* s = librdf_stream_get_object(ports);
librdf_node* port = librdf_statement_get_object(s);
@@ -657,6 +656,7 @@ slv2_plugin_has_latency(SLV2Plugin p)
librdf_free_stream(reports_latency);
}
+ END_MATCH(ports);
return ret;
}
@@ -672,7 +672,7 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p)
NULL);
uint32_t ret = 0;
- for (; !librdf_stream_end(ports); librdf_stream_next(ports)) {
+ FOREACH_MATCH(ports) {
librdf_statement* s = librdf_stream_get_object(ports);
librdf_node* port = librdf_statement_get_object(s);
@@ -693,6 +693,7 @@ slv2_plugin_get_latency_port_index(SLV2Plugin p)
break;
}
}
+ END_MATCH(ports);
return ret; // FIXME: error handling
}
@@ -848,7 +849,7 @@ slv2_plugin_get_uis(SLV2Plugin 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"),
NULL);
- for (; !librdf_stream_end(uis); librdf_stream_next(uis)) {
+ FOREACH_MATCH(uis) {
librdf_statement* s = librdf_stream_get_object(uis);
librdf_node* ui = librdf_statement_get_object(s);
@@ -879,7 +880,7 @@ slv2_plugin_get_uis(SLV2Plugin p)
slv2_value_free(binary);
slv2_value_free(type);
}
- librdf_free_stream(uis);
+ END_MATCH(uis);
if (slv2_uis_size(result) > 0) {
return result;
diff --git a/src/port.c b/src/port.c
index 2902af9..35364a8 100644
--- a/src/port.c
+++ b/src/port.c
@@ -75,7 +75,7 @@ slv2_port_get_node(SLV2Plugin p,
librdf_new_node_from_node(p->world->lv2_port_node),
NULL);
librdf_node* ret = NULL;
- for (; !librdf_stream_end(ports); librdf_stream_next(ports)) {
+ FOREACH_MATCH(ports) {
librdf_statement* s = librdf_stream_get_object(ports);
librdf_node* node = librdf_statement_get_object(s);
@@ -89,6 +89,7 @@ slv2_port_get_node(SLV2Plugin p,
break;
}
}
+ END_MATCH(ports);
assert(ret);
return ret;
}
@@ -142,7 +143,7 @@ slv2_values_from_stream_objects(SLV2Plugin p, librdf_stream* stream)
}
SLV2Values values = slv2_values_new();
- for (; !librdf_stream_end(stream); librdf_stream_next(stream)) {
+ FOREACH_MATCH(stream) {
raptor_sequence_push(
values,
slv2_value_new_librdf_node(
@@ -150,7 +151,7 @@ slv2_values_from_stream_objects(SLV2Plugin p, librdf_stream* stream)
librdf_statement_get_object(
librdf_stream_get_object(stream))));
}
- librdf_free_stream(stream);
+ END_MATCH(stream);
return values;
}
@@ -320,7 +321,7 @@ slv2_port_get_scale_points(SLV2Plugin p,
if (!librdf_stream_end(points))
ret = slv2_scale_points_new();
- for (; !librdf_stream_end(points); librdf_stream_next(points)) {
+ FOREACH_MATCH(points) {
librdf_statement* s = librdf_stream_get_object(points);
librdf_node* point = librdf_statement_get_object(s);
@@ -338,7 +339,7 @@ slv2_port_get_scale_points(SLV2Plugin p,
raptor_sequence_push(ret, slv2_scale_point_new(value, label));
}
}
- librdf_free_stream(points);
+ END_MATCH(points);
assert(!ret || slv2_values_size(ret) > 0);
return ret;
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index 45d3fc7..590c143 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -43,6 +43,11 @@ extern "C" {
#define SLV2_NS_XSD (const uint8_t*)"http://www.w3.org/2001/XMLSchema#"
#define SLV2_NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+#define FOREACH_MATCH(stream) \
+ for (; !librdf_stream_end(stream); librdf_stream_next(stream))
+
+#define END_MATCH(stream) librdf_free_stream(stream)
+
/* ********* PORT ********* */
/** Reference to a port on some plugin. */
diff --git a/src/world.c b/src/world.c
index c47d2e3..e179534 100644
--- a/src/world.c
+++ b/src/world.c
@@ -262,7 +262,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
NULL,
librdf_new_node_from_node(world->rdf_a_node),
librdf_new_node_from_node(world->dyn_manifest_node));
- for (; !librdf_stream_end(dmanifests); librdf_stream_next(dmanifests)) {
+ FOREACH_MATCH(dmanifests) {
librdf_statement* s = librdf_stream_get_object(dmanifests);
librdf_node* dmanifest = librdf_statement_get_subject(s);
@@ -322,7 +322,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
NULL,
librdf_new_node_from_node(world->rdf_a_node),
librdf_new_node_from_node(world->lv2_plugin_node));
- for (; !librdf_stream_end(dyn_plugins); librdf_stream_next(dyn_plugins)) {
+ FOREACH_MATCH(dyn_plugins) {
librdf_statement* s = librdf_stream_get_object(dyn_plugins);
librdf_node* plugin = librdf_statement_get_subject(s);
@@ -332,7 +332,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_new_node_from_uri_string(world->world, SLV2_NS_RDFS "seeAlso"),
librdf_new_node_from_node(binary_node));
}
- librdf_free_stream(dyn_plugins);
+ END_MATCH(dyn_plugins);
// Merge dynamic model into main manifest model
librdf_stream* dyn_manifest_stream = librdf_model_as_stream(dyn_manifest_model);
@@ -341,7 +341,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_free_model(dyn_manifest_model);
librdf_free_storage(dyn_manifest_storage);
}
- librdf_free_stream(dmanifests);
+ END_MATCH(dmanifests);
#endif // SLV2_DYN_MANIFEST
// ?plugin a lv2:Plugin
@@ -350,7 +350,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
NULL,
librdf_new_node_from_node(world->rdf_a_node),
librdf_new_node_from_node(world->lv2_plugin_node));
- for (; !librdf_stream_end(results); librdf_stream_next(results)) {
+ FOREACH_MATCH(results) {
librdf_statement* s = librdf_stream_get_object(results);
librdf_node* plugin = librdf_statement_get_subject(s);
@@ -368,7 +368,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_new_node_from_uri_string(world->world, SLV2_NS_SLV2 "bundleURI"),
librdf_new_node_from_uri(world->world, bundle_uri->val.uri_val));
}
- librdf_free_stream(results);
+ END_MATCH(results);
// ?specification a lv2:Specification
results = slv2_world_find_statements(
@@ -376,7 +376,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
NULL,
librdf_new_node_from_node(world->rdf_a_node),
librdf_new_node_from_node(world->lv2_specification_node));
- for (; !librdf_stream_end(results); librdf_stream_next(results)) {
+ FOREACH_MATCH(results) {
librdf_statement* s = librdf_stream_get_object(results);
librdf_node* spec = librdf_statement_get_subject(s);
@@ -394,7 +394,7 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri)
librdf_new_node_from_uri_string(world->world, SLV2_NS_SLV2 "bundleURI"),
librdf_new_node_from_uri(world->world, bundle_uri->val.uri_val));
}
- librdf_free_stream(results);
+ END_MATCH(results);
// Join the temporary model to the main model
librdf_stream* manifest_stream = librdf_model_as_stream(manifest_model);
@@ -496,7 +496,7 @@ slv2_world_load_specifications(SLV2World world)
NULL,
librdf_new_node_from_node(world->rdf_a_node),
librdf_new_node_from_node(world->lv2_specification_node));
- for (; !librdf_stream_end(specs); librdf_stream_next(specs)) {
+ FOREACH_MATCH(specs) {
librdf_statement* s = librdf_stream_get_object(specs);
librdf_node* spec_node = librdf_statement_get_subject(s);
@@ -505,16 +505,16 @@ slv2_world_load_specifications(SLV2World world)
librdf_new_node_from_node(spec_node),
librdf_new_node_from_node(world->rdfs_seealso_node),
NULL);
- for (; !librdf_stream_end(files); librdf_stream_next(files)) {
+ FOREACH_MATCH(files) {
librdf_statement* t = librdf_stream_get_object(files);
librdf_node* file_node = librdf_statement_get_object(t);
librdf_uri* file_uri = librdf_node_get_uri(file_node);
slv2_world_load_file(world, file_uri);
}
- librdf_free_stream(files);
+ END_MATCH(files);
}
- librdf_free_stream(specs);
+ END_MATCH(specs);
}
@@ -532,7 +532,7 @@ slv2_world_load_plugin_classes(SLV2World world)
NULL,
librdf_new_node_from_node(world->rdf_a_node),
librdf_new_node_from_node(world->rdfs_class_node));
- for (; !librdf_stream_end(classes); librdf_stream_next(classes)) {
+ FOREACH_MATCH(classes) {
librdf_statement* s = librdf_stream_get_object(classes);
librdf_node* class_node = librdf_statement_get_subject(s);
librdf_uri* class_uri = librdf_node_get_uri(class_node);
@@ -591,7 +591,7 @@ slv2_world_load_plugin_classes(SLV2World world)
librdf_free_node(parent_node);
librdf_free_node(label_node);
}
- librdf_free_stream(classes);
+ END_MATCH(classes);
}
@@ -651,7 +651,7 @@ slv2_world_load_all(SLV2World world)
NULL,
librdf_new_node_from_node(world->rdf_a_node),
librdf_new_node_from_node(world->lv2_plugin_node));
- for (; !librdf_stream_end(plugins); librdf_stream_next(plugins)) {
+ FOREACH_MATCH(plugins) {
librdf_statement* s = librdf_stream_get_object(plugins);
librdf_node* plugin_node = librdf_statement_get_subject(s);
librdf_uri* plugin_uri = librdf_node_get_uri(plugin_node);
@@ -707,7 +707,7 @@ slv2_world_load_all(SLV2World world)
librdf_new_node_from_node(plugin_node),
librdf_new_node_from_node(world->slv2_dmanifest_node),
NULL);
- for (; !librdf_stream_end(dmanifests); librdf_stream_next(dmanifests)) {
+ FOREACH_MATCH(dmanifests) {
librdf_statement* s = librdf_stream_get_object(dmanifests);
librdf_node* lib_node = librdf_statement_get_object(s);
librdf_uri* lib_uri = librdf_node_get_uri(lib_node);
@@ -718,7 +718,7 @@ slv2_world_load_all(SLV2World world)
plugin->dynman_uri = slv2_value_new_librdf_uri(world, lib_uri);
}
}
- librdf_free_stream(dmanifests);
+ END_MATCH(dmanifests);
}
#endif
librdf_stream* files = slv2_world_find_statements(
@@ -726,7 +726,7 @@ slv2_world_load_all(SLV2World world)
librdf_new_node_from_node(plugin_node),
librdf_new_node_from_node(world->rdfs_seealso_node),
NULL);
- for (; !librdf_stream_end(files); librdf_stream_next(files)) {
+ FOREACH_MATCH(files) {
librdf_statement* s = librdf_stream_get_object(files);
librdf_node* file_node = librdf_statement_get_object(s);
librdf_uri* file_uri = librdf_node_get_uri(file_node);
@@ -734,11 +734,11 @@ slv2_world_load_all(SLV2World world)
raptor_sequence_push(plugin->data_uris,
slv2_value_new_librdf_uri(world, file_uri));
}
- librdf_free_stream(files);
+ END_MATCH(files);
librdf_free_node(bundle_node);
}
- librdf_free_stream(plugins);
+ END_MATCH(plugins);
}