diff options
author | David Robillard <d@drobilla.net> | 2012-03-18 15:41:58 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-03-18 15:41:58 +0000 |
commit | 91ae836711ba3df5f44407dadcadb0bd9ac53621 (patch) | |
tree | f01047babb9d09230aa8a774e20bbe7cff505c3e /src | |
parent | 90830a30aa7e16b4ebb3a249f1456da174b1eca3 (diff) | |
download | serd-91ae836711ba3df5f44407dadcadb0bd9ac53621.tar.gz serd-91ae836711ba3df5f44407dadcadb0bd9ac53621.tar.bz2 serd-91ae836711ba3df5f44407dadcadb0bd9ac53621.zip |
Add serd_reader_set_default_graph() for reading a file as a named graph.
git-svn-id: http://svn.drobilla.net/serd/trunk@338 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src')
-rw-r--r-- | src/reader.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/reader.c b/src/reader.c index 7e9bb3d4..23ef9fef 100644 --- a/src/reader.c +++ b/src/reader.c @@ -67,6 +67,7 @@ struct SerdReaderImpl { Ref rdf_first; Ref rdf_rest; Ref rdf_nil; + SerdNode default_graph; FILE* fd; SerdStack stack; SerdSyntax syntax; @@ -236,9 +237,13 @@ pop_node(SerdReader* reader, Ref ref) static inline bool emit_statement(SerdReader* reader, ReadContext ctx, Ref o, Ref d, Ref l) { + SerdNode* graph = deref(reader, ctx.graph); + if (!graph && reader->default_graph.buf) { + graph = &reader->default_graph; + } bool ret = !reader->statement_sink || !reader->statement_sink( - reader->handle, *ctx.flags, deref(reader, ctx.graph), + reader->handle, *ctx.flags, graph, deref(reader, ctx.subject), deref(reader, ctx.predicate), deref(reader, o), deref(reader, d), deref(reader, l)); *ctx.flags &= SERD_ANON_CONT|SERD_LIST_CONT; // Preserve only cont flags @@ -1354,6 +1359,7 @@ serd_reader_new(SerdSyntax syntax, me->prefix_sink = prefix_sink; me->statement_sink = statement_sink; me->end_sink = end_sink; + me->default_graph = SERD_NODE_NULL; me->fd = 0; me->stack = serd_stack_new(SERD_PAGE_SIZE); me->syntax = syntax; @@ -1384,6 +1390,7 @@ serd_reader_free(SerdReader* reader) pop_node(reader, reader->rdf_nil); pop_node(reader, reader->rdf_rest); pop_node(reader, reader->rdf_first); + serd_node_free(&reader->default_graph); #ifdef SERD_STACK_CHECK free(reader->allocs); @@ -1417,6 +1424,15 @@ serd_reader_add_blank_prefix(SerdReader* reader, memcpy(reader->bprefix, prefix, reader->bprefix_len + 1); } } + +SERD_API +void +serd_reader_set_default_graph(SerdReader* reader, + const SerdNode* graph) +{ + serd_node_free(&reader->default_graph); + reader->default_graph = serd_node_copy(graph); +} SERD_API SerdStatus |