aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd/sink.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-03-01 19:38:01 -0500
committerDavid Robillard <d@drobilla.net>2023-12-02 16:27:02 -0500
commitc2e59da8865a8c5719b8ddaf5f68204729a8ebab (patch)
tree4a8c2eb24c4a274eac41a226df6679a6319b6ac4 /include/serd/sink.h
parentb631e7a3d6a807aaf4919396b62ba96e1a9f0bd9 (diff)
downloadserd-c2e59da8865a8c5719b8ddaf5f68204729a8ebab.tar.gz
serd-c2e59da8865a8c5719b8ddaf5f68204729a8ebab.tar.bz2
serd-c2e59da8865a8c5719b8ddaf5f68204729a8ebab.zip
Add SerdSink interface and hide implementations
Diffstat (limited to 'include/serd/sink.h')
-rw-r--r--include/serd/sink.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/include/serd/sink.h b/include/serd/sink.h
index 702197d5..f24db683 100644
--- a/include/serd/sink.h
+++ b/include/serd/sink.h
@@ -56,6 +56,74 @@ typedef SerdStatus (*SerdStatementFunc)(void* SERD_NULLABLE handle,
typedef SerdStatus (*SerdEndFunc)(void* SERD_NULLABLE handle,
const SerdNode* SERD_NONNULL node);
+/// An interface that receives a stream of RDF data
+typedef struct SerdSinkImpl SerdSink;
+
+/// Function to free an opaque handle
+typedef void (*SerdFreeFunc)(void* SERD_NULLABLE ptr);
+
+/**
+ Create a new sink.
+
+ Initially, the sink has no set functions and will do nothing. Use the
+ serd_sink_set_*_func functions to set handlers for various events.
+
+ @param handle Opaque handle that will be passed to sink functions.
+ @param free_handle Free function to call on handle in serd_sink_free().
+*/
+SERD_API SerdSink* SERD_ALLOCATED
+serd_sink_new(void* SERD_NULLABLE handle,
+ SerdFreeFunc SERD_NULLABLE free_handle);
+
+/// Free `sink`
+SERD_API void
+serd_sink_free(SerdSink* SERD_NULLABLE sink);
+
+/// Set a function to be called when the base URI changes
+SERD_API SerdStatus
+serd_sink_set_base_func(SerdSink* SERD_NONNULL sink,
+ SerdBaseFunc SERD_NULLABLE base_func);
+
+/// Set a function to be called when a namespace prefix is defined
+SERD_API SerdStatus
+serd_sink_set_prefix_func(SerdSink* SERD_NONNULL sink,
+ SerdPrefixFunc SERD_NULLABLE prefix_func);
+
+/// Set a function to be called when a statement is emitted
+SERD_API SerdStatus
+serd_sink_set_statement_func(SerdSink* SERD_NONNULL sink,
+ SerdStatementFunc SERD_NULLABLE statement_func);
+
+/// Set a function to be called when an anonymous node ends
+SERD_API SerdStatus
+serd_sink_set_end_func(SerdSink* SERD_NONNULL sink,
+ SerdEndFunc SERD_NULLABLE end_func);
+
+/// Set the base URI
+SERD_API SerdStatus
+serd_sink_write_base(const SerdSink* SERD_NONNULL sink,
+ const SerdNode* SERD_NONNULL uri);
+
+/// Set a namespace prefix
+SERD_API SerdStatus
+serd_sink_write_prefix(const SerdSink* SERD_NONNULL sink,
+ const SerdNode* SERD_NONNULL name,
+ const SerdNode* SERD_NONNULL uri);
+
+/// Write a statement from individual nodes
+SERD_API SerdStatus
+serd_sink_write(const SerdSink* SERD_NONNULL sink,
+ SerdStatementFlags flags,
+ const SerdNode* SERD_NONNULL subject,
+ const SerdNode* SERD_NONNULL predicate,
+ const SerdNode* SERD_NONNULL object,
+ const SerdNode* SERD_NULLABLE graph);
+
+/// Mark the end of an anonymous node
+SERD_API SerdStatus
+serd_sink_write_end(const SerdSink* SERD_NONNULL sink,
+ const SerdNode* SERD_NONNULL node);
+
/**
@}
*/