From d8849ba15dff011b2b064429ba53668674d488c0 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 3 Mar 2012 21:44:14 +0000 Subject: Remove pointless wrapper around Sord API. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@4020 a436a847-0d15-0410-975c-d299462d15a1 --- src/lilv_internal.h | 48 +++---------------------------------- src/plugin.c | 48 ++++++++++++++++++------------------- src/port.c | 16 ++++++------- src/query.c | 30 ++++++++++------------- src/state.c | 24 +++++++++---------- src/world.c | 68 ++++++++++++++++++++++++++--------------------------- 6 files changed, 94 insertions(+), 140 deletions(-) (limited to 'src') diff --git a/src/lilv_internal.h b/src/lilv_internal.h index f292d2a..2ebaa0c 100644 --- a/src/lilv_internal.h +++ b/src/lilv_internal.h @@ -297,51 +297,9 @@ lilv_world_query_values_internal(LilvWorld* world, #define FOREACH_MATCH(iter) \ for (; !sord_iter_end(iter); sord_iter_next(iter)) -static inline const SordNode* -lilv_match_subject(SordIter* iter) { - SordQuad tup; - sord_iter_get(iter, tup); - return tup[SORD_SUBJECT]; -} - -static inline const SordNode* -lilv_match_predicate(SordIter* iter) { - SordQuad tup; - sord_iter_get(iter, tup); - return tup[SORD_PREDICATE]; -} - -static inline const SordNode* -lilv_match_object(SordIter* iter) { - SordQuad tup; - sord_iter_get(iter, tup); - return tup[SORD_OBJECT]; -} - -static inline const SordNode* -lilv_match_graph(SordIter* iter) { - SordQuad tup; - sord_iter_get(iter, tup); - return tup[SORD_GRAPH]; -} - -static inline void -lilv_match_end(SordIter* iter) -{ - sord_iter_free(iter); -} - -static inline bool lilv_matches_next(SordIter* matches) { - return sord_iter_next(matches); -} - -static inline bool lilv_matches_end(SordIter* matches) { - return sord_iter_end(matches); -} - -LilvNodes* lilv_nodes_from_stream_objects(LilvWorld* w, - SordIter* stream, - bool object); +LilvNodes* lilv_nodes_from_stream_objects(LilvWorld* w, + SordIter* stream, + SordQuadIndex field); char* lilv_strjoin(const char* first, ...); char* lilv_strdup(const char* str); diff --git a/src/plugin.c b/src/plugin.c index fb396df..164a212 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -107,10 +107,10 @@ lilv_plugin_get_one(const LilvPlugin* p, LilvNode* ret = NULL; SordIter* stream = lilv_world_query_internal( p->world, subject, predicate, NULL); - if (!lilv_matches_end(stream)) { - ret = lilv_node_new_from_node(p->world, lilv_match_object(stream)); + if (!sord_iter_end(stream)) { + ret = lilv_node_new_from_node(p->world, sord_iter_get_node(stream, SORD_OBJECT)); } - lilv_match_end(stream); + sord_iter_free(stream); return ret; } @@ -211,7 +211,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p) NULL); FOREACH_MATCH(ports) { - const SordNode* port = lilv_match_object(ports); + const SordNode* port = sord_iter_get_node(ports, SORD_OBJECT); LilvNode* index = lilv_plugin_get_unique( p, port, p->world->uris.lv2_index); LilvNode* symbol = lilv_plugin_get_unique( @@ -257,7 +257,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p) SordIter* types = lilv_world_query_internal( p->world, port, p->world->uris.rdf_a, NULL); FOREACH_MATCH(types) { - const SordNode* type = lilv_match_object(types); + const SordNode* type = sord_iter_get_node(types, SORD_OBJECT); if (sord_node_get_type(type) == SORD_URI) { zix_tree_insert( (ZixTree*)this_port->classes, @@ -267,7 +267,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p) lilv_node_as_uri(p->plugin_uri)); } } - lilv_match_end(types); + sord_iter_free(types); done: lilv_node_free(symbol); @@ -277,7 +277,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p) break; } } - lilv_match_end(ports); + sord_iter_free(ports); // Check sanity for (uint32_t i = 0; i < p->num_ports; ++i) { @@ -330,13 +330,13 @@ lilv_plugin_get_library_uri(const LilvPlugin* const_p) p->world->uris.lv2_binary, NULL); FOREACH_MATCH(results) { - const SordNode* binary_node = lilv_match_object(results); + const SordNode* binary_node = sord_iter_get_node(results, SORD_OBJECT); if (sord_node_get_type(binary_node) == SORD_URI) { p->binary_uri = lilv_node_new_from_node(p->world, binary_node); break; } } - lilv_match_end(results); + sord_iter_free(results); } if (!p->binary_uri) { LILV_WARNF("Plugin <%s> has no lv2:binary\n", @@ -366,7 +366,7 @@ lilv_plugin_get_class(const LilvPlugin* const_p) p->world->uris.rdf_a, NULL); FOREACH_MATCH(results) { - const SordNode* class_node = lilv_match_object(results); + const SordNode* class_node = sord_iter_get_node(results, SORD_OBJECT); if (sord_node_get_type(class_node) != SORD_URI) { continue; } @@ -385,7 +385,7 @@ lilv_plugin_get_class(const LilvPlugin* const_p) lilv_node_free(klass); } - lilv_match_end(results); + sord_iter_free(results); if (p->plugin_class == NULL) p->plugin_class = p->world->lv2_plugin_class; @@ -567,20 +567,20 @@ lilv_plugin_has_latency(const LilvPlugin* p) bool ret = false; FOREACH_MATCH(ports) { - const SordNode* port = lilv_match_object(ports); + const SordNode* port = sord_iter_get_node(ports, SORD_OBJECT); SordIter* reports_latency = lilv_world_query_internal( p->world, port, p->world->uris.lv2_portProperty, p->world->uris.lv2_reportsLatency); - const bool end = lilv_matches_end(reports_latency); - lilv_match_end(reports_latency); + const bool end = sord_iter_end(reports_latency); + sord_iter_free(reports_latency); if (!end) { ret = true; break; } } - lilv_match_end(ports); + sord_iter_free(ports); return ret; } @@ -598,8 +598,8 @@ lilv_plugin_get_port_by_property(const LilvPlugin* plugin, plugin->world->uris.lv2_portProperty, port_property->val.uri_val); - const bool found = !lilv_matches_end(iter); - lilv_match_end(iter); + const bool found = !sord_iter_end(iter); + sord_iter_free(iter); if (found) { return port; @@ -625,9 +625,9 @@ lilv_plugin_get_port_by_parameter(const LilvPlugin* plugin, world->uris.lv2_isParameter, parameter->val.uri_val); - const bool found = !lilv_matches_end(iter) && + const bool found = !sord_iter_end(iter) && lilv_port_is_a(plugin, port, port_class); - lilv_match_end(iter); + sord_iter_free(iter); if (found) { return port; @@ -775,13 +775,13 @@ lilv_plugin_get_author(const LilvPlugin* p) sord_node_free(p->world->world, doap_maintainer); - if (lilv_matches_end(maintainers)) { + if (sord_iter_end(maintainers)) { return NULL; } - const SordNode* author = lilv_match_object(maintainers); + const SordNode* author = sord_iter_get_node(maintainers, SORD_OBJECT); - lilv_match_end(maintainers); + sord_iter_free(maintainers); return author; } @@ -848,7 +848,7 @@ lilv_plugin_get_uis(const LilvPlugin* p) NULL); FOREACH_MATCH(uis) { - const SordNode* ui = lilv_match_object(uis); + const SordNode* ui = sord_iter_get_node(uis, SORD_OBJECT); LilvNode* type = lilv_plugin_get_unique(p, ui, p->world->uris.rdf_a); LilvNode* binary = lilv_plugin_get_unique(p, ui, ui_binary_node); @@ -870,7 +870,7 @@ lilv_plugin_get_uis(const LilvPlugin* p) zix_tree_insert((ZixTree*)result, lilv_ui, NULL); } - lilv_match_end(uis); + sord_iter_free(uis); sord_node_free(p->world->world, ui_binary_node); sord_node_free(p->world->world, ui_ui_node); diff --git a/src/port.c b/src/port.c index f2f8fd6..a8d1176 100644 --- a/src/port.c +++ b/src/port.c @@ -73,8 +73,8 @@ lilv_port_has_property(const LilvPlugin* p, p->world->uris.lv2_portProperty, lilv_node_as_node(property)); - const bool ret = !lilv_matches_end(results); - lilv_match_end(results); + const bool ret = !sord_iter_end(results); + sord_iter_free(results); return ret; } @@ -93,8 +93,8 @@ lilv_port_supports_event(const LilvPlugin* p, sord_new_uri(p->world->world, NS_EV "supportsEvent"), lilv_node_as_node(event)); - const bool ret = !lilv_matches_end(results); - lilv_match_end(results); + const bool ret = !sord_iter_end(results); + sord_iter_free(results); return ret; } @@ -111,7 +111,7 @@ lilv_port_get_value_by_node(const LilvPlugin* p, predicate, NULL); - return lilv_nodes_from_stream_objects(p->world, results, true); + return lilv_nodes_from_stream_objects(p->world, results, SORD_OBJECT); } LILV_API @@ -223,11 +223,11 @@ lilv_port_get_scale_points(const LilvPlugin* p, NULL); LilvScalePoints* ret = NULL; - if (!lilv_matches_end(points)) + if (!sord_iter_end(points)) ret = lilv_scale_points_new(); FOREACH_MATCH(points) { - const SordNode* point = lilv_match_object(points); + const SordNode* point = sord_iter_get_node(points, SORD_OBJECT); LilvNode* value = lilv_plugin_get_unique( p, @@ -244,7 +244,7 @@ lilv_port_get_scale_points(const LilvPlugin* p, (ZixTree*)ret, lilv_scale_point_new(value, label), NULL); } } - lilv_match_end(points); + sord_iter_free(points); assert(!ret || lilv_nodes_size(ret) > 0); return ret; diff --git a/src/query.c b/src/query.c index e09ab1d..7f2a7de 100644 --- a/src/query.c +++ b/src/query.c @@ -47,18 +47,16 @@ lilv_lang_matches(const char* a, const char* b) } LilvNodes* -lilv_nodes_from_stream_objects_i18n(LilvWorld* world, - SordIter* stream, - bool object) +lilv_nodes_from_stream_objects_i18n(LilvWorld* world, + SordIter* stream, + SordQuadIndex field) { LilvNodes* values = lilv_nodes_new(); const SordNode* nolang = NULL; // Untranslated value const SordNode* partial = NULL; // Partial language match char* syslang = lilv_get_lang(); FOREACH_MATCH(stream) { - const SordNode* value = object - ? lilv_match_object(stream) - : lilv_match_subject(stream); + const SordNode* value = sord_iter_get_node(stream, field); if (sord_node_get_type(value) == SORD_LITERAL) { const char* lang = sord_node_get_language(value); LilvLangMatch lm = LILV_LANG_MATCH_NONE; @@ -88,7 +86,7 @@ lilv_nodes_from_stream_objects_i18n(LilvWorld* world, NULL); } } - lilv_match_end(stream); + sord_iter_free(stream); free(syslang); if (lilv_nodes_size(values) > 0) { @@ -118,27 +116,25 @@ lilv_nodes_from_stream_objects_i18n(LilvWorld* world, } LilvNodes* -lilv_nodes_from_stream_objects(LilvWorld* world, - SordIter* stream, - bool object) +lilv_nodes_from_stream_objects(LilvWorld* world, + SordIter* stream, + SordQuadIndex field) { - if (lilv_matches_end(stream)) { - lilv_match_end(stream); + if (sord_iter_end(stream)) { + sord_iter_free(stream); return NULL; } else if (world->opt.filter_language) { - return lilv_nodes_from_stream_objects_i18n(world, stream, object); + return lilv_nodes_from_stream_objects_i18n(world, stream, field); } else { LilvNodes* values = lilv_nodes_new(); FOREACH_MATCH(stream) { - const SordNode* value = object - ? lilv_match_object(stream) - : lilv_match_subject(stream); + const SordNode* value = sord_iter_get_node(stream, field); LilvNode* node = lilv_node_new_from_node(world, value); if (node) { zix_tree_insert((ZixTree*)values, node, NULL); } } - lilv_match_end(stream); + sord_iter_free(stream); return values; } } diff --git a/src/state.c b/src/state.c index 37b1f1c..7d0f7f2 100644 --- a/src/state.c +++ b/src/state.c @@ -437,7 +437,7 @@ get1(SordModel* model, const SordNode* s, const SordNode* p) { const SordQuad pat = { s, p, NULL, NULL }; SordIter* const i = sord_find(model, pat); - SordNode* const node = i ? sord_node_copy(lilv_match_object(i)) : NULL; + SordNode* const node = i ? sord_node_copy(sord_iter_get_node(i, SORD_OBJECT)) : NULL; sord_iter_free(i); return node; } @@ -459,11 +459,11 @@ new_state_from_model(LilvWorld* world, node, world->uris.lv2_appliesTo, NULL, NULL }; SordIter* i = sord_find(model, upat); if (i) { - state->plugin_uri = lilv_node_new_from_node( - world, lilv_match_object(i)); + const SordNode* object = sord_iter_get_node(i, SORD_OBJECT); + const SordNode* graph = sord_iter_get_node(i, SORD_GRAPH); + state->plugin_uri = lilv_node_new_from_node(world, object); if (!state->dir) { - state->dir = lilv_strdup( - (const char*)sord_node_get_string(lilv_match_graph(i))); + state->dir = lilv_strdup((const char*)sord_node_get_string(graph)); } sord_iter_free(i); } else { @@ -475,11 +475,11 @@ new_state_from_model(LilvWorld* world, const SordQuad lpat = { node, world->uris.rdfs_label, NULL, NULL }; i = sord_find(model, lpat); if (i) { - state->label = lilv_strdup( - (const char*)sord_node_get_string(lilv_match_object(i))); + const SordNode* object = sord_iter_get_node(i, SORD_OBJECT); + const SordNode* graph = sord_iter_get_node(i, SORD_GRAPH); + state->label = lilv_strdup((const char*)sord_node_get_string(object)); if (!state->dir) { - state->dir = lilv_strdup( - (const char*)sord_node_get_string(lilv_match_graph(i))); + state->dir = lilv_strdup((const char*)sord_node_get_string(graph)); } sord_iter_free(i); } @@ -488,7 +488,7 @@ new_state_from_model(LilvWorld* world, const SordQuad ppat = { node, world->uris.lv2_port, NULL, NULL }; SordIter* ports = sord_find(model, ppat); FOREACH_MATCH(ports) { - const SordNode* port = lilv_match_object(ports); + const SordNode* port = sord_iter_get_node(ports, SORD_OBJECT); const SordNode* label = get1(model, port, world->uris.rdfs_label); const SordNode* symbol = get1(model, port, world->uris.lv2_symbol); const SordNode* value = get1(model, port, world->uris.pset_value); @@ -529,8 +529,8 @@ new_state_from_model(LilvWorld* world, lv2_atom_forge_init(&forge, map); FOREACH_MATCH(props) { - const SordNode* p = lilv_match_predicate(props); - const SordNode* o = lilv_match_object(props); + const SordNode* p = sord_iter_get_node(props, SORD_PREDICATE); + const SordNode* o = sord_iter_get_node(props, SORD_OBJECT); chunk.len = 0; lv2_atom_forge_set_sink( diff --git a/src/world.c b/src/world.c index 0dc8dee..3ae9f7c 100644 --- a/src/world.c +++ b/src/world.c @@ -230,7 +230,7 @@ lilv_world_query_values_internal(LilvWorld* world, return lilv_nodes_from_stream_objects( world, lilv_world_query_internal(world, subject, predicate, object), - (object == NULL)); + (object == NULL) ? SORD_OBJECT : SORD_SUBJECT); } static SerdNode @@ -299,12 +299,12 @@ lilv_world_add_spec(LilvWorld* world, NULL, NULL); FOREACH_MATCH(files) { - const SordNode* file_node = lilv_match_object(files); + const SordNode* file_node = sord_iter_get_node(files, SORD_OBJECT); zix_tree_insert((ZixTree*)spec->data_uris, lilv_node_new_from_node(world, file_node), NULL); } - lilv_match_end(files); + sord_iter_free(files); // Add specification to world specification list spec->next = world->specs; @@ -356,12 +356,12 @@ lilv_world_add_plugin(LilvWorld* world, NULL, NULL); FOREACH_MATCH(files) { - const SordNode* file_node = lilv_match_object(files); + const SordNode* file_node = sord_iter_get_node(files, SORD_OBJECT); zix_tree_insert((ZixTree*)plugin->data_uris, lilv_node_new_from_node(world, file_node), NULL); } - lilv_match_end(files); + sord_iter_free(files); // Add plugin to world plugin sequence zix_tree_insert((ZixTree*)world->plugins, plugin, NULL); @@ -388,7 +388,7 @@ lilv_world_load_dyn_manifest(LilvWorld* world, world->uris.dman_DynManifest, bundle_node); FOREACH_MATCH(dmanifests) { - const SordNode* dmanifest = lilv_match_subject(dmanifests); + const SordNode* dmanifest = sord_iter_get_node(dmanifests, SORD_SUBJECT); // ?dman lv2:binary ?binary SordIter* binaries = lilv_world_find_statements( @@ -397,20 +397,20 @@ lilv_world_load_dyn_manifest(LilvWorld* world, world->uris.lv2_binary, NULL, bundle_node); - if (lilv_matches_end(binaries)) { - lilv_match_end(binaries); + if (sord_iter_end(binaries)) { + sord_iter_free(binaries); LILV_ERRORF("Dynamic manifest in <%s> has no binaries, ignored\n", sord_node_get_string(bundle_node)); continue; } // Get binary path - const SordNode* binary = lilv_match_object(binaries); + const SordNode* binary = sord_iter_get_node(binaries, SORD_OBJECT); const uint8_t* lib_uri = sord_node_get_string(binary); const char* lib_path = lilv_uri_to_path((const char*)lib_uri); if (!lib_path) { LILV_ERROR("No dynamic manifest library path\n"); - lilv_match_end(binaries); + sord_iter_free(binaries); continue; } @@ -418,7 +418,7 @@ lilv_world_load_dyn_manifest(LilvWorld* world, void* lib = dlopen(lib_path, RTLD_LAZY); if (!lib) { LILV_ERRORF("Failed to open dynmanifest library `%s'\n", lib_path); - lilv_match_end(binaries); + sord_iter_free(binaries); continue; } @@ -428,7 +428,7 @@ lilv_world_load_dyn_manifest(LilvWorld* world, OpenFunc dmopen = (OpenFunc)lilv_dlfunc(lib, "lv2_dyn_manifest_open"); if (!dmopen || dmopen(&handle, &dman_features)) { LILV_ERRORF("No `lv2_dyn_manifest_open' in `%s'\n", lib_path); - lilv_match_end(binaries); + sord_iter_free(binaries); dlclose(lib); continue; } @@ -440,7 +440,7 @@ lilv_world_load_dyn_manifest(LilvWorld* world, if (!get_subjects_func) { LILV_ERRORF("No `lv2_dyn_manifest_get_subjects' in `%s'\n", lib_path); - lilv_match_end(binaries); + sord_iter_free(binaries); dlclose(lib); continue; } @@ -477,15 +477,15 @@ lilv_world_load_dyn_manifest(LilvWorld* world, world->uris.lv2_Plugin, dmanifest); FOREACH_MATCH(plug_results) { - const SordNode* plugin_node = lilv_match_subject(plug_results); + const SordNode* plugin_node = sord_iter_get_node(plug_results, SORD_SUBJECT); lilv_world_add_plugin(world, plugin_node, &manifest_uri, desc, bundle_node); } - lilv_match_end(plug_results); + sord_iter_free(plug_results); - lilv_match_end(binaries); + sord_iter_free(binaries); } - lilv_match_end(dmanifests); + sord_iter_free(dmanifests); #endif // LILV_DYN_MANIFEST } @@ -525,11 +525,11 @@ lilv_world_load_bundle(LilvWorld* world, LilvNode* bundle_uri) world->uris.lv2_Plugin, bundle_node); FOREACH_MATCH(plug_results) { - const SordNode* plugin_node = lilv_match_subject(plug_results); + const SordNode* plugin_node = sord_iter_get_node(plug_results, SORD_SUBJECT); lilv_world_add_plugin(world, plugin_node, &manifest_uri, NULL, bundle_node); } - lilv_match_end(plug_results); + sord_iter_free(plug_results); lilv_world_load_dyn_manifest(world, bundle_node, manifest_uri); @@ -541,10 +541,10 @@ lilv_world_load_bundle(LilvWorld* world, LilvNode* bundle_uri) world->uris.lv2_Specification, bundle_node); FOREACH_MATCH(spec_results) { - const SordNode* spec = lilv_match_subject(spec_results); + const SordNode* spec = sord_iter_get_node(spec_results, SORD_SUBJECT); lilv_world_add_spec(world, spec, bundle_node); } - lilv_match_end(spec_results); + sord_iter_free(spec_results); serd_node_free(&manifest_uri); } @@ -658,7 +658,7 @@ lilv_world_load_plugin_classes(LilvWorld* world) world->uris.rdfs_Class, NULL); FOREACH_MATCH(classes) { - const SordNode* class_node = lilv_match_subject(classes); + const SordNode* class_node = sord_iter_get_node(classes, SORD_SUBJECT); // Get parents (superclasses) SordIter* parents = lilv_world_find_statements( @@ -668,13 +668,13 @@ lilv_world_load_plugin_classes(LilvWorld* world) NULL, NULL); - if (lilv_matches_end(parents)) { - lilv_match_end(parents); + if (sord_iter_end(parents)) { + sord_iter_free(parents); continue; } - const SordNode* parent_node = lilv_match_object(parents); - lilv_match_end(parents); + const SordNode* parent_node = sord_iter_get_node(parents, SORD_OBJECT); + sord_iter_free(parents); if (!sord_node_get_type(parent_node) == SORD_URI) { // Class parent is not a resource, ignore (e.g. owl restriction) @@ -689,14 +689,14 @@ lilv_world_load_plugin_classes(LilvWorld* world) NULL, NULL); - if (lilv_matches_end(labels)) { - lilv_match_end(labels); + if (sord_iter_end(labels)) { + sord_iter_free(labels); continue; } - const SordNode* label_node = lilv_match_object(labels); + const SordNode* label_node = sord_iter_get_node(labels, SORD_OBJECT); const uint8_t* label = sord_node_get_string(label_node); - lilv_match_end(labels); + sord_iter_free(labels); LilvPluginClasses* classes = world->plugin_classes; LilvPluginClass* pclass = lilv_plugin_class_new( @@ -706,7 +706,7 @@ lilv_world_load_plugin_classes(LilvWorld* world) zix_tree_insert((ZixTree*)classes, pclass, NULL); } } - lilv_match_end(classes); + sord_iter_free(classes); } LILV_API @@ -737,7 +737,7 @@ lilv_world_load_all(LilvWorld* world) */ ((LilvPlugin*)plugin)->replaced = true; } - lilv_match_end(replacement); + sord_iter_free(replacement); } // Query out things to cache @@ -761,7 +761,7 @@ lilv_world_load_resource(LilvWorld* world, world->uris.rdfs_seeAlso, NULL, NULL); FOREACH_MATCH(files) { - const SordNode* file = lilv_match_object(files); + const SordNode* file = sord_iter_get_node(files, SORD_OBJECT); const uint8_t* str = sord_node_get_string(file); LilvNode* file_node = lilv_node_new_from_node(world, file); ZixTreeIter* iter; @@ -787,7 +787,7 @@ lilv_world_load_resource(LilvWorld* world, } lilv_node_free(file_node); // ...here } - lilv_match_end(files); + sord_iter_free(files); return n_read; } -- cgit v1.2.1