From aebfe13a070ee542929e0ec19b4b2e9221dc1582 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 10 May 2018 19:29:22 +0200 Subject: Add SerdSink interface and hide individual function implementations --- src/reader.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) (limited to 'src/reader.c') diff --git a/src/reader.c b/src/reader.c index 63e45070..fd7acd96 100644 --- a/src/reader.c +++ b/src/reader.c @@ -121,9 +121,9 @@ emit_statement(SerdReader* reader, ReadContext ctx, Ref o) if (!graph && reader->default_graph) { graph = reader->default_graph; } - bool ret = !reader->statement_sink || - !reader->statement_sink( - reader->handle, *ctx.flags, graph, + bool ret = !reader->sink->statement || + !reader->sink->statement( + reader->sink->handle, *ctx.flags, graph, deref(reader, ctx.subject), deref(reader, ctx.predicate), deref(reader, o)); *ctx.flags &= SERD_ANON_CONT|SERD_LIST_CONT; // Preserve only cont flags @@ -155,26 +155,16 @@ serd_reader_read_document(SerdReader* reader) } SerdReader* -serd_reader_new(SerdSyntax syntax, - void* handle, - void (*free_handle)(void*), - SerdBaseSink base_sink, - SerdPrefixSink prefix_sink, - SerdStatementSink statement_sink, - SerdEndSink end_sink) +serd_reader_new(SerdSyntax syntax, const SerdSink* sink) { - SerdReader* me = (SerdReader*)calloc(1, sizeof(SerdReader)); - me->handle = handle; - me->free_handle = free_handle; - me->base_sink = base_sink; - me->prefix_sink = prefix_sink; - me->statement_sink = statement_sink; - me->end_sink = end_sink; - me->default_graph = NULL; - me->stack = serd_stack_new(SERD_PAGE_SIZE); - me->syntax = syntax; - me->next_id = 1; - me->strict = true; + SerdReader* me = (SerdReader*)calloc(1, sizeof(SerdReader)); + + me->sink = sink; + me->default_graph = NULL; + me->stack = serd_stack_new(SERD_PAGE_SIZE); + me->syntax = syntax; + me->next_id = 1; + me->strict = true; me->rdf_first = push_node(me, SERD_URI, NS_RDF "first", 48); me->rdf_rest = push_node(me, SERD_URI, NS_RDF "rest", 47); @@ -211,18 +201,9 @@ serd_reader_free(SerdReader* reader) #endif free(reader->stack.buf); free(reader->bprefix); - if (reader->free_handle) { - reader->free_handle(reader->handle); - } free(reader); } -void* -serd_reader_get_handle(const SerdReader* reader) -{ - return reader->handle; -} - void serd_reader_add_blank_prefix(SerdReader* reader, const char* prefix) -- cgit v1.2.1