From dadf08057acf8a43b878b0448ce9019efbdf0309 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 15 Jun 2018 15:15:55 -0400 Subject: Make SerdSink opaque --- src/sink.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 6 deletions(-) (limited to 'src/sink.c') diff --git a/src/sink.c b/src/sink.c index b0437c66..0f6faf85 100644 --- a/src/sink.c +++ b/src/sink.c @@ -15,20 +15,67 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "serd/serd.h" +#include "sink.h" #include "statement.h" +#include "serd/serd.h" + +#include + +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_set_base(SerdSink* sink, const SerdNode* uri) { - return sink->base(sink->handle, uri); + return sink->base ? sink->base(sink->handle, uri) : SERD_SUCCESS; } SerdStatus serd_sink_set_prefix(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 @@ -36,7 +83,8 @@ serd_sink_write_statement(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 @@ -49,11 +97,11 @@ serd_sink_write(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_end(SerdSink* sink, const SerdNode* node) { - return sink->end(sink->handle, node); + return sink->end ? sink->end(sink->handle, node) : SERD_SUCCESS; } -- cgit v1.2.1