aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-15 15:15:55 -0400
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit0aff74b23f4d85d7f157f25d399c14b6a78e998b (patch)
tree917ef773266f5b9417a1c394f2f8451ae774a49c /src
parent9baa0127ea016c3ee409a64563b960cff135bbdb (diff)
downloadserd-0aff74b23f4d85d7f157f25d399c14b6a78e998b.tar.gz
serd-0aff74b23f4d85d7f157f25d399c14b6a78e998b.tar.bz2
serd-0aff74b23f4d85d7f157f25d399c14b6a78e998b.zip
Make SerdSink opaque
Diffstat (limited to 'src')
-rw-r--r--src/n3.c1
-rw-r--r--src/reader.c1
-rw-r--r--src/sink.c62
-rw-r--r--src/sink.h33
-rw-r--r--src/writer.c1
5 files changed, 90 insertions, 8 deletions
diff --git a/src/n3.c b/src/n3.c
index a21135ea..905fa9e4 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -18,6 +18,7 @@
#include "node.h"
#include "reader.h"
#include "serd_internal.h"
+#include "sink.h"
#include "stack.h"
#include "string_utils.h"
#include "uri_utils.h"
diff --git a/src/reader.c b/src/reader.c
index f8cd27be..b92d1e5a 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -18,6 +18,7 @@
#include "system.h"
#include "serd_internal.h"
+#include "sink.h"
#include "statement.h"
#include "world.h"
diff --git a/src/sink.c b/src/sink.c
index 40071d72..c8a0dd62 100644
--- a/src/sink.c
+++ b/src/sink.c
@@ -1,5 +1,5 @@
/*
- Copyright 2011-2018 David Robillard <http://drobilla.net>
+ Copyright 2011-2020 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
@@ -14,16 +14,61 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include "serd/serd.h"
+#include "sink.h"
#include "statement.h"
-#include <stddef.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_write_base(const SerdSink* sink, const SerdNode* uri)
{
- return sink->base(sink->handle, uri);
+ return sink->base ? sink->base(sink->handle, uri) : SERD_SUCCESS;
}
SerdStatus
@@ -31,7 +76,7 @@ serd_sink_write_prefix(const 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
@@ -39,7 +84,8 @@ serd_sink_write_statement(const 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
@@ -52,11 +98,11 @@ serd_sink_write(const 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_write_end(const 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..25dfb079
--- /dev/null
+++ b/src/sink.h
@@ -0,0 +1,33 @@
+/*
+ Copyright 2011-2020 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 adfb64b2..4b5b1245 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 "uri_utils.h"