aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd/serd.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/serd/serd.h')
-rw-r--r--include/serd/serd.h95
1 files changed, 89 insertions, 6 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 611b0176..49cfcee4 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -893,6 +893,9 @@ serd_caret_column(const SerdCaret* SERD_NONNULL caret);
@{
*/
+/// A subject, predicate, and object, with optional graph context
+typedef struct SerdStatementImpl SerdStatement;
+
/// Index of a node in a statement
typedef enum {
SERD_SUBJECT = 0, ///< Subject
@@ -902,6 +905,81 @@ typedef enum {
} SerdField;
/**
+ Create a new statement.
+
+ Note that, to minimise model overhead, statements do not own their nodes, so
+ they must have a longer lifetime than the statement for it to be valid. For
+ statements in models, this is the lifetime of the model. For user-created
+ statements, the simplest way to handle this is to use `SerdNodes`.
+
+ @param s The subject
+ @param p The predicate ("key")
+ @param o The object ("value")
+ @param g The graph ("context")
+ @param caret Optional caret at the origin of this statement
+ @return A new statement that must be freed with serd_statement_free()
+*/
+SERD_API
+SerdStatement* SERD_ALLOCATED
+serd_statement_new(const SerdNode* SERD_NONNULL s,
+ const SerdNode* SERD_NONNULL p,
+ const SerdNode* SERD_NONNULL o,
+ const SerdNode* SERD_NULLABLE g,
+ const SerdCaret* SERD_NULLABLE caret);
+
+/// Return a copy of `statement`
+SERD_API
+SerdStatement* SERD_ALLOCATED
+serd_statement_copy(const SerdStatement* SERD_NULLABLE statement);
+
+/// Free `statement`
+SERD_API
+void
+serd_statement_free(SerdStatement* SERD_NULLABLE statement);
+
+/// Return the given node of the statement
+SERD_PURE_API
+const SerdNode* SERD_NULLABLE
+serd_statement_node(const SerdStatement* SERD_NONNULL statement,
+ SerdField field);
+
+/// Return the subject of the statement
+SERD_PURE_API
+const SerdNode* SERD_NONNULL
+serd_statement_subject(const SerdStatement* SERD_NONNULL statement);
+
+/// Return the predicate of the statement
+SERD_PURE_API
+const SerdNode* SERD_NONNULL
+serd_statement_predicate(const SerdStatement* SERD_NONNULL statement);
+
+/// Return the object of the statement
+SERD_PURE_API
+const SerdNode* SERD_NONNULL
+serd_statement_object(const SerdStatement* SERD_NONNULL statement);
+
+/// Return the graph of the statement
+SERD_PURE_API
+const SerdNode* SERD_NULLABLE
+serd_statement_graph(const SerdStatement* SERD_NONNULL statement);
+
+/// Return the source location where the statement originated, or NULL
+SERD_PURE_API
+const SerdCaret* SERD_NULLABLE
+serd_statement_caret(const SerdStatement* SERD_NONNULL statement);
+
+/**
+ Return true iff `a` is equal to `b`, ignoring statement caret metadata.
+
+ Only returns true if nodes are equivalent, does not perform wildcard
+ matching.
+*/
+SERD_PURE_API
+bool
+serd_statement_equals(const SerdStatement* SERD_NULLABLE a,
+ const SerdStatement* SERD_NULLABLE b);
+
+/**
@}
@defgroup serd_world World
@{
@@ -1007,12 +1085,10 @@ typedef SerdStatus (*SerdPrefixFunc)(void* SERD_NULLABLE handle,
Called for every RDF statement in the serialisation.
*/
-typedef SerdStatus (*SerdStatementFunc)(void* SERD_NULLABLE handle,
- SerdStatementFlags flags,
- const SerdNode* SERD_NULLABLE graph,
- const SerdNode* SERD_NONNULL subject,
- const SerdNode* SERD_NONNULL predicate,
- const SerdNode* SERD_NONNULL object);
+typedef SerdStatus (*SerdStatementFunc)(void* SERD_NULLABLE handle,
+ SerdStatementFlags flags,
+ const SerdStatement* SERD_NONNULL
+ statement);
/**
Sink function for anonymous node end markers.
@@ -1092,6 +1168,13 @@ serd_sink_write_prefix(const SerdSink* SERD_NONNULL sink,
const SerdNode* SERD_NONNULL name,
const SerdNode* SERD_NONNULL uri);
+/// Write a statement
+SERD_API
+SerdStatus
+serd_sink_write_statement(const SerdSink* SERD_NONNULL sink,
+ SerdStatementFlags flags,
+ const SerdStatement* SERD_NONNULL statement);
+
/// Write a statement from individual nodes
SERD_API
SerdStatus