diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/n3.c | 1 | ||||
-rw-r--r-- | src/reader.c | 1 | ||||
-rw-r--r-- | src/sink.c | 60 | ||||
-rw-r--r-- | src/sink.h | 33 | ||||
-rw-r--r-- | src/writer.c | 1 |
5 files changed, 90 insertions, 6 deletions
@@ -17,6 +17,7 @@ #include "node.h" #include "reader.h" #include "serd_internal.h" +#include "sink.h" #include "string_utils.h" #include "uri_utils.h" diff --git a/src/reader.c b/src/reader.c index fb06bdc3..9b1d9f4d 100644 --- a/src/reader.c +++ b/src/reader.c @@ -20,6 +20,7 @@ #include "node.h" #include "serd/serd.h" #include "serd_internal.h" +#include "sink.h" #include "stack.h" #include "statement.h" #include "system.h" @@ -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 <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_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; } diff --git a/src/sink.h b/src/sink.h new file mode 100644 index 00000000..03523370 --- /dev/null +++ b/src/sink.h @@ -0,0 +1,33 @@ +/* + 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. +*/ + +#ifndef SERD_SINK_H +#define SERD_SINK_H + +#include "serd/serd.h" + +/** + An interface that receives a stream of RDF data. +*/ +struct SerdSinkImpl { + void* handle; + SerdBaseSink base; + SerdPrefixSink prefix; + SerdStatementSink statement; + SerdEndSink end; +}; + +#endif // SERD_SINK_H diff --git a/src/writer.c b/src/writer.c index 4a5d12ab..c11920eb 100644 --- a/src/writer.c +++ b/src/writer.c @@ -18,6 +18,7 @@ #include "env.h" #include "node.h" #include "serd_internal.h" +#include "sink.h" #include "stack.h" #include "string_utils.h" #include "system.h" |