summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format34
-rw-r--r--include/sord/sord.h150
-rw-r--r--include/sord/sordmm.hpp6
-rw-r--r--src/sord.c3
-rw-r--r--src/sord_validate.c3
-rw-r--r--src/syntax.c3
-rw-r--r--test/test_sord.c3
7 files changed, 91 insertions, 111 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..255c865
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,34 @@
+# Copyright 2020-2024 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+---
+AlignConsecutiveAssignments: true
+AlignConsecutiveDeclarations: true
+AlignEscapedNewlines: Left
+AttributeMacros:
+ - SORD_API
+ - SORD_LOG_FUNC
+BasedOnStyle: Mozilla
+BraceWrapping:
+ AfterClass: true
+ AfterEnum: false
+ AfterExternBlock: false
+ AfterFunction: true
+ AfterNamespace: false
+ AfterStruct: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+BreakBeforeBraces: Custom
+Cpp11BracedListStyle: true
+IndentCaseLabels: false
+IndentPPDirectives: AfterHash
+KeepEmptyLinesAtTheStartOfBlocks: false
+SpacesInContainerLiterals: false
+StatementMacros:
+ - SORDI_ERROR
+ - SORDI_ERRORF
+ - SORD_ITER_LOG
+ - SORD_LOG
+ - SORD_UNREACHABLE
+ - _Pragma
+...
diff --git a/include/sord/sord.h b/include/sord/sord.h
index 93f9c07..663cb81 100644
--- a/include/sord/sord.h
+++ b/include/sord/sord.h
@@ -126,15 +126,13 @@ typedef enum {
(e.g. nodes) can be shared between worlds, and this should be avoided if
possible for performance reasons.
*/
-SORD_API
-SordWorld*
+SORD_API SordWorld*
sord_world_new(void);
/**
Free `world`.
*/
-SORD_API
-void
+SORD_API void
sord_world_free(SordWorld* world);
/**
@@ -143,8 +141,7 @@ sord_world_free(SordWorld* world);
The `error_sink` will be called with `handle` as its first argument. If
no error function is set, errors are printed to stderr.
*/
-SORD_API
-void
+SORD_API void
sord_world_set_error_sink(SordWorld* world,
SerdErrorSink error_sink,
void* handle);
@@ -161,15 +158,13 @@ sord_world_set_error_sink(SordWorld* world,
Note this function measures `str`, which is a common bottleneck.
Use sord_node_from_serd_node() instead if `str` is already measured.
*/
-SORD_API
-SordNode*
+SORD_API SordNode*
sord_new_uri(SordWorld* world, const uint8_t* uri);
/**
Get a URI node from a relative URI string.
*/
-SORD_API
-SordNode*
+SORD_API SordNode*
sord_new_relative_uri(SordWorld* world,
const uint8_t* uri,
const uint8_t* base_uri);
@@ -180,8 +175,7 @@ sord_new_relative_uri(SordWorld* world,
Note this function measures `str`, which is a common bottleneck.
Use sord_node_from_serd_node() instead if `str` is already measured.
*/
-SORD_API
-SordNode*
+SORD_API SordNode*
sord_new_blank(SordWorld* world, const uint8_t* str);
/**
@@ -190,8 +184,7 @@ sord_new_blank(SordWorld* world, const uint8_t* str);
Note this function measures `str`, which is a common bottleneck.
Use sord_node_from_serd_node() instead if `str` is already measured.
*/
-SORD_API
-SordNode*
+SORD_API SordNode*
sord_new_literal(SordWorld* world,
SordNode* datatype,
const uint8_t* str,
@@ -203,44 +196,38 @@ sord_new_literal(SordWorld* world,
Node that since nodes are interned and reference counted, this does not
actually create a deep copy of `node`.
*/
-SORD_API
-SordNode*
+SORD_API SordNode*
sord_node_copy(const SordNode* node);
/**
Free a node (drop a reference).
*/
-SORD_API
-void
+SORD_API void
sord_node_free(SordWorld* world, SordNode* node);
/**
Return the type of a node (SORD_URI, SORD_BLANK, or SORD_LITERAL).
*/
-SORD_API
-SordNodeType
+SORD_API SordNodeType
sord_node_get_type(const SordNode* node);
/**
Return the string value of a node.
*/
-SORD_API
-const uint8_t*
+SORD_API const uint8_t*
sord_node_get_string(const SordNode* node);
/**
Return the string value of a node, and set `bytes` to its length in bytes.
*/
-SORD_API
-const uint8_t*
+SORD_API const uint8_t*
sord_node_get_string_counted(const SordNode* node, size_t* bytes);
/**
Return the string value of a node, and set `bytes` to its length in bytes,
and `count` to its length in characters.
*/
-SORD_API
-const uint8_t*
+SORD_API const uint8_t*
sord_node_get_string_measured(const SordNode* node,
size_t* bytes,
size_t* chars);
@@ -248,22 +235,19 @@ sord_node_get_string_measured(const SordNode* node,
/**
Return the language of a literal node (or NULL).
*/
-SORD_API
-const char*
+SORD_API const char*
sord_node_get_language(const SordNode* node);
/**
Return the datatype URI of a literal node (or NULL).
*/
-SORD_API
-SordNode*
+SORD_API SordNode*
sord_node_get_datatype(const SordNode* node);
/**
Return the flags (string attributes) of a node.
*/
-SORD_API
-SerdNodeFlags
+SORD_API SerdNodeFlags
sord_node_get_flags(const SordNode* node);
/**
@@ -273,8 +257,7 @@ sord_node_get_flags(const SordNode* node);
of exactly one statement, and therefore can be inlined since it needn't
be referred to by name.
*/
-SORD_API
-bool
+SORD_API bool
sord_node_is_inline_object(const SordNode* node);
/**
@@ -282,8 +265,7 @@ sord_node_is_inline_object(const SordNode* node);
Note this is much faster than comparing the node's strings.
*/
-SORD_API
-bool
+SORD_API bool
sord_node_equals(const SordNode* a, const SordNode* b);
/**
@@ -291,8 +273,7 @@ sord_node_equals(const SordNode* a, const SordNode* b);
The returned node is shared and must not be freed or modified.
*/
-SORD_API
-const SerdNode*
+SORD_API const SerdNode*
sord_node_to_serd_node(const SordNode* node);
/**
@@ -300,8 +281,7 @@ sord_node_to_serd_node(const SordNode* node);
The returned node must be freed using sord_node_free().
*/
-SORD_API
-SordNode*
+SORD_API SordNode*
sord_node_from_serd_node(SordWorld* world,
SerdEnv* env,
const SerdNode* node,
@@ -325,22 +305,19 @@ sord_node_from_serd_node(SordWorld* world,
@param graphs If true, store (and index) graph contexts.
*/
-SORD_API
-SordModel*
+SORD_API SordModel*
sord_new(SordWorld* world, unsigned indices, bool graphs);
/**
Close and free `model`.
*/
-SORD_API
-void
+SORD_API void
sord_free(SordModel* model);
/**
Get the world associated with `model`.
*/
-SORD_API
-SordWorld*
+SORD_API SordWorld*
sord_get_world(SordModel* model);
/**
@@ -348,38 +325,33 @@ sord_get_world(SordModel* model);
Nodes are included in this count iff they are a part of a quad in `world`.
*/
-SORD_API
-size_t
+SORD_API size_t
sord_num_nodes(const SordWorld* world);
/**
Return the number of quads stored in `model`.
*/
-SORD_API
-size_t
+SORD_API size_t
sord_num_quads(const SordModel* model);
/**
Return an iterator to the start of `model`.
*/
-SORD_API
-SordIter*
+SORD_API SordIter*
sord_begin(const SordModel* model);
/**
Search for statements by a quad pattern.
@return an iterator to the first match, or NULL if no matches found.
*/
-SORD_API
-SordIter*
+SORD_API SordIter*
sord_find(SordModel* model, const SordQuad pat);
/**
Search for statements by nodes.
@return an iterator to the first match, or NULL if no matches found.
*/
-SORD_API
-SordIter*
+SORD_API SordIter*
sord_search(SordModel* model,
const SordNode* s,
const SordNode* p,
@@ -392,8 +364,7 @@ sord_search(SordModel* model,
The returned node must be freed using sord_node_free().
@return the first matching node, or NULL if no matches are found.
*/
-SORD_API
-SordNode*
+SORD_API SordNode*
sord_get(SordModel* model,
const SordNode* s,
const SordNode* p,
@@ -403,8 +374,7 @@ sord_get(SordModel* model,
/**
Return true iff a statement exists.
*/
-SORD_API
-bool
+SORD_API bool
sord_ask(SordModel* model,
const SordNode* s,
const SordNode* p,
@@ -414,8 +384,7 @@ sord_ask(SordModel* model,
/**
Return the number of matching statements.
*/
-SORD_API
-uint64_t
+SORD_API uint64_t
sord_count(SordModel* model,
const SordNode* s,
const SordNode* p,
@@ -427,8 +396,7 @@ sord_count(SordModel* model,
@return true if `model` contains a match for `pat`, otherwise false.
*/
-SORD_API
-bool
+SORD_API bool
sord_contains(SordModel* model, const SordQuad pat);
/**
@@ -438,8 +406,7 @@ sord_contains(SordModel* model, const SordQuad pat);
@return true on success, false, on error.
*/
-SORD_API
-bool
+SORD_API bool
sord_add(SordModel* model, const SordQuad tup);
/**
@@ -448,8 +415,7 @@ sord_add(SordModel* model, const SordQuad tup);
Calling this function invalidates all iterators on `model`. To remove quads
while iterating, use sord_erase() instead.
*/
-SORD_API
-void
+SORD_API void
sord_remove(SordModel* model, const SordQuad tup);
/**
@@ -461,8 +427,7 @@ sord_remove(SordModel* model, const SordQuad tup);
@param iter Iterator to the element to erase, which is incremented to the
next value on return.
*/
-SORD_API
-SerdStatus
+SORD_API SerdStatus
sord_erase(SordModel* model, SordIter* iter);
/**
@@ -474,15 +439,13 @@ sord_erase(SordModel* model, SordIter* iter);
/**
Create an inserter for writing statements to a model.
*/
-SORD_API
-SordInserter*
+SORD_API SordInserter*
sord_inserter_new(SordModel* model, SerdEnv* env);
/**
Free an inserter.
*/
-SORD_API
-void
+SORD_API void
sord_inserter_free(SordInserter* inserter);
/**
@@ -490,8 +453,7 @@ sord_inserter_free(SordInserter* inserter);
Note this function can be safely casted to SerdBaseSink.
*/
-SORD_API
-SerdStatus
+SORD_API SerdStatus
sord_inserter_set_base_uri(SordInserter* inserter, const SerdNode* uri);
/**
@@ -499,8 +461,7 @@ sord_inserter_set_base_uri(SordInserter* inserter, const SerdNode* uri);
Note this function can be safely casted to SerdPrefixSink.
*/
-SORD_API
-SerdStatus
+SORD_API SerdStatus
sord_inserter_set_prefix(SordInserter* inserter,
const SerdNode* name,
const SerdNode* uri);
@@ -510,8 +471,7 @@ sord_inserter_set_prefix(SordInserter* inserter,
Note this function can be safely casted to SerdStatementSink.
*/
-SORD_API
-SerdStatus
+SORD_API SerdStatus
sord_inserter_write_statement(SordInserter* inserter,
SerdStatementFlags flags,
const SerdNode* graph,
@@ -530,8 +490,7 @@ sord_inserter_write_statement(SordInserter* inserter,
/**
Set `quad` to the quad pointed to by `iter`.
*/
-SORD_API
-void
+SORD_API void
sord_iter_get(const SordIter* iter, SordQuad tup);
/**
@@ -539,36 +498,31 @@ sord_iter_get(const SordIter* iter, SordQuad tup);
Returns NULL if `iter` is NULL or is at the end.
*/
-SORD_API
-const SordNode*
+SORD_API const SordNode*
sord_iter_get_node(const SordIter* iter, SordQuadIndex index);
/**
Return the store pointed to by `iter`.
*/
-SORD_API
-const SordModel*
+SORD_API const SordModel*
sord_iter_get_model(SordIter* iter);
/**
Increment `iter` to point to the next statement.
*/
-SORD_API
-bool
+SORD_API bool
sord_iter_next(SordIter* iter);
/**
Return true iff `iter` is at the end of its range.
*/
-SORD_API
-bool
+SORD_API bool
sord_iter_end(const SordIter* iter);
/**
Free `iter`.
*/
-SORD_API
-void
+SORD_API void
sord_iter_free(SordIter* iter);
/**
@@ -584,8 +538,7 @@ sord_iter_free(SordIter* iter);
support (ID 0 is a wildcard). It does not actually read node data.
@return true iff `x` and `y` match.
*/
-SORD_API
-bool
+SORD_API bool
sord_quad_match(const SordQuad x, const SordQuad y);
/**
@@ -597,8 +550,7 @@ sord_quad_match(const SordQuad x, const SordQuad y);
/**
Return a reader that will read into `model`.
*/
-SORD_API
-SerdReader*
+SORD_API SerdReader*
sord_new_reader(SordModel* model,
SerdEnv* env,
SerdSyntax syntax,
@@ -607,8 +559,7 @@ sord_new_reader(SordModel* model,
/**
Write a model to a writer.
*/
-SORD_API
-bool
+SORD_API bool
sord_write(SordModel* model, SerdWriter* writer, SordNode* graph);
/**
@@ -616,8 +567,7 @@ sord_write(SordModel* model, SerdWriter* writer, SordNode* graph);
This increments `iter` to its end, then frees it.
*/
-SORD_API
-bool
+SORD_API bool
sord_write_iter(SordIter* iter, SerdWriter* writer);
/**
diff --git a/include/sord/sordmm.hpp b/include/sord/sordmm.hpp
index abd1c33..236e891 100644
--- a/include/sord/sordmm.hpp
+++ b/include/sord/sordmm.hpp
@@ -42,10 +42,10 @@ public:
Noncopyable() = default;
~Noncopyable() = default;
- Noncopyable(const Noncopyable&) = delete;
+ Noncopyable(const Noncopyable&) = delete;
const Noncopyable& operator=(const Noncopyable&) = delete;
- Noncopyable(Noncopyable&&) = delete;
+ Noncopyable(Noncopyable&&) = delete;
Noncopyable& operator=(Noncopyable&&) = delete;
};
@@ -441,7 +441,7 @@ struct Iter : public Wrapper<SordIter> {
, _world(world)
{}
- Iter(const Iter&) = delete;
+ Iter(const Iter&) = delete;
Iter& operator=(const Iter&) = delete;
inline Iter(Iter&& iter) noexcept
diff --git a/src/sord.c b/src/sord.c
index 1adab9e..ed7f40c 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -209,8 +209,7 @@ sord_node_create(const SordNode* const node)
return copy;
}
-SORD_LOG_FUNC(3, 4)
-static void
+SORD_LOG_FUNC(3, 4) static void
error(SordWorld* world, SerdStatus st, const char* fmt, ...)
{
va_list args;
diff --git a/src/sord_validate.c b/src/sord_validate.c
index 47c2051..094c421 100644
--- a/src/sord_validate.c
+++ b/src/sord_validate.c
@@ -132,8 +132,7 @@ absolute_path(const uint8_t* path)
#endif
}
-SORD_LOG_FUNC(2, 3)
-static int
+SORD_LOG_FUNC(2, 3) static int
errorf(const SordQuad quad, const char* fmt, ...)
{
va_list args;
diff --git a/src/syntax.c b/src/syntax.c
index b15eccc..dc80180 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -79,8 +79,7 @@ sord_inserter_write_statement(SordInserter* inserter,
return SERD_SUCCESS;
}
-SORD_API
-SerdReader*
+SORD_API SerdReader*
sord_new_reader(SordModel* model,
SerdEnv* env,
SerdSyntax syntax,
diff --git a/test/test_sord.c b/test/test_sord.c
index 7ad9da7..df5e398 100644
--- a/test/test_sord.c
+++ b/test/test_sord.c
@@ -41,8 +41,7 @@ uri(SordWorld* world, unsigned num)
return sord_new_uri(world, (const uint8_t*)str);
}
-SORD_LOG_FUNC(1, 2)
-static int
+SORD_LOG_FUNC(1, 2) static int
test_fail(const char* fmt, ...)
{
va_list args;