diff options
author | David Robillard <d@drobilla.net> | 2011-02-25 07:28:10 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-02-25 07:28:10 +0000 |
commit | ddd073f0a1c47e5dbba2efd04617862e49171bed (patch) | |
tree | a3059f6da6da72fb17b6e47b059fad8e8ab4008a /serd | |
parent | 7cab293e741784109f9e0a6a3893d3c6629da999 (diff) | |
download | serd-ddd073f0a1c47e5dbba2efd04617862e49171bed.tar.gz serd-ddd073f0a1c47e5dbba2efd04617862e49171bed.tar.bz2 serd-ddd073f0a1c47e5dbba2efd04617862e49171bed.zip |
Abstract common read state tracking code (SerdReadState) to make user code less tedious.
git-svn-id: http://svn.drobilla.net/serd/trunk@110 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'serd')
-rw-r--r-- | serd/serd.h | 63 |
1 files changed, 58 insertions, 5 deletions
diff --git a/serd/serd.h b/serd/serd.h index 803ddea7..a56ab971 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -63,7 +63,7 @@ extern "C" { */ /** - Namespace prefixes. + Environment (namespace prefixes). A SerdEnv represents a set of namespace prefixes, and is used to resolve CURIEs to full URIs. @@ -79,6 +79,16 @@ typedef struct SerdEnvImpl* SerdEnv; typedef struct SerdReaderImpl* SerdReader; /** + Read state. + + This represents state (context) necessary for fully resolving URIs during a + read (i.e. the base URI and namespace prefixes). It is implemented + separately from SerdReader so the reader can avoid the overhead in cases + where this information is unnecessary (e.g. streaming reserialisation). +*/ +typedef struct SerdReadStateImpl* SerdReadState; + +/** RDF writer. A SerdWriter provides a number of functions to allow writing RDF syntax out @@ -330,7 +340,7 @@ serd_node_free(SerdNode* node); */ /** - Sink for base URI changes. + Sink (callback) for base URI changes. Called whenever the base URI of the serialisation changes. */ @@ -338,7 +348,7 @@ typedef bool (*SerdBaseSink)(void* handle, const SerdNode* uri); /** - Sink for namespace definitions. + Sink (callback) for namespace definitions. Called whenever a prefix is defined in the serialisation. */ @@ -347,7 +357,7 @@ typedef bool (*SerdPrefixSink)(void* handle, const SerdNode* uri); /** - Sink for statements. + Sink (callback) for statements. Called for every RDF statement in the serialisation. */ @@ -360,7 +370,7 @@ typedef bool (*SerdStatementSink)(void* handle, const SerdNode* object_lang); /** - Sink for anonymous node end markers. + Sink (callback) for anonymous node end markers. This is called to indicate that the anonymous node with the given @a value will no longer be referred to by any future statements @@ -483,6 +493,49 @@ void serd_reader_free(SerdReader reader); /** + Create a new read state with the given initial base URI and environment. + + A reference to @a env will be kept, and @a env will be modified as the + state is modified. +*/ +SERD_API +SerdReadState +serd_read_state_new(SerdEnv env, + const uint8_t* base_uri_str); + +/** + Free @a state. +*/ +SERD_API +void +serd_read_state_free(SerdReadState state); + +/** + Get the current base URI. +*/ +SERD_API +SerdNode +serd_read_state_get_base_uri(SerdReadState state, + SerdURI* out); + +/** + Set the current base URI. +*/ +SERD_API +bool +serd_read_state_set_base_uri(SerdReadState state, + const SerdNode* uri_node); + +/** + Set a namespace prefix. +*/ +SERD_API +bool +serd_read_state_set_prefix(SerdReadState state, + const SerdNode* name, + const SerdNode* uri_node); + +/** @} @name SerdWriter @{ |