diff options
author | David Robillard <d@drobilla.net> | 2011-05-03 05:31:23 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-05-03 05:31:23 +0000 |
commit | 2b2f150447c2d3bde17cbe5d95b9902b7ef6e040 (patch) | |
tree | e99b31b70b61a9c3d827aa87e38bb596fd016c73 /src | |
parent | 5ea7474cad2748fad2a8e0f414c02ec56cb82dff (diff) | |
download | lilv-2b2f150447c2d3bde17cbe5d95b9902b7ef6e040.tar.gz lilv-2b2f150447c2d3bde17cbe5d95b9902b7ef6e040.tar.bz2 lilv-2b2f150447c2d3bde17cbe5d95b9902b7ef6e040.zip |
Replace lilv_plugin_get_value_for_subject with lilv_world_find_nodes.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3247 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/lilv_internal.h | 19 | ||||
-rw-r--r-- | src/node.c | 21 | ||||
-rw-r--r-- | src/plugin.c | 58 | ||||
-rw-r--r-- | src/port.c | 8 | ||||
-rw-r--r-- | src/world.c | 60 |
5 files changed, 88 insertions, 78 deletions
diff --git a/src/lilv_internal.h b/src/lilv_internal.h index eec8c89..1e54f77 100644 --- a/src/lilv_internal.h +++ b/src/lilv_internal.h @@ -238,7 +238,8 @@ void lilv_ui_free(LilvUI* ui); LilvNode* lilv_node_new(LilvWorld* world, LilvNodeType type, const char* val); -LilvNode* lilv_node_new_from_node(LilvWorld* world, const SordNode* node); +LilvNode* lilv_node_new_from_node(LilvWorld* world, + const SordNode* node); const SordNode* lilv_node_as_node(const LilvNode* value); int lilv_header_compare_by_uri(const void* a, const void* b, void* user_data); @@ -261,16 +262,16 @@ LilvScalePoint* lilv_scale_point_new(LilvNode* value, LilvNode* label); void lilv_scale_point_free(LilvScalePoint* point); SordIter* -lilv_world_query(LilvWorld* world, - const SordNode* subject, - const SordNode* predicate, - const SordNode* object); +lilv_world_query_internal(LilvWorld* world, + const SordNode* subject, + const SordNode* predicate, + const SordNode* object); LilvNodes* -lilv_world_query_values(LilvWorld* world, - const SordNode* subject, - const SordNode* predicate, - const SordNode* object); +lilv_world_query_values_internal(LilvWorld* world, + const SordNode* subject, + const SordNode* predicate, + const SordNode* object); #define FOREACH_MATCH(iter) \ for (; !sord_iter_end(iter); sord_iter_next(iter)) @@ -73,10 +73,11 @@ lilv_node_new(LilvWorld* world, LilvNodeType type, const char* str) switch (type) { case LILV_VALUE_URI: val->val.uri_val = sord_new_uri(world->world, (const uint8_t*)str); - assert(val->val.uri_val); val->str_val = (char*)sord_node_get_string(val->val.uri_val); break; case LILV_VALUE_BLANK: + val->val.uri_val = sord_new_blank(world->world, (const uint8_t*)str); + val->str_val = (char*)sord_node_get_string(val->val.uri_val); case LILV_VALUE_STRING: case LILV_VALUE_INT: case LILV_VALUE_FLOAT: @@ -93,14 +94,14 @@ LilvNode* lilv_node_new_from_node(LilvWorld* world, const SordNode* node) { LilvNode* result = NULL; - SordNode* datatype_uri = NULL; + SordNode* datatype_uri = NULL; LilvNodeType type = LILV_VALUE_STRING; switch (sord_node_get_type(node)) { case SORD_URI: type = LILV_VALUE_URI; result = malloc(sizeof(struct LilvNodeImpl)); - result->world = world; + result->world = (LilvWorld*)world; result->type = LILV_VALUE_URI; result->val.uri_val = sord_node_copy(node); result->str_val = (char*)sord_node_get_string(result->val.uri_val); @@ -196,10 +197,13 @@ lilv_node_duplicate(const LilvNode* val) result->world = val->world; result->type = val->type; - if (val->type == LILV_VALUE_URI) { + switch (val->type) { + case LILV_VALUE_URI: + case LILV_VALUE_BLANK: result->val.uri_val = sord_node_copy(val->val.uri_val); result->str_val = (char*)sord_node_get_string(result->val.uri_val); - } else { + break; + default: result->str_val = lilv_strdup(val->str_val); result->val = val->val; } @@ -212,9 +216,12 @@ void lilv_node_free(LilvNode* val) { if (val) { - if (val->type == LILV_VALUE_URI) { + switch (val->type) { + case LILV_VALUE_URI: + case LILV_VALUE_BLANK: sord_node_free(val->world->world, val->val.uri_val); - } else { + break; + default: free(val->str_val); } free(val); diff --git a/src/plugin.c b/src/plugin.c index 4ea2757..5c36180 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -88,7 +88,8 @@ lilv_plugin_get_one(const LilvPlugin* p, const SordNode* predicate) { LilvNode* ret = NULL; - SordIter* stream = lilv_world_query(p->world, subject, predicate, 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)); } @@ -178,7 +179,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p) p->ports = malloc(sizeof(LilvPort*)); p->ports[0] = NULL; - SordIter* ports = lilv_world_query( + SordIter* ports = lilv_world_query_internal( p->world, p->plugin_uri->val.uri_val, p->world->lv2_port_node, @@ -226,7 +227,7 @@ lilv_plugin_load_ports_if_necessary(const LilvPlugin* const_p) p->ports[this_index] = this_port; } - SordIter* types = lilv_world_query( + SordIter* types = lilv_world_query_internal( p->world, port, p->world->rdf_a_node, NULL); FOREACH_MATCH(types) { const SordNode* type = lilv_match_object(types); @@ -292,7 +293,7 @@ lilv_plugin_get_library_uri(const LilvPlugin* const_p) lilv_plugin_load_if_necessary(p); if (!p->binary_uri) { // <plugin> lv2:binary ?binary - SordIter* results = lilv_world_query( + SordIter* results = lilv_world_query_internal( p->world, p->plugin_uri->val.uri_val, p->world->lv2_binary_node, @@ -328,7 +329,7 @@ lilv_plugin_get_class(const LilvPlugin* const_p) lilv_plugin_load_if_necessary(p); if (!p->plugin_class) { // <plugin> a ?class - SordIter* results = lilv_world_query( + SordIter* results = lilv_world_query_internal( p->world, p->plugin_uri->val.uri_val, p->world->rdf_a_node, @@ -417,37 +418,8 @@ LilvNodes* lilv_plugin_get_value(const LilvPlugin* p, const LilvNode* predicate) { - return lilv_plugin_get_value_for_subject(p, p->plugin_uri, predicate); -} - -LILV_API -LilvNodes* -lilv_plugin_get_value_for_subject(const LilvPlugin* p, - const LilvNode* subject, - const LilvNode* predicate) -{ - lilv_plugin_load_ports_if_necessary(p); - if (!lilv_node_is_uri(subject) && !lilv_node_is_blank(subject)) { - LILV_ERRORF("Subject `%s' is not a resource\n", subject->str_val); - return NULL; - } - if (!lilv_node_is_uri(predicate)) { - LILV_ERRORF("Predicate `%s' is not a URI\n", predicate->str_val); - return NULL; - } - - SordNode* subject_node = (lilv_node_is_uri(subject)) - ? sord_node_copy(subject->val.uri_val) - : sord_new_blank(p->world->world, - (const uint8_t*)lilv_node_as_blank(subject)); - - LilvNodes* ret = lilv_world_query_values(p->world, - subject_node, - predicate->val.uri_val, - NULL); - - sord_node_free(p->world->world, subject_node); - return ret; + lilv_plugin_load_if_necessary(p); + return lilv_world_find_nodes(p->world, p->plugin_uri, predicate, NULL); } LILV_API @@ -525,7 +497,7 @@ bool lilv_plugin_has_latency(const LilvPlugin* p) { lilv_plugin_load_if_necessary(p); - SordIter* ports = lilv_world_query( + SordIter* ports = lilv_world_query_internal( p->world, p->plugin_uri->val.uri_val, p->world->lv2_port_node, @@ -534,7 +506,7 @@ lilv_plugin_has_latency(const LilvPlugin* p) bool ret = false; FOREACH_MATCH(ports) { const SordNode* port = lilv_match_object(ports); - SordIter* reports_latency = lilv_world_query( + SordIter* reports_latency = lilv_world_query_internal( p->world, port, p->world->lv2_portproperty_node, @@ -556,7 +528,7 @@ uint32_t lilv_plugin_get_latency_port_index(const LilvPlugin* p) { lilv_plugin_load_if_necessary(p); - SordIter* ports = lilv_world_query( + SordIter* ports = lilv_world_query_internal( p->world, p->plugin_uri->val.uri_val, p->world->lv2_port_node, @@ -564,8 +536,8 @@ lilv_plugin_get_latency_port_index(const LilvPlugin* p) uint32_t ret = 0; FOREACH_MATCH(ports) { - const SordNode* port = lilv_match_object(ports); - SordIter* reports_latency = lilv_world_query( + const SordNode* port = lilv_match_object(ports); + SordIter* reports_latency = lilv_world_query_internal( p->world, port, p->world->lv2_portproperty_node, @@ -669,7 +641,7 @@ lilv_plugin_get_author(const LilvPlugin* p) SordNode* doap_maintainer = sord_new_uri( p->world->world, NS_DOAP "maintainer"); - SordIter* maintainers = lilv_world_query( + SordIter* maintainers = lilv_world_query_internal( p->world, p->plugin_uri->val.uri_val, doap_maintainer, @@ -743,7 +715,7 @@ lilv_plugin_get_uis(const LilvPlugin* p) SordNode* ui_binary_node = sord_new_uri(p->world->world, NS_UI "binary"); LilvUIs* result = lilv_uis_new(); - SordIter* uis = lilv_world_query( + SordIter* uis = lilv_world_query_internal( p->world, p->plugin_uri->val.uri_val, ui_ui_node, @@ -67,7 +67,7 @@ lilv_port_has_property(const LilvPlugin* p, const LilvNode* property) { assert(property); - SordIter* results = lilv_world_query( + SordIter* results = lilv_world_query_internal( p->world, port->node, p->world->lv2_portproperty_node, @@ -87,7 +87,7 @@ lilv_port_supports_event(const LilvPlugin* p, #define NS_EV (const uint8_t*)"http://lv2plug.in/ns/ext/event#" assert(event); - SordIter* results = lilv_world_query( + SordIter* results = lilv_world_query_internal( p->world, port->node, sord_new_uri(p->world->world, NS_EV "supportsEvent"), @@ -105,7 +105,7 @@ lilv_port_get_value_by_node(const LilvPlugin* p, { assert(sord_node_get_type(predicate) == SORD_URI); - SordIter* results = lilv_world_query( + SordIter* results = lilv_world_query_internal( p->world, port->node, predicate, @@ -208,7 +208,7 @@ LilvScalePoints* lilv_port_get_scale_points(const LilvPlugin* p, const LilvPort* port) { - SordIter* points = lilv_world_query( + SordIter* points = lilv_world_query_internal( p->world, port->node, sord_new_uri(p->world->world, (const uint8_t*)LILV_NS_LV2 "scalePoint"), diff --git a/src/world.c b/src/world.c index fbe86ff..0de3e38 100644 --- a/src/world.c +++ b/src/world.c @@ -201,36 +201,66 @@ lilv_world_set_option(LilvWorld* world, } static SordIter* -lilv_world_find_statements(LilvWorld* world, - SordModel* model, - const SordNode* subject, - const SordNode* predicate, - const SordNode* object, - const SordNode* graph) +lilv_world_find_statements(const LilvWorld* world, + SordModel* model, + const SordNode* subject, + const SordNode* predicate, + const SordNode* object, + const SordNode* graph) { SordQuad pat = { subject, predicate, object, graph }; return sord_find(model, pat); } +LILV_API +LilvNodes* +lilv_world_find_nodes(LilvWorld* world, + const LilvNode* subject, + const LilvNode* predicate, + const LilvNode* object) +{ + if (!lilv_node_is_uri(subject) && !lilv_node_is_blank(subject)) { + LILV_ERRORF("Subject `%s' is not a resource\n", subject->str_val); + return NULL; + } + if (!lilv_node_is_uri(predicate)) { + LILV_ERRORF("Predicate `%s' is not a URI\n", predicate->str_val); + return NULL; + } + + SordNode* subject_node = (lilv_node_is_uri(subject)) + ? sord_node_copy(subject->val.uri_val) + : sord_new_blank(world->world, + (const uint8_t*)lilv_node_as_blank(subject)); + + LilvNodes* ret = lilv_world_query_values_internal(world, + subject_node, + predicate->val.uri_val, + NULL); + + sord_node_free(world->world, subject_node); + return ret; +} + SordIter* -lilv_world_query(LilvWorld* world, - const SordNode* subject, - const SordNode* predicate, - const SordNode* object) +lilv_world_query_internal(LilvWorld* world, + const SordNode* subject, + const SordNode* predicate, + const SordNode* object) { return lilv_world_find_statements(world, world->model, subject, predicate, object, NULL); } LilvNodes* -lilv_world_query_values(LilvWorld* world, - const SordNode* subject, - const SordNode* predicate, - const SordNode* object) +lilv_world_query_values_internal(LilvWorld* world, + const SordNode* subject, + const SordNode* predicate, + const SordNode* object) { return lilv_nodes_from_stream_objects( world, - lilv_world_query(world, subject, predicate, object)); + lilv_world_query_internal(world, subject, predicate, object)); } static SerdNode |