diff options
author | David Robillard <d@drobilla.net> | 2011-03-10 07:20:34 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-03-10 07:20:34 +0000 |
commit | 4f0ea64bf84fc2532e5104fc1bc5d6ccf76d3fff (patch) | |
tree | 4fc91a5c6fb37f1267587513d216feee2787972c /src | |
parent | 509579ed2b7a99b2056136a3faafa7ef11d3a57d (diff) | |
download | lilv-4f0ea64bf84fc2532e5104fc1bc5d6ccf76d3fff.tar.gz lilv-4f0ea64bf84fc2532e5104fc1bc5d6ccf76d3fff.tar.bz2 lilv-4f0ea64bf84fc2532e5104fc1bc5d6ccf76d3fff.zip |
Hide as many collection details as possible while keeping generic iterator / SLV2_FOREACH API.
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3064 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r-- | src/collections.c | 68 | ||||
-rw-r--r-- | src/slv2_internal.h | 33 |
2 files changed, 101 insertions, 0 deletions
diff --git a/src/collections.c b/src/collections.c index bdbf640..4c3ae5e 100644 --- a/src/collections.c +++ b/src/collections.c @@ -165,3 +165,71 @@ slv2_iter_end(SLV2Iter i) { return !i || g_sequence_iter_is_end((GSequenceIter*)i); } + +#define SLV2_COLLECTION_IMPL(prefix, CT, ET) \ +SLV2_API \ +unsigned \ +prefix##_size(CT collection) { \ + return slv2_collection_size(collection); \ +} \ +\ +SLV2_API \ +SLV2Iter \ +prefix##_begin(CT collection) { \ + return slv2_collection_begin(collection); \ +} \ +\ +SLV2_API \ +ET \ +prefix##_get(CT collection, SLV2Iter i) { \ + return (ET)slv2_collection_get(collection, i); \ +} \ +\ +SLV2_DEPRECATED \ +SLV2_API \ +ET \ +prefix##_get_at(CT collection, unsigned index) { \ + return (ET)slv2_collection_get_at(collection, index); \ +} + +SLV2_COLLECTION_IMPL(slv2_plugin_classes, SLV2PluginClasses, SLV2PluginClass) +SLV2_COLLECTION_IMPL(slv2_scale_points, SLV2ScalePoints, SLV2ScalePoint) +SLV2_COLLECTION_IMPL(slv2_uis, SLV2UIs, SLV2UI) +SLV2_COLLECTION_IMPL(slv2_values, SLV2Values, SLV2Value) +SLV2_COLLECTION_IMPL(slv2_plugins, SLV2Plugins, SLV2Plugin) + +SLV2_API +void +slv2_plugin_classes_free(SLV2PluginClasses collection) { + slv2_collection_free(collection); +} + +SLV2_API +void +slv2_scale_points_free(SLV2ScalePoints collection) { + slv2_collection_free(collection); +} + +SLV2_API +void +slv2_uis_free(SLV2UIs collection) { + slv2_collection_free(collection); +} + +SLV2_API +void +slv2_values_free(SLV2Values collection) { + slv2_collection_free(collection); +} + +SLV2_API +void +slv2_plugins_free(SLV2World world, SLV2Plugins plugins){ +} + +SLV2_API +SLV2Value +slv2_values_get_first(SLV2Values collection) { + return (SLV2Value)slv2_collection_get(collection, + slv2_collection_begin(collection)); +} diff --git a/src/slv2_internal.h b/src/slv2_internal.h index f800a68..b1f223f 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -140,6 +140,39 @@ slv2_plugin_get_unique(SLV2Plugin p, SLV2Plugins slv2_plugins_new(); +/** + 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); + +/** + Get an element from @a collection by index. + + @a index has no significance other than as an index into @a collection. + + Any @a index not less than the size of the collection will return NULL, + so all elements in a collection can be enumerated by repeated calls + to this function starting with @a index = 0. + + Note this function is a search, and not constant time. + This function is deprecated, use iterators instead. + + @return NULL if @a index is out of range. +*/ +SLV2_DEPRECATED +SLV2_API +void* +slv2_collection_get_at(SLV2Collection collection, + unsigned index); /* ********* Instance ********* */ |