aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-22 19:37:04 +0200
committerDavid Robillard <d@drobilla.net>2018-05-27 21:10:21 +0200
commit436b2362b00543e67194664318e96d965fe390b6 (patch)
tree28ef1197a3134f3bc905644c1182caf7dd8aed72
parentdc9eaf381cb774ce9ddf57613e99fb7e381da041 (diff)
downloadserd-436b2362b00543e67194664318e96d965fe390b6.tar.gz
serd-436b2362b00543e67194664318e96d965fe390b6.tar.bz2
serd-436b2362b00543e67194664318e96d965fe390b6.zip
Add sink API
-rw-r--r--serd/serd.h29
-rw-r--r--src/sink.c61
-rw-r--r--wscript1
3 files changed, 91 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 514fccf4..b9cced8d 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -918,6 +918,35 @@ serd_env_foreach(const SerdEnv* env,
/**
@}
+ @name Sink
+ @{
+*/
+
+SERD_API
+SerdStatus
+serd_sink_set_base(const SerdSinkInterface* sink, const SerdNode* uri);
+
+SERD_API
+SerdStatus
+serd_sink_set_prefix(const SerdSinkInterface* sink,
+ const SerdNode* name,
+ const SerdNode* uri);
+
+SERD_API
+SerdStatus
+serd_sink_write_statement(const SerdSinkInterface* sink,
+ const SerdStatement* statement);
+
+SERD_API
+SerdStatus
+serd_sink_write_range(const SerdSinkInterface* sink, SerdIter* iter);
+
+SERD_API
+SerdStatus
+serd_sink_end(const SerdSinkInterface* sink, const SerdNode* node);
+
+/**
+ @}
@name Reader
@{
*/
diff --git a/src/sink.c b/src/sink.c
new file mode 100644
index 00000000..40d48562
--- /dev/null
+++ b/src/sink.c
@@ -0,0 +1,61 @@
+/*
+ Copyright 2011-2014 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.
+*/
+
+#include "serd/serd.h"
+
+SerdStatus
+serd_sink_set_base(const SerdSinkInterface* sink, const SerdNode* uri)
+{
+ return sink->base(sink->handle, uri);
+}
+
+SerdStatus
+serd_sink_set_prefix(const SerdSinkInterface* sink,
+ const SerdNode* name,
+ const SerdNode* uri)
+{
+ return sink->prefix(sink->handle, name, uri);
+}
+
+SerdStatus
+serd_sink_write_statement(const SerdSinkInterface* sink,
+ const SerdStatement* statement)
+{
+ return sink->statement(sink->handle,
+ 0, // FIXME: flags
+ serd_statement_get_graph(statement),
+ serd_statement_get_subject(statement),
+ serd_statement_get_predicate(statement),
+ serd_statement_get_object(statement));
+}
+
+SerdStatus
+serd_sink_write_range(const SerdSinkInterface* sink, SerdIter* iter)
+{
+ SerdStatus st = SERD_SUCCESS;
+ for (; !st && !serd_iter_end(iter); serd_iter_next(iter)) {
+ st = serd_sink_write_statement(sink, serd_iter_get(iter));
+ }
+ serd_iter_free(iter);
+
+ return st;
+}
+
+SerdStatus
+serd_sink_end(const SerdSinkInterface* sink, const SerdNode* node)
+{
+ return sink->end(sink->handle, node);
+}
diff --git a/wscript b/wscript
index 660e63c0..6471a1a9 100644
--- a/wscript
+++ b/wscript
@@ -96,6 +96,7 @@ lib_source = ['src/base64.c',
'src/node.c',
'src/nodes.c',
'src/reader.c',
+ 'src/sink.c',
'src/statement.c',
'src/string.c',
'src/system.c',