From 98cd625a7ba5eb91d473c1fe1504c7a9c050ef86 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 30 Jan 2011 04:23:47 +0000 Subject: Non-SPARQL version of slv2_port_get_range. 1 query left... git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@2867 a436a847-0d15-0410-975c-d299462d15a1 --- src/port.c | 91 ++++++++++++++++++++++++++--------------------------- src/slv2_internal.h | 3 ++ src/world.c | 6 ++++ 3 files changed, 54 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/port.c b/src/port.c index 8ca2be0..3e072ed 100644 --- a/src/port.c +++ b/src/port.c @@ -177,6 +177,24 @@ slv2_port_get_value_by_qname(SLV2Plugin p, } +static SLV2Values +slv2_port_get_value_by_node(SLV2Plugin p, + SLV2Port port, + librdf_node* predicate) +{ + assert(librdf_node_is_resource(predicate)); + + librdf_node* port_node = slv2_port_get_node(p, port); + librdf_stream* results = slv2_plugin_find_statements( + p, + port_node, + predicate, + NULL); + + return slv2_values_from_stream_objects(p, results); +} + + SLV2Values slv2_port_get_value(SLV2Plugin p, SLV2Port port, @@ -187,14 +205,10 @@ slv2_port_get_value(SLV2Plugin p, return NULL; } - librdf_node* port_node = slv2_port_get_node(p, port); - librdf_stream* results = slv2_plugin_find_statements( - p, - port_node, - librdf_new_node_from_uri(p->world->world, slv2_value_as_librdf_uri(predicate)), - NULL); - - return slv2_values_from_stream_objects(p, results); + return slv2_port_get_value_by_node( + p, port, + librdf_new_node_from_uri(p->world->world, + slv2_value_as_librdf_uri(predicate))); } @@ -264,45 +278,30 @@ slv2_port_get_range(SLV2Plugin p, SLV2Value* min, SLV2Value* max) { - if (def) - *def = NULL; - if (min) - *min = NULL; - if (max) - *max = NULL; - - char* query = slv2_strjoin( - "SELECT DISTINCT ?def ?min ?max WHERE {\n" - "<", slv2_value_as_uri(p->plugin_uri), "> lv2:port ?port .\n" - "?port lv2:symbol \"", slv2_value_as_string(port->symbol), "\".\n", - "OPTIONAL { ?port lv2:default ?def }\n", - "OPTIONAL { ?port lv2:minimum ?min }\n", - "OPTIONAL { ?port lv2:maximum ?max }\n", - "\n}", NULL); - - SLV2Results results = slv2_plugin_query_sparql(p, query); - - while (!librdf_query_results_finished(results->rdf_results)) { - librdf_node* def_node = librdf_query_results_get_binding_value(results->rdf_results, 0); - librdf_node* min_node = librdf_query_results_get_binding_value(results->rdf_results, 1); - librdf_node* max_node = librdf_query_results_get_binding_value(results->rdf_results, 2); - - if (def && def_node && !*def) - *def = slv2_value_new_librdf_node(p->world, def_node); - if (min && min_node && !*min) - *min = slv2_value_new_librdf_node(p->world, min_node); - if (max && max_node && !*max) - *max = slv2_value_new_librdf_node(p->world, max_node); - - if ((!def || *def) && (!min || *min) && (!max || *max)) - break; - - librdf_query_results_next(results->rdf_results); + if (def) { + SLV2Values defaults = slv2_port_get_value_by_node( + p, port, p->world->lv2_default_node); + *def = defaults + ? slv2_value_duplicate(slv2_values_get_at(defaults, 0)) + : NULL; + slv2_values_free(defaults); + } + if (min) { + SLV2Values minimums = slv2_port_get_value_by_node( + p, port, p->world->lv2_minimum_node); + *min = minimums + ? slv2_value_duplicate(slv2_values_get_at(minimums, 0)) + : NULL; + slv2_values_free(minimums); + } + if (max) { + SLV2Values maximums = slv2_port_get_value_by_node( + p, port, p->world->lv2_maximum_node); + *max = maximums + ? slv2_value_duplicate(slv2_values_get_at(maximums, 0)) + : NULL; + slv2_values_free(maximums); } - - slv2_results_free(results); - - free(query); } diff --git a/src/slv2_internal.h b/src/slv2_internal.h index f2984a3..f25018e 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -160,6 +160,9 @@ struct _SLV2World { librdf_node* lv2_specification_node; librdf_node* lv2_plugin_node; librdf_node* lv2_binary_node; + librdf_node* lv2_default_node; + librdf_node* lv2_minimum_node; + librdf_node* lv2_maximum_node; librdf_node* lv2_port_node; librdf_node* lv2_portproperty_node; librdf_node* lv2_index_node; diff --git a/src/world.c b/src/world.c index 1909ca5..e4f292c 100644 --- a/src/world.c +++ b/src/world.c @@ -63,6 +63,9 @@ slv2_world_new_internal(SLV2World world) world->lv2_specification_node = NEW_URI(SLV2_NS_LV2 "Specification"); world->lv2_plugin_node = NEW_URI(SLV2_NS_LV2 "Plugin"); world->lv2_binary_node = NEW_URI(SLV2_NS_LV2 "binary"); + world->lv2_default_node = NEW_URI(SLV2_NS_LV2 "default"); + world->lv2_minimum_node = NEW_URI(SLV2_NS_LV2 "minimum"); + world->lv2_maximum_node = NEW_URI(SLV2_NS_LV2 "maximum"); world->lv2_port_node = NEW_URI(SLV2_NS_LV2 "port"); world->lv2_portproperty_node = NEW_URI(SLV2_NS_LV2 "portProperty"); world->lv2_index_node = NEW_URI(SLV2_NS_LV2 "index"); @@ -162,6 +165,9 @@ slv2_world_free(SLV2World world) librdf_free_node(world->lv2_specification_node); librdf_free_node(world->lv2_plugin_node); librdf_free_node(world->lv2_binary_node); + librdf_free_node(world->lv2_default_node); + librdf_free_node(world->lv2_minimum_node); + librdf_free_node(world->lv2_maximum_node); librdf_free_node(world->lv2_port_node); librdf_free_node(world->lv2_portproperty_node); librdf_free_node(world->lv2_index_node); -- cgit v1.2.1