From 2a16021425dab995e902d133b060ebcf6c59a00c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 28 Apr 2011 06:02:12 +0000 Subject: 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 --- slv2/slv2.h | 89 +++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 35 deletions(-) (limited to 'slv2') 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 @@ -364,10 +359,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 @@ -414,10 +421,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); @@ -434,6 +437,14 @@ SLV2_API 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 -- cgit v1.2.1