From 3760ff6900140d9bae6f811f8d13112862adc751 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 29 Apr 2011 02:46:53 +0000 Subject: Remove half-assed qname API. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3226 a436a847-0d15-0410-975c-d299462d15a1 --- src/lilv_internal.h | 30 +++++++++++------------ src/plugin.c | 35 ++++++--------------------- src/port.c | 25 +------------------ src/util.c | 23 ------------------ src/world.c | 70 +++++++++++++++++++++++++++-------------------------- 5 files changed, 60 insertions(+), 123 deletions(-) (limited to 'src') diff --git a/src/lilv_internal.h b/src/lilv_internal.h index 64cb04a..b33d07e 100644 --- a/src/lilv_internal.h +++ b/src/lilv_internal.h @@ -49,12 +49,12 @@ static inline char* dlerror(void) { return "Unknown error"; } #include "lilv/lilv.h" -#define LILV_NS_DOAP (const uint8_t*)"http://usefulinc.com/ns/doap#" -#define LILV_NS_RDFS (const uint8_t*)"http://www.w3.org/2000/01/rdf-schema#" -#define LILV_NS_LILV (const uint8_t*)"http://drobilla.net/ns/lilv#" -#define LILV_NS_LV2 (const uint8_t*)"http://lv2plug.in/ns/lv2core#" -#define LILV_NS_XSD (const uint8_t*)"http://www.w3.org/2001/XMLSchema#" -#define LILV_NS_RDF (const uint8_t*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#" +#define LILV_NS_DOAP "http://usefulinc.com/ns/doap#" +#define LILV_NS_RDFS "http://www.w3.org/2000/01/rdf-schema#" +#define LILV_NS_LILV "http://drobilla.net/ns/lilv#" +#define LILV_NS_LV2 "http://lv2plug.in/ns/lv2core#" +#define LILV_NS_XSD "http://www.w3.org/2001/XMLSchema#" +#define LILV_NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" typedef SordIter* LilvMatches; typedef const SordNode* LilvNode; @@ -228,16 +228,16 @@ struct LilvWorldImpl { LilvPlugins* plugins; SordNode* dc_replaces_node; SordNode* dyn_manifest_node; - SordNode* lv2_specification_node; - SordNode* lv2_plugin_node; SordNode* lv2_binary_node; SordNode* lv2_default_node; - SordNode* lv2_minimum_node; + SordNode* lv2_index_node; SordNode* lv2_maximum_node; + SordNode* lv2_minimum_node; + SordNode* lv2_plugin_node; SordNode* lv2_port_node; SordNode* lv2_portproperty_node; SordNode* lv2_reportslatency_node; - SordNode* lv2_index_node; + SordNode* lv2_specification_node; SordNode* lv2_symbol_node; SordNode* rdf_a_node; SordNode* rdf_value_node; @@ -245,13 +245,14 @@ struct LilvWorldImpl { SordNode* rdfs_label_node; SordNode* rdfs_seealso_node; SordNode* rdfs_subclassof_node; - SordNode* lilv_dmanifest_node; SordNode* xsd_boolean_node; SordNode* xsd_decimal_node; SordNode* xsd_double_node; SordNode* xsd_integer_node; LilvValue* doap_name_val; LilvValue* lv2_name_val; + LilvValue* lv2_optionalFeature_val; + LilvValue* lv2_requiredFeature_val; LilvOptions opt; }; @@ -362,10 +363,9 @@ LilvValues* lilv_values_from_stream_objects(const LilvPlugin* p, /* ********* Utilities ********* */ -char* lilv_strjoin(const char* first, ...); -char* lilv_strdup(const char* str); -char* lilv_get_lang(); -uint8_t* lilv_qname_expand(const LilvPlugin* p, const char* qname); +char* lilv_strjoin(const char* first, ...); +char* lilv_strdup(const char* str); +char* lilv_get_lang(); typedef void (*VoidFunc)(); diff --git a/src/plugin.c b/src/plugin.c index 7ff47c5..e91317f 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -383,7 +383,9 @@ LILV_API bool lilv_plugin_verify(const LilvPlugin* plugin) { - LilvValues* results = lilv_plugin_get_value_by_qname(plugin, "rdf:type"); + LilvValue* rdf_type = lilv_new_uri(plugin->world, LILV_NS_RDF "type"); + LilvValues* results = lilv_plugin_get_value(plugin, rdf_type); + lilv_value_free(rdf_type); if (!results) { return false; } @@ -395,13 +397,9 @@ lilv_plugin_verify(const LilvPlugin* plugin) } lilv_values_free(results); - results = lilv_plugin_get_value_by_qname(plugin, "doap:license"); - if (!results) { - return false; - } - - lilv_values_free(results); - results = lilv_plugin_get_value_by_qname(plugin, "lv2:port"); + LilvValue* lv2_port = lilv_new_uri(plugin->world, LILV_NS_LV2 "port"); + results = lilv_plugin_get_value(plugin, lv2_port); + lilv_value_free(lv2_port); if (!results) { return false; } @@ -440,23 +438,6 @@ lilv_plugin_get_value(const LilvPlugin* p, return lilv_plugin_get_value_for_subject(p, p->plugin_uri, predicate); } -LILV_API -LilvValues* -lilv_plugin_get_value_by_qname(const LilvPlugin* p, - const char* predicate) -{ - char* pred_uri = (char*)lilv_qname_expand(p, predicate); - if (!pred_uri) { - return NULL; - } - LilvValue* pred_value = lilv_new_uri(p->world, pred_uri); - LilvValues* ret = lilv_plugin_get_value(p, pred_value); - - lilv_value_free(pred_value); - free(pred_uri); - return ret; -} - LILV_API LilvValues* lilv_plugin_get_value_for_subject(const LilvPlugin* p, @@ -657,14 +638,14 @@ LILV_API LilvValues* lilv_plugin_get_optional_features(const LilvPlugin* p) { - return lilv_plugin_get_value_by_qname(p, "lv2:optionalFeature"); + return lilv_plugin_get_value(p, p->world->lv2_optionalFeature_val); } LILV_API LilvValues* lilv_plugin_get_required_features(const LilvPlugin* p) { - return lilv_plugin_get_value_by_qname(p, "lv2:requiredFeature"); + return lilv_plugin_get_value(p, p->world->lv2_requiredFeature_val); } LILV_API diff --git a/src/port.c b/src/port.c index 3f4d871..2110e4d 100644 --- a/src/port.c +++ b/src/port.c @@ -126,29 +126,6 @@ lilv_port_supports_event(const LilvPlugin* p, return ret; } -LILV_API -LilvValues* -lilv_port_get_value_by_qname(const LilvPlugin* p, - const LilvPort* port, - const char* predicate) -{ - assert(predicate); - uint8_t* pred_uri = lilv_qname_expand(p, predicate); - if (!pred_uri) { - return NULL; - } - - LilvNode port_node = lilv_port_get_node(p, port); - LilvMatches results = lilv_plugin_find_statements( - p, - port_node, - sord_new_uri(p->world->world, pred_uri), - NULL); - - free(pred_uri); - return lilv_values_from_stream_objects(p, results); -} - static LilvValues* lilv_port_get_value_by_node(const LilvPlugin* p, const LilvPort* port, @@ -264,7 +241,7 @@ lilv_port_get_scale_points(const LilvPlugin* p, LilvMatches points = lilv_plugin_find_statements( p, port_node, - sord_new_uri(p->world->world, LILV_NS_LV2 "scalePoint"), + sord_new_uri(p->world->world, (const uint8_t*)LILV_NS_LV2 "scalePoint"), NULL); LilvScalePoints* ret = NULL; diff --git a/src/util.c b/src/util.c index 0603a7a..e59ddc9 100644 --- a/src/util.c +++ b/src/util.c @@ -110,26 +110,3 @@ lilv_get_lang() return lang; } - -uint8_t* -lilv_qname_expand(const LilvPlugin* p, const char* qname) -{ - const size_t qname_len = strlen(qname); - SerdNode qname_node = { (const uint8_t*)qname, - qname_len + 1, qname_len, - SERD_CURIE }; - - SerdChunk uri_prefix; - SerdChunk uri_suffix; - if (serd_env_expand(p->world->namespaces, &qname_node, &uri_prefix, &uri_suffix)) { - const size_t uri_len = uri_prefix.len + uri_suffix.len; - char* uri = malloc(uri_len + 1); - memcpy(uri, uri_prefix.buf, uri_prefix.len); - memcpy(uri + uri_prefix.len, uri_suffix.buf, uri_suffix.len); - uri[uri_len] = '\0'; - return (uint8_t*)uri; - } else { - LILV_ERRORF("Failed to expand QName `%s'\n", qname); - return NULL; - } -} diff --git a/src/world.c b/src/world.c index e930964..03570c0 100644 --- a/src/world.c +++ b/src/world.c @@ -59,36 +59,37 @@ lilv_world_new() #define NS_DYNMAN (const uint8_t*)"http://lv2plug.in/ns/ext/dynmanifest#" #define NS_DC (const uint8_t*)"http://dublincore.org/documents/dcmi-namespace/" -#define NEW_URI(uri) sord_new_uri(world->world, uri) +#define NEW_URI(uri) sord_new_uri(world->world, (const uint8_t*)uri) #define NEW_URI_VAL(uri) lilv_new_uri(world, (const char*)(uri)); - world->dc_replaces_node = NEW_URI(NS_DC "replaces"); - world->dyn_manifest_node = NEW_URI(NS_DYNMAN "DynManifest"); - world->lv2_specification_node = NEW_URI(LILV_NS_LV2 "Specification"); - world->lv2_plugin_node = NEW_URI(LILV_NS_LV2 "Plugin"); - world->lv2_binary_node = NEW_URI(LILV_NS_LV2 "binary"); - world->lv2_default_node = NEW_URI(LILV_NS_LV2 "default"); - world->lv2_minimum_node = NEW_URI(LILV_NS_LV2 "minimum"); - world->lv2_maximum_node = NEW_URI(LILV_NS_LV2 "maximum"); - world->lv2_port_node = NEW_URI(LILV_NS_LV2 "port"); - world->lv2_portproperty_node = NEW_URI(LILV_NS_LV2 "portProperty"); - world->lv2_reportslatency_node = NEW_URI(LILV_NS_LV2 "reportsLatency"); - world->lv2_index_node = NEW_URI(LILV_NS_LV2 "index"); - world->lv2_symbol_node = NEW_URI(LILV_NS_LV2 "symbol"); - world->rdf_a_node = NEW_URI(LILV_NS_RDF "type"); - world->rdf_value_node = NEW_URI(LILV_NS_RDF "value"); - world->rdfs_class_node = NEW_URI(LILV_NS_RDFS "Class"); - world->rdfs_label_node = NEW_URI(LILV_NS_RDFS "label"); - world->rdfs_seealso_node = NEW_URI(LILV_NS_RDFS "seeAlso"); - world->rdfs_subclassof_node = NEW_URI(LILV_NS_RDFS "subClassOf"); - world->lilv_dmanifest_node = NEW_URI(LILV_NS_LILV "dynamic-manifest"); - world->xsd_boolean_node = NEW_URI(LILV_NS_XSD "boolean"); - world->xsd_decimal_node = NEW_URI(LILV_NS_XSD "decimal"); - world->xsd_double_node = NEW_URI(LILV_NS_XSD "double"); - world->xsd_integer_node = NEW_URI(LILV_NS_XSD "integer"); - - world->doap_name_val = NEW_URI_VAL(LILV_NS_DOAP "name"); - world->lv2_name_val = NEW_URI_VAL(LILV_NS_LV2 "name"); + world->dc_replaces_node = NEW_URI(NS_DC "replaces"); + world->dyn_manifest_node = NEW_URI(NS_DYNMAN "DynManifest"); + world->lv2_binary_node = NEW_URI(LILV_NS_LV2 "binary"); + world->lv2_default_node = NEW_URI(LILV_NS_LV2 "default"); + world->lv2_index_node = NEW_URI(LILV_NS_LV2 "index"); + world->lv2_maximum_node = NEW_URI(LILV_NS_LV2 "maximum"); + world->lv2_minimum_node = NEW_URI(LILV_NS_LV2 "minimum"); + world->lv2_plugin_node = NEW_URI(LILV_NS_LV2 "Plugin"); + world->lv2_port_node = NEW_URI(LILV_NS_LV2 "port"); + world->lv2_portproperty_node = NEW_URI(LILV_NS_LV2 "portProperty"); + world->lv2_reportslatency_node = NEW_URI(LILV_NS_LV2 "reportsLatency"); + world->lv2_specification_node = NEW_URI(LILV_NS_LV2 "Specification"); + world->lv2_symbol_node = NEW_URI(LILV_NS_LV2 "symbol"); + world->rdf_a_node = NEW_URI(LILV_NS_RDF "type"); + world->rdf_value_node = NEW_URI(LILV_NS_RDF "value"); + world->rdfs_class_node = NEW_URI(LILV_NS_RDFS "Class"); + world->rdfs_label_node = NEW_URI(LILV_NS_RDFS "label"); + world->rdfs_seealso_node = NEW_URI(LILV_NS_RDFS "seeAlso"); + world->rdfs_subclassof_node = NEW_URI(LILV_NS_RDFS "subClassOf"); + world->xsd_boolean_node = NEW_URI(LILV_NS_XSD "boolean"); + world->xsd_decimal_node = NEW_URI(LILV_NS_XSD "decimal"); + world->xsd_double_node = NEW_URI(LILV_NS_XSD "double"); + world->xsd_integer_node = NEW_URI(LILV_NS_XSD "integer"); + + world->doap_name_val = NEW_URI_VAL(LILV_NS_DOAP "name"); + world->lv2_name_val = NEW_URI_VAL(LILV_NS_LV2 "name"); + world->lv2_optionalFeature_val = NEW_URI_VAL(LILV_NS_LV2 "optionalFeature"); + world->lv2_requiredFeature_val = NEW_URI_VAL(LILV_NS_LV2 "requiredFeature"); world->lv2_plugin_class = lilv_plugin_class_new( world, NULL, world->lv2_plugin_node, "Plugin"); @@ -122,30 +123,31 @@ lilv_world_free(LilvWorld* world) lilv_node_free(world, world->dc_replaces_node); lilv_node_free(world, world->dyn_manifest_node); - lilv_node_free(world, world->lv2_specification_node); - lilv_node_free(world, world->lv2_plugin_node); lilv_node_free(world, world->lv2_binary_node); lilv_node_free(world, world->lv2_default_node); - lilv_node_free(world, world->lv2_minimum_node); + lilv_node_free(world, world->lv2_index_node); lilv_node_free(world, world->lv2_maximum_node); + lilv_node_free(world, world->lv2_minimum_node); + lilv_node_free(world, world->lv2_plugin_node); lilv_node_free(world, world->lv2_port_node); lilv_node_free(world, world->lv2_portproperty_node); lilv_node_free(world, world->lv2_reportslatency_node); - lilv_node_free(world, world->lv2_index_node); + lilv_node_free(world, world->lv2_specification_node); lilv_node_free(world, world->lv2_symbol_node); lilv_node_free(world, world->rdf_a_node); lilv_node_free(world, world->rdf_value_node); + lilv_node_free(world, world->rdfs_class_node); lilv_node_free(world, world->rdfs_label_node); lilv_node_free(world, world->rdfs_seealso_node); lilv_node_free(world, world->rdfs_subclassof_node); - lilv_node_free(world, world->rdfs_class_node); - lilv_node_free(world, world->lilv_dmanifest_node); lilv_node_free(world, world->xsd_boolean_node); lilv_node_free(world, world->xsd_decimal_node); lilv_node_free(world, world->xsd_double_node); lilv_node_free(world, world->xsd_integer_node); lilv_value_free(world->doap_name_val); lilv_value_free(world->lv2_name_val); + lilv_value_free(world->lv2_optionalFeature_val); + lilv_value_free(world->lv2_requiredFeature_val); for (GSList* l = world->specs; l; l = l->next) { LilvSpec* spec = (LilvSpec*)l->data; -- cgit v1.2.1