summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lilv/lilv.h33
-rw-r--r--lilv/lilvmm.hpp7
-rw-r--r--src/lilv_internal.h19
-rw-r--r--src/node.c21
-rw-r--r--src/plugin.c58
-rw-r--r--src/port.c8
-rw-r--r--src/world.c60
-rw-r--r--test/lilv_test.c4
-rw-r--r--utils/lv2info.c11
9 files changed, 113 insertions, 108 deletions
diff --git a/lilv/lilv.h b/lilv/lilv.h
index fbb7207..0d0eec4 100644
--- a/lilv/lilv.h
+++ b/lilv/lilv.h
@@ -609,6 +609,18 @@ const LilvPlugins*
lilv_world_get_all_plugins(const LilvWorld* world);
/**
+ Find nodes matching a triple pattern.
+ Either @c subject or @c object may be NULL (i.e. a wildcard), but not both.
+ @return All matches for the wildcard field, or NULL.
+*/
+LILV_API
+LilvNodes*
+lilv_world_find_nodes(LilvWorld* world,
+ const LilvNode* subject,
+ const LilvNode* predicate,
+ const LilvNode* object);
+
+/**
@}
@name Plugin
@{
@@ -719,27 +731,6 @@ lilv_plugin_get_value(const LilvPlugin* p,
const LilvNode* predicate);
/**
- Get a value associated with some subject in a plugin's data files.
- @a predicate must be either a URI or a QName.
-
- Returns the ?object of all triples found of the form:
-
- <code>subject predicate ?object</code>
-
- This can be used to investigate URIs returned by lilv_plugin_get_value
- (if information about it is contained in the plugin's data files).
-
- May return NULL if the property was not found, or if object is not
- sensibly represented as an LilvNodes (e.g. blank nodes).
- Return value must be freed by caller with lilv_nodes_free.
-*/
-LILV_API
-LilvNodes*
-lilv_plugin_get_value_for_subject(const LilvPlugin* p,
- const LilvNode* subject_uri,
- const LilvNode* predicate_uri);
-
-/**
Return whether a feature is supported by a plugin.
This will return true if the feature is an optional or required feature
of the plugin.
diff --git a/lilv/lilvmm.hpp b/lilv/lilvmm.hpp
index d0bd1cd..5fb51af 100644
--- a/lilv/lilvmm.hpp
+++ b/lilv/lilvmm.hpp
@@ -146,7 +146,10 @@ struct World {
inline LilvNode* new_bool(bool val) {
return lilv_new_bool(me, val);
}
-
+ LILV_WRAP2(Nodes, world, find_nodes,
+ Node, subject,
+ Node, predicate,
+ Node, object);
LILV_WRAP2_VOID(world, set_option, const char*, uri, LilvNode*, value);
LILV_WRAP0_VOID(world, free);
LILV_WRAP0_VOID(world, load_all);
@@ -199,8 +202,6 @@ struct Plugin {
LILV_WRAP0(Node, plugin, get_name);
LILV_WRAP0(PluginClass, plugin, get_class);
LILV_WRAP1(Nodes, plugin, get_value, Node, pred);
- LILV_WRAP2(Nodes, plugin, get_value_for_subject, Node, subject,
- Node, predicate);
LILV_WRAP1(bool, plugin, has_feature, Node, feature_uri);
LILV_WRAP0(Nodes, plugin, get_supported_features);
LILV_WRAP0(Nodes, plugin, get_required_features);
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))
diff --git a/src/node.c b/src/node.c
index 1344e8f..1c5cc4f 100644
--- a/src/node.c
+++ b/src/node.c
@@ -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,
diff --git a/src/port.c b/src/port.c
index a23f737..8aa4c59 100644
--- a/src/port.c
+++ b/src/port.c
@@ -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
diff --git a/test/lilv_test.c b/test/lilv_test.c
index ade2c23..6ad2998 100644
--- a/test/lilv_test.c
+++ b/test/lilv_test.c
@@ -467,7 +467,7 @@ test_plugin(void)
PLUGIN_NAME("Test plugin") " ; "
LICENSE_GPL " ; "
"lv2:optionalFeature lv2:hardRTCapable ; "
- "lv2:requiredFeature <http://lv2plug.in/ns/ext/event> ; "
+ "lv2:requiredFeature <http://lv2plug.in/ns/ext/event> ; "
":foo 1.6180 ; "
":bar true ; "
":baz false ; "
@@ -612,7 +612,7 @@ test_plugin(void)
LilvNode* thing_uri = lilv_new_uri(world, "http://example.org/thing");
LilvNode* name_p = lilv_new_uri(world, "http://usefulinc.com/ns/doap#name");
- LilvNodes* thing_names = lilv_plugin_get_value_for_subject(plug, thing_uri, name_p);
+ LilvNodes* thing_names = lilv_world_find_nodes(world, thing_uri, name_p, NULL);
TEST_ASSERT(lilv_nodes_size(thing_names) == 1);
LilvNode* thing_name = lilv_nodes_get_first(thing_names);
TEST_ASSERT(thing_name);
diff --git a/utils/lv2info.c b/utils/lv2info.c
index 53d9b05..f8745c3 100644
--- a/utils/lv2info.c
+++ b/utils/lv2info.c
@@ -143,7 +143,8 @@ print_port(const LilvPlugin* p,
}
void
-print_plugin(const LilvPlugin* p)
+print_plugin(LilvWorld* world,
+ const LilvPlugin* p)
{
LilvNode* val = NULL;
@@ -271,8 +272,10 @@ print_plugin(const LilvPlugin* p)
if (presets)
printf("\tPresets: \n");
LILV_FOREACH(nodes, i, presets) {
- LilvNodes* titles = lilv_plugin_get_value_for_subject(
- p, lilv_nodes_get(presets, i), title_pred);
+ LilvNodes* titles = lilv_world_find_nodes(world,
+ lilv_nodes_get(presets, i),
+ title_pred,
+ NULL);
if (titles) {
const LilvNode* title = lilv_nodes_get(titles, lilv_nodes_begin(titles));
printf("\t %s\n", lilv_node_as_string(title));
@@ -361,7 +364,7 @@ main(int argc, char** argv)
const LilvPlugin* p = lilv_plugins_get_by_uri(plugins, uri);
if (p) {
- print_plugin(p);
+ print_plugin(world, p);
} else {
fprintf(stderr, "Plugin not found.\n");
}