summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-04-28 06:02:12 +0000
committerDavid Robillard <d@drobilla.net>2011-04-28 06:02:12 +0000
commit2a16021425dab995e902d133b060ebcf6c59a00c (patch)
tree042783cc69184323d799da5db497461d108f6a89
parent00ceff504269034db8e1bfb54a97b5732c2dadce (diff)
downloadlilv-2a16021425dab995e902d133b060ebcf6c59a00c.tar.gz
lilv-2a16021425dab995e902d133b060ebcf6c59a00c.tar.bz2
lilv-2a16021425dab995e902d133b060ebcf6c59a00c.zip
More future-proof collection APIs.
Make all iterator actions occur through a collection specific function. Verbose, and a low of API, but allows for the possibility of different collection implementation types (given a choice between verbosity and no type safety, I'll take verbosity). git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3211 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--slv2/slv2.h89
-rw-r--r--src/collections.c23
-rw-r--r--src/plugin.c6
-rw-r--r--src/pluginui.c2
-rw-r--r--src/port.c2
-rw-r--r--src/slv2_internal.h30
-rw-r--r--src/world.c6
-rw-r--r--test/slv2_test.c19
-rw-r--r--utils/lv2_inspect.c20
-rw-r--r--utils/lv2_list.c4
-rw-r--r--utils/slv2_bench.c4
-rw-r--r--wscript2
12 files changed, 116 insertions, 91 deletions
diff --git a/slv2/slv2.h b/slv2/slv2.h
index 5ea2bf2..96f4662 100644
--- a/slv2/slv2.h
+++ b/slv2/slv2.h
@@ -307,37 +307,24 @@ slv2_value_as_bool(SLV2Value value);
@{
*/
-/* Iter */
+/* Collections */
typedef void* SLV2Iter;
-
-/** Increment @a i to point at the next element in the collection. */
-SLV2_API
-SLV2Iter
-slv2_iter_next(SLV2Iter i);
-
-/** Return true iff @a i is at the end of the collection. */
-SLV2_API
-bool
-slv2_iter_end(SLV2Iter i);
-
-/* Collection */
-
typedef void* SLV2Collection;
-SLV2_API
-SLV2Iter
-slv2_collection_begin(SLV2Collection collection);
-
-SLV2_API
-void*
-slv2_collection_get(SLV2Collection collection,
- SLV2Iter i);
-
-#define SLV2_FOREACH(iter, collection) \
- for (SLV2Iter (iter) = slv2_collection_begin(collection); \
- !slv2_iter_end(iter); \
- (iter) = slv2_iter_next(iter))
+/**
+ Iterate over each element of a collection.
+ @code
+ SLV2_FOREACH(plugin_classes, i, classes) {
+ SLV2PluginClass c = slv2_plugin_classes_get(classes, i);
+ // ...
+ }
+ @endcode
+*/
+#define SLV2_FOREACH(colltype, iter, collection) \
+ for (SLV2Iter (iter) = slv2_ ## colltype ## _begin(collection); \
+ !slv2_ ## colltype ## _is_end(collection, iter); \
+ (iter) = slv2_ ## colltype ## _next(collection, iter))
/* SLV2PluginClasses */
@@ -357,6 +344,14 @@ SLV2_API
SLV2PluginClass
slv2_plugin_classes_get(SLV2PluginClasses collection, SLV2Iter i);
+SLV2_API
+SLV2Iter
+slv2_plugin_classes_next(SLV2PluginClasses collection, SLV2Iter i);
+
+SLV2_API
+bool
+slv2_plugin_classes_is_end(SLV2PluginClasses collection, SLV2Iter i);
+
SLV2_DEPRECATED
SLV2_API
SLV2PluginClass
@@ -365,10 +360,6 @@ slv2_plugin_classes_get_at(SLV2PluginClasses collection, unsigned index);
/* SLV2ScalePoints */
SLV2_API
-SLV2ScalePoints
-slv2_scale_points_new(void);
-
-SLV2_API
void
slv2_scale_points_free(SLV2ScalePoints collection);
@@ -384,6 +375,14 @@ SLV2_API
SLV2ScalePoint
slv2_scale_points_get(SLV2ScalePoints collection, SLV2Iter i);
+SLV2_API
+SLV2Iter
+slv2_scale_points_next(SLV2ScalePoints collection, SLV2Iter i);
+
+SLV2_API
+bool
+slv2_scale_points_is_end(SLV2ScalePoints collection, SLV2Iter i);
+
SLV2_DEPRECATED
SLV2_API
SLV2ScalePoint
@@ -407,6 +406,14 @@ SLV2_API
SLV2UI
slv2_uis_get(SLV2UIs collection, SLV2Iter i);
+SLV2_API
+SLV2Iter
+slv2_uis_next(SLV2UIs collection, SLV2Iter i);
+
+SLV2_API
+bool
+slv2_uis_is_end(SLV2UIs collection, SLV2Iter i);
+
SLV2_DEPRECATED
SLV2_API
SLV2UI
@@ -415,10 +422,6 @@ slv2_uis_get_at(SLV2UIs collection, unsigned index);
/* Values */
SLV2_API
-SLV2ScalePoints
-slv2_values_new(void);
-
-SLV2_API
void
slv2_values_free(SLV2Values collection);
@@ -435,6 +438,14 @@ SLV2Value
slv2_values_get(SLV2Values collection, SLV2Iter i);
SLV2_API
+SLV2Iter
+slv2_values_next(SLV2Values collection, SLV2Iter i);
+
+SLV2_API
+bool
+slv2_values_is_end(SLV2Values collection, SLV2Iter i);
+
+SLV2_API
SLV2Value
slv2_values_get_first(SLV2Values collection);
@@ -457,6 +468,14 @@ SLV2_API
SLV2Plugin
slv2_plugins_get(SLV2Plugins collection, SLV2Iter i);
+SLV2_API
+SLV2Iter
+slv2_plugins_next(SLV2Plugins collection, SLV2Iter i);
+
+SLV2_API
+bool
+slv2_plugins_is_end(SLV2Plugins collection, SLV2Iter i);
+
SLV2_DEPRECATED
SLV2_API
SLV2Plugin
diff --git a/src/collections.c b/src/collections.c
index 254d406..d8f5e1b 100644
--- a/src/collections.c
+++ b/src/collections.c
@@ -26,7 +26,6 @@ slv2_collection_new(GDestroyNotify destructor)
return g_sequence_new(destructor);
}
-SLV2_API
void
slv2_collection_free(SLV2Collection coll)
{
@@ -34,14 +33,12 @@ slv2_collection_free(SLV2Collection coll)
g_sequence_free((GSequence*)coll);
}
-SLV2_API
unsigned
slv2_collection_size(SLV2Collection coll)
{
return (coll ? g_sequence_get_length((GSequence*)coll) : 0);
}
-SLV2_API
void*
slv2_collection_get_at(SLV2Collection coll, unsigned index)
{
@@ -53,14 +50,12 @@ slv2_collection_get_at(SLV2Collection coll, unsigned index)
}
}
-SLV2_API
SLV2Iter
slv2_collection_begin(SLV2Collection collection)
{
return collection ? g_sequence_get_begin_iter(collection) : NULL;
}
-SLV2_API
void*
slv2_collection_get(SLV2Collection collection,
SLV2Iter i)
@@ -70,14 +65,12 @@ slv2_collection_get(SLV2Collection collection,
/* Constructors */
-SLV2_API
SLV2ScalePoints
slv2_scale_points_new(void)
{
return slv2_collection_new((GDestroyNotify)slv2_scale_point_free);
}
-SLV2_API
SLV2Values
slv2_values_new(void)
{
@@ -133,7 +126,7 @@ SLV2_API
bool
slv2_values_contains(SLV2Values list, SLV2Value value)
{
- SLV2_FOREACH(i, list)
+ SLV2_FOREACH(values, i, list)
if (slv2_value_equals(slv2_values_get(list, i), value))
return true;
@@ -142,14 +135,12 @@ slv2_values_contains(SLV2Values list, SLV2Value value)
/* Iterator */
-SLV2_API
SLV2Iter
slv2_iter_next(SLV2Iter i)
{
return g_sequence_iter_next((GSequenceIter*)i);
}
-SLV2_API
bool
slv2_iter_end(SLV2Iter i)
{
@@ -175,6 +166,18 @@ prefix##_get(CT collection, SLV2Iter i) { \
return (ET)slv2_collection_get(collection, i); \
} \
\
+SLV2_API \
+SLV2Iter \
+prefix##_next(CT collection, SLV2Iter i) { \
+ return slv2_iter_next(i); \
+} \
+\
+SLV2_API \
+bool \
+prefix##_is_end(CT collection, SLV2Iter i) { \
+ return slv2_iter_end(i); \
+} \
+\
SLV2_DEPRECATED \
SLV2_API \
ET \
diff --git a/src/plugin.c b/src/plugin.c
index 5de6a1a..d5c9880 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -140,7 +140,7 @@ static void
slv2_plugin_load(SLV2Plugin p)
{
// Parse all the plugin's data files into RDF model
- SLV2_FOREACH(i, p->data_uris) {
+ SLV2_FOREACH(values, i, p->data_uris) {
SLV2Value data_uri_val = slv2_values_get(p->data_uris, i);
sord_read_file(p->world->model,
sord_node_get_string(data_uri_val->val.uri_val),
@@ -641,10 +641,10 @@ slv2_plugin_get_supported_features(SLV2Plugin p)
SLV2Values required = slv2_plugin_get_required_features(p);
SLV2Values result = slv2_values_new();
- SLV2_FOREACH(i, optional)
+ SLV2_FOREACH(values, i, optional)
slv2_array_append(
result, slv2_value_duplicate(slv2_values_get(optional, i)));
- SLV2_FOREACH(i, required)
+ SLV2_FOREACH(values, i, required)
slv2_array_append(
result, slv2_value_duplicate(slv2_values_get(required, i)));
diff --git a/src/pluginui.c b/src/pluginui.c
index 250ce42..3cb2439 100644
--- a/src/pluginui.c
+++ b/src/pluginui.c
@@ -89,7 +89,7 @@ slv2_ui_is_supported(SLV2UI ui,
{
#ifdef HAVE_SUIL
SLV2Values classes = slv2_ui_get_classes(ui);
- SLV2_FOREACH(c, classes) {
+ SLV2_FOREACH(values, c, classes) {
SLV2Value type = slv2_values_get(classes, c);
const unsigned q = supported_func(slv2_value_as_uri(container_type),
slv2_value_as_uri(type));
diff --git a/src/port.c b/src/port.c
index f1346b4..a0de260 100644
--- a/src/port.c
+++ b/src/port.c
@@ -48,7 +48,7 @@ slv2_port_is_a(SLV2Plugin plugin,
SLV2Port port,
SLV2Value port_class)
{
- SLV2_FOREACH(i, port->classes)
+ SLV2_FOREACH(values, i, port->classes)
if (slv2_value_equals(slv2_values_get(port->classes, i), port_class))
return true;
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index e17eebd..2e89891 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -152,17 +152,35 @@ slv2_plugin_get_unique(SLV2Plugin p,
SLV2Plugins
slv2_plugins_new();
+
+/**
+ Increment @a i to point at the next element in the collection.
+*/
+SLV2Iter
+slv2_iter_next(SLV2Iter i);
+
+/**
+ Return true iff @a i is at the end of the collection.
+*/
+bool
+slv2_iter_end(SLV2Iter i);
+
+SLV2Iter
+slv2_collection_begin(SLV2Collection collection);
+
+void*
+slv2_collection_get(SLV2Collection collection,
+ SLV2Iter i);
+
/**
Free @a collection.
*/
-SLV2_API
void
slv2_collection_free(SLV2Collection collection);
/**
Get the number of elements in @a collection.
*/
-SLV2_API
unsigned
slv2_collection_size(SLV2Collection collection);
@@ -181,11 +199,17 @@ slv2_collection_size(SLV2Collection collection);
@return NULL if @a index is out of range.
*/
SLV2_DEPRECATED
-SLV2_API
void*
slv2_collection_get_at(SLV2Collection collection,
unsigned index);
+SLV2Values
+slv2_values_new(void);
+
+SLV2ScalePoints
+slv2_scale_points_new(void);
+
+
/* ********* Instance ********* */
/** Pimpl portion of SLV2Instance */
diff --git a/src/world.c b/src/world.c
index e722024..6970598 100644
--- a/src/world.c
+++ b/src/world.c
@@ -157,7 +157,7 @@ slv2_world_free(SLV2World world)
g_slist_free(world->specs);
world->specs = NULL;
- SLV2_FOREACH(i, world->plugins) {
+ SLV2_FOREACH(plugins, i, world->plugins) {
SLV2Plugin p = slv2_plugins_get(world->plugins, i);
slv2_plugin_free(p);
}
@@ -630,7 +630,7 @@ slv2_world_load_specifications(SLV2World world)
{
for (GSList* l = world->specs; l; l = l->next) {
SLV2Spec spec = (SLV2Spec)l->data;
- SLV2_FOREACH(f, spec->data_uris) {
+ SLV2_FOREACH(values, f, spec->data_uris) {
SLV2Value file = slv2_collection_get(spec->data_uris, f);
sord_read_file(world->model,
(const uint8_t*)slv2_value_as_uri(file),
@@ -718,7 +718,7 @@ slv2_world_load_all(SLV2World world)
// Discover bundles and read all manifest files into model
slv2_world_load_path(world, lv2_path);
- SLV2_FOREACH(p, world->plugins) {
+ SLV2_FOREACH(plugins, p, world->plugins) {
SLV2Plugin plugin = slv2_collection_get(world->plugins, p);
SLV2Value plugin_uri = slv2_plugin_get_uri(plugin);
diff --git a/test/slv2_test.c b/test/slv2_test.c
index 94338c7..0c2ad2e 100644
--- a/test/slv2_test.c
+++ b/test/slv2_test.c
@@ -306,22 +306,6 @@ test_value()
/*****************************************************************************/
-int
-test_values()
-{
- init_world();
- SLV2Value v0 = slv2_value_new_uri(world, "http://example.org/");
- SLV2Values vs1 = slv2_values_new();
- TEST_ASSERT(vs1);
- TEST_ASSERT(!slv2_values_size(vs1));
- TEST_ASSERT(!slv2_values_contains(vs1, v0));
- slv2_values_free(vs1);
- slv2_value_free(v0);
- return 1;
-}
-
-/*****************************************************************************/
-
static int discovery_plugin_found = 0;
static void
@@ -337,8 +321,6 @@ discovery_verify_plugin(SLV2Plugin plugin)
TEST_ASSERT(slv2_value_is_uri(lib_uri));
TEST_ASSERT(slv2_value_as_uri(lib_uri));
TEST_ASSERT(strstr(slv2_value_as_uri(lib_uri), "foo.so"));
- /* this is already being tested as ticket291, but the discovery and ticket291
- * may diverge at some point, so I'm duplicating it here */
TEST_ASSERT(slv2_plugin_verify(plugin));
}
}
@@ -951,7 +933,6 @@ test_ui()
static struct TestCase tests[] = {
TEST_CASE(utils),
TEST_CASE(value),
- TEST_CASE(values),
TEST_CASE(verify),
TEST_CASE(no_verify),
TEST_CASE(discovery),
diff --git a/utils/lv2_inspect.c b/utils/lv2_inspect.c
index 47204c3..5c7342d 100644
--- a/utils/lv2_inspect.c
+++ b/utils/lv2_inspect.c
@@ -55,7 +55,7 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
SLV2Values classes = slv2_port_get_classes(p, port);
printf("\t\tType: ");
- SLV2_FOREACH(i, classes) {
+ SLV2_FOREACH(values, i, classes) {
SLV2Value value = slv2_values_get(classes, i);
if (!first) {
printf("\n\t\t ");
@@ -69,7 +69,7 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
"lv2ev:supportsEvent");
if (slv2_values_size(supported) > 0) {
printf("\n\t\tSupported events:\n");
- SLV2_FOREACH(i, supported) {
+ SLV2_FOREACH(values, i, supported) {
SLV2Value value = slv2_values_get(supported, i);
printf("\t\t\t%s\n", slv2_value_as_uri(value));
}
@@ -80,7 +80,7 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
SLV2ScalePoints points = slv2_port_get_scale_points(p, port);
if (points)
printf("\n\t\tScale Points:\n");
- SLV2_FOREACH(i, points) {
+ SLV2_FOREACH(scale_points, i, points) {
SLV2ScalePoint p = slv2_scale_points_get(points, i);
printf("\t\t\t%s = \"%s\"\n",
slv2_value_as_string(slv2_scale_point_get_value(p)),
@@ -122,7 +122,7 @@ print_port(SLV2Plugin p, uint32_t index, float* mins, float* maxes, float* defau
if (slv2_values_size(properties) > 0)
printf("\t\tProperties: ");
first = true;
- SLV2_FOREACH(i, properties) {
+ SLV2_FOREACH(values, i, properties) {
if (!first) {
printf("\t\t ");
}
@@ -189,14 +189,14 @@ print_plugin(SLV2Plugin p)
SLV2UIs uis = slv2_plugin_get_uis(p);
if (slv2_values_size(uis) > 0) {
printf("\tUI: ");
- SLV2_FOREACH(i, uis) {
+ SLV2_FOREACH(uis, i, uis) {
SLV2UI ui = slv2_uis_get(uis, i);
printf("%s\n", slv2_value_as_uri(slv2_ui_get_uri(ui)));
const char* binary = slv2_value_as_uri(slv2_ui_get_binary_uri(ui));
SLV2Values types = slv2_ui_get_classes(ui);
- SLV2_FOREACH(i, types) {
+ SLV2_FOREACH(values, i, types) {
printf("\t Class: %s\n",
slv2_value_as_uri(slv2_values_get(types, i)));
}
@@ -213,7 +213,7 @@ print_plugin(SLV2Plugin p)
printf("\tData URIs: ");
SLV2Values data_uris = slv2_plugin_get_data_uris(p);
bool first = true;
- SLV2_FOREACH(i, data_uris) {
+ SLV2_FOREACH(values, i, data_uris) {
if (!first) {
printf("\n\t ");
}
@@ -228,7 +228,7 @@ print_plugin(SLV2Plugin p)
if (features)
printf("\tRequired Features: ");
first = true;
- SLV2_FOREACH(i, features) {
+ SLV2_FOREACH(values, i, features) {
if (!first) {
printf("\n\t ");
}
@@ -245,7 +245,7 @@ print_plugin(SLV2Plugin p)
if (features)
printf("\tOptional Features: ");
first = true;
- SLV2_FOREACH(i, features) {
+ SLV2_FOREACH(values, i, features) {
if (!first) {
printf("\n\t ");
}
@@ -261,7 +261,7 @@ print_plugin(SLV2Plugin p)
SLV2Values presets = slv2_plugin_get_value(p, preset_pred);
if (presets)
printf("\tPresets: \n");
- SLV2_FOREACH(i, presets) {
+ SLV2_FOREACH(values, i, presets) {
SLV2Values titles = slv2_plugin_get_value_for_subject(
p, slv2_values_get(presets, i), title_pred);
if (titles) {
diff --git a/utils/lv2_list.c b/utils/lv2_list.c
index 02779cc..d62699a 100644
--- a/utils/lv2_list.c
+++ b/utils/lv2_list.c
@@ -25,9 +25,7 @@
void
list_plugins(SLV2Plugins list, bool show_names)
{
- for (SLV2Iter i = slv2_plugins_begin(list);
- !slv2_iter_end(i);
- i = slv2_iter_next(i)) {
+ SLV2_FOREACH(plugins, i, list) {
SLV2Plugin p = slv2_plugins_get(list, i);
if (show_names) {
SLV2Value n = slv2_plugin_get_name(p);
diff --git a/utils/slv2_bench.c b/utils/slv2_bench.c
index a63b876..de1be4e 100644
--- a/utils/slv2_bench.c
+++ b/utils/slv2_bench.c
@@ -44,8 +44,8 @@ main(int argc, char** argv)
slv2_world_load_all(world);
SLV2Plugins plugins = slv2_world_get_all_plugins(world);
- SLV2_FOREACH(p, plugins) {
- SLV2Plugin plugin = slv2_collection_get(plugins, p);
+ SLV2_FOREACH(plugins, p, plugins) {
+ SLV2Plugin plugin = slv2_plugins_get(plugins, p);
slv2_plugin_get_class(plugin);
}
diff --git a/wscript b/wscript
index 9de35ee..79c7361 100644
--- a/wscript
+++ b/wscript
@@ -6,7 +6,7 @@ from waflib.extras import autowaf as autowaf
import waflib.Options as Options
# Version of this package (even if built as a child)
-SLV2_VERSION = '0.7.2'
+SLV2_VERSION = '0.7.3'
# Library version (UNIX style major, minor, micro)
# major increment <=> incompatible changes