diff options
author | David Robillard <d@drobilla.net> | 2018-06-03 19:47:07 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-04-13 19:15:32 +0200 |
commit | 63edb5d1665e7b7a9a4750c063d27a8ae7d75a77 (patch) | |
tree | 77867d26bffa81fa64f8c6b97798134b0327b4e9 /src | |
parent | 6938e50cc21b5acdfbf526e221ac4823f17dba3a (diff) | |
download | serd-63edb5d1665e7b7a9a4750c063d27a8ae7d75a77.tar.gz serd-63edb5d1665e7b7a9a4750c063d27a8ae7d75a77.tar.bz2 serd-63edb5d1665e7b7a9a4750c063d27a8ae7d75a77.zip |
Make statement sink take a statement rather than nodes
This makes the interface more extensible, towards associating more information
with statements. The serd_sink_write_nodes wrapper remains so that user code
does not need to allocate in order to write statement.
Diffstat (limited to 'src')
-rw-r--r-- | src/reader.c | 8 | ||||
-rw-r--r-- | src/sink.c | 13 | ||||
-rw-r--r-- | src/writer.c | 14 |
3 files changed, 19 insertions, 16 deletions
diff --git a/src/reader.c b/src/reader.c index ee27a2fb..40c48a41 100644 --- a/src/reader.c +++ b/src/reader.c @@ -21,6 +21,7 @@ #include "serd/serd.h" #include "serd_internal.h" #include "stack.h" +#include "statement.h" #include "system.h" #include "world.h" @@ -125,9 +126,12 @@ emit_statement(SerdReader* reader, ReadContext ctx, SerdNode* o) (subject and predicate) were already zeroed by subsequent pushes. */ serd_node_zero_pad(o); + const SerdStatement statement = { + { ctx.subject, ctx.predicate, o, graph } + }; + const SerdStatus st = reader->sink->statement( - reader->sink->handle, *ctx.flags, graph, - ctx.subject, ctx.predicate, o); + reader->sink->handle, *ctx.flags, &statement); *ctx.flags &= SERD_ANON_CONT|SERD_LIST_CONT; // Preserve only cont flags return st; } @@ -16,6 +16,8 @@ #include "serd/serd.h" +#include "statement.h" + SerdStatus serd_sink_write_base(const SerdSink* sink, const SerdNode* uri) { @@ -35,12 +37,7 @@ 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)); + return sink->statement(sink->handle, flags, statement); } SerdStatus @@ -51,8 +48,8 @@ serd_sink_write(const SerdSink* sink, const SerdNode* object, const SerdNode* graph) { - return sink->statement( - sink->handle, flags, graph, subject, predicate, object); + const SerdStatement statement = { { subject, predicate, object, graph } }; + return sink->statement(sink->handle, flags, &statement); } SerdStatus diff --git a/src/writer.c b/src/writer.c index b58260a1..692139a6 100644 --- a/src/writer.c +++ b/src/writer.c @@ -685,13 +685,15 @@ write_list_obj(SerdWriter* writer, } static SerdStatus -serd_writer_write_statement(SerdWriter* writer, - SerdStatementFlags flags, - const SerdNode* graph, - const SerdNode* subject, - const SerdNode* predicate, - const SerdNode* object) +serd_writer_write_statement(SerdWriter* writer, + SerdStatementFlags flags, + const SerdStatement* statement) { + const SerdNode* const subject = serd_statement_get_subject(statement); + const SerdNode* const predicate = serd_statement_get_predicate(statement); + const SerdNode* const object = serd_statement_get_object(statement); + const SerdNode* const graph = serd_statement_get_graph(statement); + if (!subject || !predicate || !object || !is_resource(subject) || !is_resource(predicate)) { return SERD_ERR_BAD_ARG; |