aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-03 19:42:30 +0200
committerDavid Robillard <d@drobilla.net>2019-12-19 20:55:18 -0500
commit0476f6737a568f8902f9a1317d6683c1d3f1f03d (patch)
treeb865948d80bc6b77a573fcb765fb9e6612a8b79f
parent3395e65e8b0c5edb107019d1d8345dac71f5d86c (diff)
downloadserd-0476f6737a568f8902f9a1317d6683c1d3f1f03d.tar.gz
serd-0476f6737a568f8902f9a1317d6683c1d3f1f03d.tar.bz2
serd-0476f6737a568f8902f9a1317d6683c1d3f1f03d.zip
Add sink interface
-rw-r--r--serd/serd.h60
-rw-r--r--src/sink.c62
-rw-r--r--wscript1
3 files changed, 123 insertions, 0 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 67ad5d6b..c76626de 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -949,6 +949,66 @@ serd_env_foreach(const SerdEnv* env,
/**
@}
+ @name Sink
+ @{
+*/
+
+/**
+ Set the base URI.
+
+ Simple wrapper for the `SerdBaseSink` of `sink`.
+*/
+SERD_API
+SerdStatus
+serd_sink_write_base(const SerdSink* sink, const SerdNode* uri);
+
+/**
+ Set a namespace prefix.
+
+ Simple wrapper for the `SerdPrefixSink` of `sink`.
+*/
+SERD_API
+SerdStatus
+serd_sink_write_prefix(const SerdSink* sink,
+ const SerdNode* name,
+ const SerdNode* uri);
+
+/**
+ Write a statement.
+
+ Simple wrapper for the `SerdStatementSink` of `sink`.
+*/
+SERD_API
+SerdStatus
+serd_sink_write_statement(const SerdSink* sink,
+ SerdStatementFlags flags,
+ const SerdStatement* statement);
+
+/**
+ Write a statement from individual nodes.
+
+ Simple wrapper for the `SerdStatementSink` of `sink`.
+*/
+SERD_API
+SerdStatus
+serd_sink_write(const SerdSink* sink,
+ SerdStatementFlags flags,
+ const SerdNode* subject,
+ const SerdNode* predicate,
+ const SerdNode* object,
+ const SerdNode* graph);
+
+/**
+ Mark the end of an anonymous node.
+
+ Simple wrapper for the `SerdEndSink` of `sink`.
+*/
+SERD_API
+SerdStatus
+serd_sink_write_end(const SerdSink* sink, const SerdNode* node);
+
+/**
+ @}
@name Reader
@{
*/
diff --git a/src/sink.c b/src/sink.c
new file mode 100644
index 00000000..eb31bbf6
--- /dev/null
+++ b/src/sink.c
@@ -0,0 +1,62 @@
+/*
+ Copyright 2011-2018 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_write_base(const SerdSink* sink, const SerdNode* uri)
+{
+ return sink->base(sink->handle, uri);
+}
+
+SerdStatus
+serd_sink_write_prefix(const SerdSink* sink,
+ const SerdNode* name,
+ const SerdNode* uri)
+{
+ return sink->prefix(sink->handle, name, uri);
+}
+
+SerdStatus
+serd_sink_write_statement(const SerdSink* sink,
+ const SerdStatementFlags flags,
+ const SerdStatement* statement)
+{
+ return sink->statement(sink->handle,
+ 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(const SerdSink* sink,
+ const SerdStatementFlags flags,
+ const SerdNode* subject,
+ const SerdNode* predicate,
+ const SerdNode* object,
+ const SerdNode* graph)
+{
+ return sink->statement(
+ sink->handle, flags, graph, subject, predicate, object);
+}
+
+SerdStatus
+serd_sink_write_end(const SerdSink* sink, const SerdNode* node)
+{
+ return sink->end(sink->handle, node);
+}
diff --git a/wscript b/wscript
index 48f9206c..06e47ee8 100644
--- a/wscript
+++ b/wscript
@@ -86,6 +86,7 @@ lib_source = ['src/base64.c',
'src/n3.c',
'src/node.c',
'src/reader.c',
+ 'src/sink.c',
'src/statement.c',
'src/string.c',
'src/syntax.c',