aboutsummaryrefslogtreecommitdiffstats
path: root/src/sink.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sink.c')
-rw-r--r--src/sink.c62
1 files changed, 54 insertions, 8 deletions
diff --git a/src/sink.c b/src/sink.c
index 40071d72..c8a0dd62 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -1,5 +1,5 @@
/*
- Copyright 2011-2018 David Robillard <http://drobilla.net>
+ Copyright 2011-2020 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
@@ -14,16 +14,61 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "serd/serd.h"
+#include "sink.h"
#include "statement.h"
-#include <stddef.h>
+#include "serd/serd.h"
+
+#include <stdlib.h>
+
+SerdSink*
+serd_sink_new(void* handle)
+{
+ SerdSink* sink = (SerdSink*)calloc(1, sizeof(SerdSink));
+
+ sink->handle = handle;
+ return sink;
+}
+
+void
+serd_sink_free(SerdSink* sink)
+{
+ free(sink);
+}
+
+SerdStatus
+serd_sink_set_base_func(SerdSink* sink, SerdBaseSink base_func)
+{
+ sink->base = base_func;
+ return SERD_SUCCESS;
+}
+
+SerdStatus
+serd_sink_set_prefix_func(SerdSink* sink, SerdPrefixSink prefix_func)
+{
+ sink->prefix = prefix_func;
+ return SERD_SUCCESS;
+}
+
+SerdStatus
+serd_sink_set_statement_func(SerdSink* sink, SerdStatementSink statement_func)
+{
+ sink->statement = statement_func;
+ return SERD_SUCCESS;
+}
+
+SerdStatus
+serd_sink_set_end_func(SerdSink* sink, SerdEndSink end_func)
+{
+ sink->end = end_func;
+ return SERD_SUCCESS;
+}
SerdStatus
serd_sink_write_base(const SerdSink* sink, const SerdNode* uri)
{
- return sink->base(sink->handle, uri);
+ return sink->base ? sink->base(sink->handle, uri) : SERD_SUCCESS;
}
SerdStatus
@@ -31,7 +76,7 @@ serd_sink_write_prefix(const SerdSink* sink,
const SerdNode* name,
const SerdNode* uri)
{
- return sink->prefix(sink->handle, name, uri);
+ return sink->prefix ? sink->prefix(sink->handle, name, uri) : SERD_SUCCESS;
}
SerdStatus
@@ -39,7 +84,8 @@ serd_sink_write_statement(const SerdSink* sink,
const SerdStatementFlags flags,
const SerdStatement* statement)
{
- return sink->statement(sink->handle, flags, statement);
+ return sink->statement ? sink->statement(sink->handle, flags, statement)
+ : SERD_SUCCESS;
}
SerdStatus
@@ -52,11 +98,11 @@ serd_sink_write(const SerdSink* sink,
{
const SerdStatement statement = { { subject, predicate, object, graph },
NULL };
- return sink->statement(sink->handle, flags, &statement);
+ return serd_sink_write_statement(sink, flags, &statement);
}
SerdStatus
serd_sink_write_end(const SerdSink* sink, const SerdNode* node)
{
- return sink->end(sink->handle, node);
+ return sink->end ? sink->end(sink->handle, node) : SERD_SUCCESS;
}