summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-03-08 00:54:23 +0000
committerDavid Robillard <d@drobilla.net>2011-03-08 00:54:23 +0000
commita9bbabe7ff2d9ca96ab047ccb86c2698cfb2d7b3 (patch)
tree4d124d439d59aa7da04f818a000a2f966e63503b /src
parent27341a1b6bb661114184f93fadaf534d890e8498 (diff)
downloadlilv-a9bbabe7ff2d9ca96ab047ccb86c2698cfb2d7b3.tar.gz
lilv-a9bbabe7ff2d9ca96ab047ccb86c2698cfb2d7b3.tar.bz2
lilv-a9bbabe7ff2d9ca96ab047ccb86c2698cfb2d7b3.zip
Use the same data structure for all collections (fix ticket #650).
git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3054 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/collections.c68
-rw-r--r--src/plugin.c14
-rw-r--r--src/slv2_internal.h4
3 files changed, 28 insertions, 58 deletions
diff --git a/src/collections.c b/src/collections.c
index 85f4391..43c8af7 100644
--- a/src/collections.c
+++ b/src/collections.c
@@ -27,47 +27,6 @@
#include "slv2_internal.h"
-/* ARRAYS */
-
-#define SLV2_ARRAY_IMPL(CollType, ElemType, prefix, free_func) \
-\
-CollType \
-prefix ## _new() \
-{ \
- return g_ptr_array_new_with_free_func((GDestroyNotify)free_func); \
-} \
-\
-SLV2_API \
-void \
-prefix ## _free(CollType coll) \
-{ \
- if (coll) \
- g_ptr_array_unref((GPtrArray*)coll); \
-} \
-\
-SLV2_API \
-unsigned \
-prefix ## _size(CollType coll) \
-{ \
- return (coll ? ((GPtrArray*)coll)->len : 0); \
-} \
-\
-SLV2_API \
-ElemType \
-prefix ## _get_at(CollType coll, unsigned index) \
-{ \
- if (!coll || index >= ((GPtrArray*)coll)->len) \
- return NULL; \
- else \
- return (ElemType)g_ptr_array_index((GPtrArray*)coll, (int)index); \
-}
-
-SLV2_ARRAY_IMPL(SLV2ScalePoints, SLV2ScalePoint,
- slv2_scale_points, &slv2_scale_point_free)
-SLV2_ARRAY_IMPL(SLV2Values, SLV2Value,
- slv2_values, &slv2_value_free)
-
-
/* SEQUENCE */
#define SLV2_SEQUENCE_IMPL(CollType, ElemType, prefix, free_func) \
@@ -103,21 +62,34 @@ prefix ## _get_at(CollType coll, unsigned index) \
GSequenceIter* i = g_sequence_get_iter_at_pos((GSequence*)coll, (int)index); \
return (ElemType)g_sequence_get(i); \
} \
-} \
-\
-SLV2_API \
-ElemType \
-prefix ## _get_by_uri(CollType coll, SLV2Value uri) \
-{ \
- return (ElemType)slv2_sequence_get_by_uri(coll, uri); \
}
+SLV2_SEQUENCE_IMPL(SLV2ScalePoints, SLV2ScalePoint,
+ slv2_scale_points, &slv2_scale_point_free)
+
+SLV2_SEQUENCE_IMPL(SLV2Values, SLV2Value,
+ slv2_values, &slv2_value_free)
+
SLV2_SEQUENCE_IMPL(SLV2PluginClasses, SLV2PluginClass,
slv2_plugin_classes, &slv2_plugin_class_free)
SLV2_SEQUENCE_IMPL(SLV2UIs, SLV2UI,
slv2_uis, &slv2_ui_free)
+SLV2_API
+SLV2PluginClass
+slv2_plugin_classes_get_by_uri(SLV2PluginClasses coll, SLV2Value uri)
+{
+ return (SLV2PluginClass)slv2_sequence_get_by_uri(coll, uri);
+}
+
+SLV2_API
+SLV2UI
+slv2_uis_get_by_uri(SLV2UIs coll, SLV2Value uri)
+{
+ return (SLV2UIs)slv2_sequence_get_by_uri(coll, uri);
+}
+
/* VALUES */
diff --git a/src/plugin.c b/src/plugin.c
index f2d1837..4159cdf 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -659,16 +659,14 @@ slv2_plugin_get_supported_features(SLV2Plugin p)
unsigned n_optional = slv2_values_size(optional);
unsigned n_required = slv2_values_size(required);
for (unsigned i = 0 ; i < n_optional; ++i)
- slv2_array_append(result, slv2_values_get_at(optional, i));
+ slv2_array_append(
+ result, slv2_value_duplicate(slv2_values_get_at(optional, i)));
for (unsigned i = 0 ; i < n_required; ++i)
- slv2_array_append(result, slv2_values_get_at(required, i));
+ slv2_array_append(
+ result, slv2_value_duplicate(slv2_values_get_at(required, i)));
- if (optional) {
- free(((GPtrArray*)optional)->pdata);
- }
- if (required) {
- free(((GPtrArray*)required)->pdata);
- }
+ slv2_values_free(optional);
+ slv2_values_free(required);
return result;
}
diff --git a/src/slv2_internal.h b/src/slv2_internal.h
index 0752044..97f141f 100644
--- a/src/slv2_internal.h
+++ b/src/slv2_internal.h
@@ -294,8 +294,8 @@ slv2_sequence_insert(GSequence* seq, void* value)
}
static inline void
-slv2_array_append(GPtrArray* array, void* value) {
- g_ptr_array_add(array, value);
+slv2_array_append(GSequence* seq, void* value) {
+ g_sequence_append(seq, value);
}
struct _SLV2Header*