summaryrefslogtreecommitdiffstats
path: root/utils/uri_table.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-11 23:42:14 +0000
committerDavid Robillard <d@drobilla.net>2012-08-11 23:42:14 +0000
commit83b5c7b86c23f1379d3a96ab4e70c41b032d8823 (patch)
tree05a7d1393d8f3500ece920b3377f3c8ba5e179d5 /utils/uri_table.h
parent91d638a34a872793f26892b627438ef7534e36e2 (diff)
downloadlilv-83b5c7b86c23f1379d3a96ab4e70c41b032d8823.tar.gz
lilv-83b5c7b86c23f1379d3a96ab4e70c41b032d8823.tar.bz2
lilv-83b5c7b86c23f1379d3a96ab4e70c41b032d8823.zip
Add lv2bench utility.
git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@4660 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'utils/uri_table.h')
-rw-r--r--utils/uri_table.h73
1 files changed, 73 insertions, 0 deletions
diff --git a/utils/uri_table.h b/utils/uri_table.h
new file mode 100644
index 0000000..6a27c61
--- /dev/null
+++ b/utils/uri_table.h
@@ -0,0 +1,73 @@
+/*
+ Copyright 2011-2012 David Robillard <http://drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+/**
+ @file uri_table.h A toy URI map/unmap implementation.
+
+ This file contains function definitions and must only be included once.
+*/
+
+#ifndef URI_TABLE_H
+#define URI_TABLE_H
+
+typedef struct {
+ char** uris;
+ size_t n_uris;
+} URITable;
+
+static void
+uri_table_init(URITable* table)
+{
+ table->uris = NULL;
+ table->n_uris = 0;
+}
+
+static void
+uri_table_destroy(URITable* table)
+{
+ free(table->uris);
+}
+
+static LV2_URID
+uri_table_map(LV2_URID_Map_Handle handle,
+ const char* uri)
+{
+ URITable* table = (URITable*)handle;
+ for (size_t i = 0; i < table->n_uris; ++i) {
+ if (!strcmp(table->uris[i], uri)) {
+ return i + 1;
+ }
+ }
+
+ const size_t len = strlen(uri);
+ table->uris = (char**)realloc(table->uris, ++table->n_uris * sizeof(char*));
+ table->uris[table->n_uris - 1] = malloc(len + 1);
+ memcpy(table->uris[table->n_uris - 1], uri, len + 1);
+ return table->n_uris;
+}
+
+static const char*
+uri_table_unmap(LV2_URID_Map_Handle handle,
+ LV2_URID urid)
+{
+ URITable* table = (URITable*)handle;
+ if (urid > 0 && urid <= table->n_uris) {
+ return table->uris[urid - 1];
+ }
+ return NULL;
+}
+
+#endif /* URI_TABLE_H */