summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-04-27 23:27:41 +0000
committerDavid Robillard <d@drobilla.net>2011-04-27 23:27:41 +0000
commitbb2c564579a402a92dbaa513b6a4c9641523efc5 (patch)
tree7510282f5c74ad876dd2ea0d472b3108c3c4ac4b
parentb9dee426536cf2a21fa7976dd27b8839f349c534 (diff)
downloadsord-bb2c564579a402a92dbaa513b6a4c9641523efc5.tar.gz
sord-bb2c564579a402a92dbaa513b6a4c9641523efc5.tar.bz2
sord-bb2c564579a402a92dbaa513b6a4c9641523efc5.zip
Don't hide pointers behind typedefs.
git-svn-id: http://svn.drobilla.net/sord/trunk@91 3d64ff67-21c5-427c-a301-fe4f08042e5a
-rw-r--r--sord/sord.h160
-rw-r--r--sord/sordmm.hpp33
-rw-r--r--src/sord.c235
-rw-r--r--src/sord_internal.h6
-rw-r--r--src/sord_test.c38
-rw-r--r--src/sordi.c24
-rw-r--r--src/syntax.c50
7 files changed, 269 insertions, 277 deletions
diff --git a/sord/sord.h b/sord/sord.h
index 61a3e79..5e9df0a 100644
--- a/sord/sord.h
+++ b/sord/sord.h
@@ -62,7 +62,7 @@ extern "C" {
Sord World.
The World represents all library state, including interned strings.
*/
-typedef struct _SordWorld* SordWorld;
+typedef struct SordWorldImpl SordWorld;
/**
Sord Model.
@@ -71,12 +71,12 @@ typedef struct _SordWorld* SordWorld;
graphs). It may be searched using various patterns depending on which
indices are enabled.
*/
-typedef struct _SordModel* SordModel;
+typedef struct SordModelImpl SordModel;
/**
Model Iterator.
*/
-typedef struct _SordIter* SordIter;
+typedef struct SordIterImpl SordIter;
/**
RDF Node.
@@ -84,14 +84,14 @@ typedef struct _SordIter* SordIter;
(in the case of quad objects only) string literals. Literal nodes may
have an associate language or datatype (but not both).
*/
-typedef struct _SordNode* SordNode;
+typedef struct SordNodeImpl SordNode;
/**
- Quad of IDs (statement), or a quad pattern.
+ Quad of nodes (i.e. a statement), or a quad pattern.
Nodes are ordered (S P O G). The ID of the default graph is 0.
*/
-typedef SordNode SordQuad[4];
+typedef SordNode* SordQuad[4];
/**
Index into a SordQuad.
@@ -136,7 +136,7 @@ typedef enum {
possible for performance reasons.
*/
SORD_API
-SordWorld
+SordWorld*
sord_world_new(void);
/**
@@ -144,7 +144,7 @@ sord_world_new(void);
*/
SORD_API
void
-sord_world_free(SordWorld world);
+sord_world_free(SordWorld* world);
/**
@}
@@ -158,15 +158,15 @@ sord_world_free(SordWorld world);
Use sord_get_uri_counted instead if the length of @c str is known.
*/
SORD_API
-SordNode
-sord_new_uri(SordWorld world, const uint8_t* str);
+SordNode*
+sord_new_uri(SordWorld* world, const uint8_t* str);
/**
Find a URI, creating a new one if necessary iff @c create is true.
*/
SORD_API
-SordNode
-sord_new_uri_counted(SordWorld world,
+SordNode*
+sord_new_uri_counted(SordWorld* world,
const uint8_t* str,
size_t str_len);
@@ -176,15 +176,15 @@ sord_new_uri_counted(SordWorld world,
Use sord_get_blank_counted instead if the length of @c str is known.
*/
SORD_API
-SordNode
-sord_new_blank(SordWorld world, const uint8_t* str);
+SordNode*
+sord_new_blank(SordWorld* world, const uint8_t* str);
/**
Find a blank, creating a new one if necessary iff @c create is true.
*/
SORD_API
-SordNode
-sord_new_blank_counted(SordWorld world,
+SordNode*
+sord_new_blank_counted(SordWorld* world,
const uint8_t* str,
size_t str_len);
@@ -194,9 +194,9 @@ sord_new_blank_counted(SordWorld world,
Use sord_get_literal_counted instead if the length of @c str is known.
*/
SORD_API
-SordNode
-sord_new_literal(SordWorld world,
- SordNode datatype,
+SordNode*
+sord_new_literal(SordWorld* world,
+ SordNode* datatype,
const uint8_t* str,
const char* lang);
@@ -204,9 +204,9 @@ sord_new_literal(SordWorld world,
Find a literal, creating a new one if necessary iff @c create is true.
*/
SORD_API
-SordNode
-sord_new_literal_counted(SordWorld world,
- SordNode datatype,
+SordNode*
+sord_new_literal_counted(SordWorld* world,
+ SordNode* datatype,
const uint8_t* str,
size_t str_len,
const char* lang,
@@ -214,52 +214,55 @@ sord_new_literal_counted(SordWorld world,
/**
Copy a node.
+
+ Node that since nodes are interned and reference counted, this does not
+ actually create a deep copy of @c node.
*/
SORD_API
-SordNode
-sord_node_copy(SordNode node);
+SordNode*
+sord_node_copy(SordNode* node);
/**
Free a node.
*/
SORD_API
void
-sord_node_free(SordWorld world, SordNode node);
+sord_node_free(SordWorld* world, SordNode* node);
/**
Return the type of a node (SORD_URI, SORD_BLANK, or SORD_LITERAL).
*/
SORD_API
SordNodeType
-sord_node_get_type(SordNode node);
+sord_node_get_type(const SordNode* node);
/**
Return the string value of a node.
*/
SORD_API
const uint8_t*
-sord_node_get_string(SordNode node);
+sord_node_get_string(const SordNode* node);
/**
Return the string value of a node, and set @c len to its length.
*/
SORD_API
const uint8_t*
-sord_node_get_string_counted(SordNode node, size_t* len);
+sord_node_get_string_counted(const SordNode* node, size_t* len);
/**
Return the language of a literal node (or NULL).
*/
SORD_API
const char*
-sord_node_get_language(SordNode node);
+sord_node_get_language(const SordNode* node);
/**
Return the datatype URI of a literal node (or NULL).
*/
SORD_API
-SordNode
-sord_node_get_datatype(SordNode node);
+SordNode*
+sord_node_get_datatype(const SordNode* node);
/**
Return true iff @c a is equal to @c b.
@@ -268,8 +271,8 @@ sord_node_get_datatype(SordNode node);
*/
SORD_API
bool
-sord_node_equals(const SordNode a,
- const SordNode b);
+sord_node_equals(const SordNode* a,
+ const SordNode* b);
/**
@}
@@ -289,8 +292,8 @@ sord_node_equals(const SordNode a,
@param graphs If true, store (and index) graph contexts.
*/
SORD_API
-SordModel
-sord_new(SordWorld world,
+SordModel*
+sord_new(SordWorld* world,
unsigned indices,
bool graphs);
@@ -299,14 +302,14 @@ sord_new(SordWorld world,
*/
SORD_API
void
-sord_free(SordModel model);
+sord_free(SordModel* model);
/**
Get the world associated with @c model.
*/
SORD_API
-SordWorld
-sord_get_world(SordModel model);
+SordWorld*
+sord_get_world(SordModel* model);
/**
Return the number of nodes stored in @c sord.
@@ -315,52 +318,45 @@ sord_get_world(SordModel model);
*/
SORD_API
int
-sord_num_nodes(SordWorld world);
+sord_num_nodes(const SordWorld* world);
/**
Return the number of quads stored in @c sord.
*/
SORD_API
int
-sord_num_quads(SordModel model);
+sord_num_quads(const SordModel* model);
/**
Return an iterator to the start of the store.
*/
SORD_API
-SordIter
-sord_begin(SordModel model);
-
-/**
- Return an iterator that will iterate over each graph URI.
-*/
-SORD_API
-SordIter
-sord_graphs_begin(SordModel model);
+SordIter*
+sord_begin(const SordModel* model);
/**
Search for a triple pattern.
@return an iterator to the first match, or NULL if no matches found.
*/
SORD_API
-SordIter
-sord_find(SordModel model, const SordQuad pat);
+SordIter*
+sord_find(SordModel* model, const SordQuad pat);
/**
Add a quad to the store.
*/
SORD_API
bool
-sord_add(SordModel model, const SordQuad quad);
+sord_add(SordModel* model, const SordQuad quad);
/**
Remove a quad from the store.
- Note that is it illegal to remove while iterator over @c model.
+ Note that is it illegal to remove while iterating over @c model.
*/
SORD_API
void
-sord_remove(SordModel model, const SordQuad quad);
+sord_remove(SordModel* model, const SordQuad quad);
/**
@}
@@ -373,35 +369,35 @@ sord_remove(SordModel model, const SordQuad quad);
*/
SORD_API
void
-sord_iter_get(SordIter iter, SordQuad quad);
+sord_iter_get(const SordIter* iter, SordQuad quad);
/**
Return the store pointed to by @c iter.
*/
SORD_API
-SordModel
-sord_iter_get_model(SordIter iter);
+const SordModel*
+sord_iter_get_model(SordIter* iter);
/**
Increment @c iter to point to the next statement.
*/
SORD_API
bool
-sord_iter_next(SordIter iter);
+sord_iter_next(SordIter* iter);
/**
Return true iff @c iter is at the end of its range.
*/
SORD_API
bool
-sord_iter_end(SordIter iter);
+sord_iter_end(const SordIter* iter);
/**
Free @c iter.
*/
SORD_API
void
-sord_iter_free(SordIter iter);
+sord_iter_free(SordIter* iter);
/**
@}
@@ -428,45 +424,45 @@ sord_quad_match(const SordQuad x, const SordQuad y);
SORD_API
bool
-sord_read_file(SordModel model,
- const uint8_t* uri,
- const SordNode graph,
- const uint8_t* blank_prefix);
+sord_read_file(SordModel* model,
+ const uint8_t* uri,
+ SordNode* graph,
+ const uint8_t* blank_prefix);
SORD_API
bool
-sord_read_file_handle(SordModel model,
- FILE* fd,
- const uint8_t* base_uri,
- const SordNode graph,
- const uint8_t* blank_prefix);
+sord_read_file_handle(SordModel* model,
+ FILE* fd,
+ const uint8_t* base_uri,
+ SordNode* graph,
+ const uint8_t* blank_prefix);
SORD_API
bool
-sord_read_string(SordModel model,
+sord_read_string(SordModel* model,
const uint8_t* str,
const uint8_t* base_uri);
SORD_API
bool
-sord_write_file(SordModel model,
- SerdEnv* env,
- const uint8_t* uri,
- const SordNode graph,
- const uint8_t* blank_prefix);
+sord_write_file(SordModel* model,
+ SerdEnv* env,
+ const uint8_t* uri,
+ SordNode* graph,
+ const uint8_t* blank_prefix);
SORD_API
bool
-sord_write_file_handle(SordModel model,
- SerdEnv* env,
- FILE* fd,
- const uint8_t* base_uri,
- const SordNode graph,
- const uint8_t* blank_prefix);
+sord_write_file_handle(SordModel* model,
+ SerdEnv* env,
+ FILE* fd,
+ const uint8_t* base_uri,
+ SordNode* graph,
+ const uint8_t* blank_prefix);
SORD_API
uint8_t*
-sord_write_string(SordModel model,
+sord_write_string(SordModel* model,
SerdEnv* env,
const uint8_t* base_uri);
diff --git a/sord/sordmm.hpp b/sord/sordmm.hpp
index d8e61fa..8c0dc10 100644
--- a/sord/sordmm.hpp
+++ b/sord/sordmm.hpp
@@ -97,7 +97,7 @@ public:
};
/** Sord library state. */
-class World : public boost::noncopyable, public Wrapper<SordWorld> {
+class World : public boost::noncopyable, public Wrapper<SordWorld*> {
public:
inline World()
: _next_blank_id(0)
@@ -117,7 +117,7 @@ public:
}
inline const Namespaces& prefixes() const { return _prefixes; }
- inline SordWorld world() { return _c_obj; }
+ inline SordWorld* world() { return _c_obj; }
private:
Namespaces _prefixes;
@@ -127,7 +127,7 @@ private:
/** An RDF Node (resource, literal, etc)
*/
-class Node : public Wrapper<SordNode> {
+class Node : public Wrapper<SordNode*> {
public:
enum Type {
UNKNOWN = 0,
@@ -136,11 +136,11 @@ public:
LITERAL = SORD_LITERAL
};
- inline Node() : Wrapper<SordNode>(NULL), _world(NULL) {}
+ inline Node() : Wrapper<SordNode*>(NULL), _world(NULL) {}
inline Node(World& world, Type t, const std::string& s);
inline Node(World& world);
- inline Node(World& world, SordNode node);
+ inline Node(World& world, SordNode* node);
inline Node(const Node& other);
inline ~Node();
@@ -148,7 +148,8 @@ public:
return _c_obj ? (Type)sord_node_get_type(_c_obj) : UNKNOWN;
}
- inline SordNode get_node() const { return _c_obj; }
+ inline const SordNode* get_node() const { return _c_obj; }
+ inline SordNode* get_node() { return _c_obj; }
inline bool is_valid() const { return type() != UNKNOWN; }
@@ -259,7 +260,7 @@ Node::Node(World& world)
}
inline
-Node::Node(World& world, SordNode node)
+Node::Node(World& world, SordNode* node)
: _world(&world)
{
_c_obj = node ? sord_node_copy(node) : NULL;
@@ -267,7 +268,7 @@ Node::Node(World& world, SordNode node)
inline
Node::Node(const Node& other)
- : Wrapper<SordNode>()
+ : Wrapper<SordNode*>()
, _world(other._world)
{
if (_world) {
@@ -307,7 +308,7 @@ inline bool
Node::is_literal_type(const char* type_uri) const
{
if (_c_obj && sord_node_get_type(_c_obj) == SORD_LITERAL) {
- SordNode datatype = sord_node_get_datatype(_c_obj);
+ const SordNode* datatype = sord_node_get_datatype(_c_obj);
if (datatype && !strcmp((const char*)sord_node_get_string(datatype),
type_uri))
return true;
@@ -346,24 +347,24 @@ Node::to_bool() const
return !strcmp((const char*)sord_node_get_string(_c_obj), "true");
}
-struct Iter : public Wrapper<SordIter> {
- inline Iter(World& world, SordIter c_obj)
- : Wrapper<SordIter>(c_obj), _world(world) {}
+struct Iter : public Wrapper<SordIter*> {
+ inline Iter(World& world, SordIter* c_obj)
+ : Wrapper<SordIter*>(c_obj), _world(world) {}
inline ~Iter() { sord_iter_free(_c_obj); }
inline bool end() const { return sord_iter_end(_c_obj); }
inline bool next() const { return sord_iter_next(_c_obj); }
inline Iter& operator++() { assert(!end()); next(); return *this; }
- inline Node get_subject() const {
+ inline const Node get_subject() const {
SordQuad quad;
sord_iter_get(_c_obj, quad);
return Node(_world, quad[SORD_SUBJECT]);
}
- inline Node get_predicate() const {
+ inline const Node get_predicate() const {
SordQuad quad;
sord_iter_get(_c_obj, quad);
return Node(_world, quad[SORD_PREDICATE]);
}
- inline Node get_object() const {
+ inline const Node get_object() const {
SordQuad quad;
sord_iter_get(_c_obj, quad);
return Node(_world, quad[SORD_OBJECT]);
@@ -373,7 +374,7 @@ struct Iter : public Wrapper<SordIter> {
/** An RDF Model (collection of triples).
*/
-class Model : public boost::noncopyable, public Wrapper<SordModel> {
+class Model : public boost::noncopyable, public Wrapper<SordModel*> {
public:
inline Model(World& world, const Glib::ustring& base_uri=".");
inline ~Model();
diff --git a/src/sord.c b/src/sord.c
index 3843e2c..599d35f 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -97,7 +97,7 @@ static const int orderings[NUM_ORDERS][TUP_LEN] = {
};
/** World */
-struct _SordWorld {
+struct SordWorldImpl {
GHashTable* names; ///< URI or blank node identifier string => ID
GHashTable* langs; ///< Language tag => Interned language tag
GHashTable* literals; ///< Literal => ID
@@ -105,8 +105,8 @@ struct _SordWorld {
};
/** Store */
-struct _SordModel {
- SordWorld world;
+struct SordModelImpl {
+ SordWorld* world;
/** Index for each possible triple ordering (may or may not exist).
* If an index for e.g. SPO exists, it is a dictionary with
@@ -127,29 +127,29 @@ typedef enum {
} SearchMode;
/** Iterator over some range of a store */
-struct _SordIter {
- SordModel sord; ///< Store this is an iterator for
- GSequenceIter* cur; ///< Current DB cursor
- SordQuad pat; ///< Iteration pattern (in ordering order)
- int ordering[TUP_LEN]; ///< Store ordering
- SearchMode mode; ///< Iteration mode
- int n_prefix; ///< Length of range prefix (RANGE, FILTER_RANGE)
- bool end; ///< True iff reached end
- bool skip_graphs; ///< True iff iteration should ignore graphs
+struct SordIterImpl {
+ const SordModel* sord; ///< Store this is an iterator for
+ GSequenceIter* cur; ///< Current DB cursor
+ SordQuad pat; ///< Iteration pattern (in ordering order)
+ int ordering[TUP_LEN]; ///< Store ordering
+ SearchMode mode; ///< Iteration mode
+ int n_prefix; ///< Length of range prefix (RANGE, FILTER_RANGE)
+ bool end; ///< True iff reached end
+ bool skip_graphs; ///< True iff iteration should ignore graphs
};
static unsigned
sord_literal_hash(const void* n)
{
- SordNode node = (SordNode)n;
+ SordNode* node = (SordNode*)n;
return g_str_hash(node->buf) + (node->lang ? g_str_hash(node->lang) : 0);
}
static gboolean
sord_literal_equal(const void* a, const void* b)
{
- SordNode a_node = (SordNode)a;
- SordNode b_node = (SordNode)b;
+ SordNode* a_node = (SordNode*)a;
+ SordNode* b_node = (SordNode*)b;
return (a_node == b_node)
|| (g_str_equal(sord_node_get_string(a_node),
sord_node_get_string(b_node))
@@ -157,10 +157,10 @@ sord_literal_equal(const void* a, const void* b)
&& (a_node->datatype == b_node->datatype));
}
-SordWorld
+SordWorld*
sord_world_new(void)
{
- SordWorld world = malloc(sizeof(struct _SordWorld));
+ SordWorld* world = malloc(sizeof(struct SordWorldImpl));
world->names = g_hash_table_new_full(g_str_hash, g_str_equal, 0, 0);
world->langs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, 0);
world->literals = g_hash_table_new_full(sord_literal_hash, sord_literal_equal, 0, 0);
@@ -169,7 +169,7 @@ sord_world_new(void)
}
void
-sord_world_free(SordWorld world)
+sord_world_free(SordWorld* world)
{
g_hash_table_unref(world->names);
g_hash_table_unref(world->langs);
@@ -178,7 +178,7 @@ sord_world_free(SordWorld world)
}
static inline int
-sord_node_compare(const SordNode a, const SordNode b)
+sord_node_compare(const SordNode* a, const SordNode* b)
{
if (a == b) {
return 0;
@@ -213,7 +213,7 @@ sord_node_compare(const SordNode a, const SordNode b)
}
bool
-sord_node_equals(const SordNode a, const SordNode b)
+sord_node_equals(const SordNode* a, const SordNode* b)
{
if (!a || !b) {
return (a == b);
@@ -231,7 +231,7 @@ sord_node_equals(const SordNode a, const SordNode b)
* result set.
*/
static inline int
-sord_id_compare(SordModel sord, const SordNode a, const SordNode b)
+sord_id_compare(SordModel* sord, const SordNode* a, const SordNode* b)
{
if (a == b || !a || !b) {
return (const char*)a - (const char*)b;
@@ -242,7 +242,7 @@ sord_id_compare(SordModel sord, const SordNode a, const SordNode b)
/** Return true iff IDs are equivalent, or one is a wildcard */
static inline bool
-sord_id_match(const SordNode a, const SordNode b)
+sord_id_match(const SordNode* a, const SordNode* b)
{
return !a || !b || (a == b);
}
@@ -269,9 +269,9 @@ sord_quad_match(const SordQuad x, const SordQuad y)
static int
sord_quad_compare(const void* x_ptr, const void* y_ptr, void* user_data)
{
- SordModel const sord = (SordModel)user_data;
- SordNode* const x = (SordNode*)x_ptr;
- SordNode* const y = (SordNode*)y_ptr;
+ SordModel* const sord = (SordModel*)user_data;
+ SordNode** const x = (SordNode**)x_ptr;
+ SordNode** const y = (SordNode**)y_ptr;
for (int i = 0; i < TUP_LEN; ++i) {
const int cmp = sord_id_compare(sord, x[i], y[i]);
@@ -283,21 +283,21 @@ sord_quad_compare(const void* x_ptr, const void* y_ptr, void* user_data)
}
static inline bool
-sord_iter_forward(SordIter iter)
+sord_iter_forward(SordIter* iter)
{
if (!iter->skip_graphs) {
iter->cur = g_sequence_iter_next(iter->cur);
return g_sequence_iter_is_end(iter->cur);
}
- const SordNode* key = (const SordNode*)g_sequence_get(iter->cur);
+ SordNode** key = (SordNode**)g_sequence_get(iter->cur);
const SordQuad initial = { key[0], key[1], key[2], key[3] };
while (true) {
iter->cur = g_sequence_iter_next(iter->cur);
if (g_sequence_iter_is_end(iter->cur))
return true;
- key = (const SordNode*)g_sequence_get(iter->cur);
+ key = (SordNode**)g_sequence_get(iter->cur);
for (int i = 0; i < 3; ++i)
if (key[i] != initial[i])
return false;
@@ -309,12 +309,12 @@ sord_iter_forward(SordIter iter)
* @return true iff iterator reached end of valid range.
*/
static inline bool
-sord_iter_seek_match(SordIter iter)
+sord_iter_seek_match(SordIter* iter)
{
for (iter->end = true;
!g_sequence_iter_is_end(iter->cur);
sord_iter_forward(iter)) {
- const SordNode* const key = (const SordNode*)g_sequence_get(iter->cur);
+ SordNode** const key = (SordNode**)g_sequence_get(iter->cur);
if (sord_quad_match_inline(key, iter->pat))
return (iter->end = false);
}
@@ -326,13 +326,13 @@ sord_iter_seek_match(SordIter iter)
* @return true iff iterator reached end of valid range.
*/
static inline bool
-sord_iter_seek_match_range(SordIter iter)
+sord_iter_seek_match_range(SordIter* iter)
{
if (iter->end)
return true;
do {
- const SordNode* key = (const SordNode*)g_sequence_get(iter->cur);
+ SordNode** key = (SordNode**)g_sequence_get(iter->cur);
if (sord_quad_match_inline(key, iter->pat))
return false; // Found match
@@ -348,13 +348,13 @@ sord_iter_seek_match_range(SordIter iter)
return (iter->end = true); // Reached end
}
-static SordIter
-sord_iter_new(SordModel sord, GSequenceIter* cur, const SordQuad pat,
+static SordIter*
+sord_iter_new(const SordModel* sord, GSequenceIter* cur, const SordQuad pat,
SordOrder order, SearchMode mode, int n_prefix)
{
const int* ordering = orderings[order];
- SordIter iter = malloc(sizeof(struct _SordIter));
+ SordIter* iter = malloc(sizeof(struct SordIterImpl));
iter->sord = sord;
iter->cur = cur;
iter->mode = mode;
@@ -371,7 +371,7 @@ sord_iter_new(SordModel sord, GSequenceIter* cur, const SordQuad pat,
case SINGLE:
case RANGE:
assert(
- sord_quad_match_inline((const SordNode*)g_sequence_get(iter->cur),
+ sord_quad_match_inline((SordNode**)g_sequence_get(iter->cur),
iter->pat));
break;
case FILTER_RANGE:
@@ -392,16 +392,16 @@ sord_iter_new(SordModel sord, GSequenceIter* cur, const SordQuad pat,
return iter;
}
-SordModel
-sord_iter_get_model(SordIter iter)
+const SordModel*
+sord_iter_get_model(SordIter* iter)
{
return iter->sord;
}
void
-sord_iter_get(SordIter iter, SordQuad id)
+sord_iter_get(const SordIter* iter, SordQuad id)
{
- const SordNode* key = (const SordNode*)g_sequence_get(iter->cur);
+ SordNode** key = (SordNode**)g_sequence_get(iter->cur);
id[iter->ordering[0]] = key[0];
id[iter->ordering[1]] = key[1];
id[iter->ordering[2]] = key[2];
@@ -409,12 +409,12 @@ sord_iter_get(SordIter iter, SordQuad id)
}
bool
-sord_iter_next(SordIter iter)
+sord_iter_next(SordIter* iter)
{
if (iter->end)
return true;
- const SordNode* key;
+ const SordNode** key;
iter->end = sord_iter_forward(iter);
if (!iter->end) {
switch (iter->mode) {
@@ -428,7 +428,7 @@ sord_iter_next(SordIter iter)
case RANGE:
SORD_ITER_LOG("%p range next\n", (void*)iter);
// At the end if the MSNs no longer match
- key = (const SordNode*)g_sequence_get(iter->cur);
+ key = (const SordNode**)g_sequence_get(iter->cur);
assert(key);
for (int i = 0; i < iter->n_prefix; ++i) {
if (!sord_id_match(key[i], iter->pat[i])) {
@@ -465,13 +465,13 @@ sord_iter_next(SordIter iter)
}
bool
-sord_iter_end(SordIter iter)
+sord_iter_end(const SordIter* iter)
{
return !iter || iter->end;
}
void
-sord_iter_free(SordIter iter)
+sord_iter_free(SordIter* iter)
{
SORD_ITER_LOG("%p Free\n", (void*)iter);
if (iter) {
@@ -484,7 +484,7 @@ sord_iter_free(SordIter iter)
* corresponding order with a G prepended (so G will be the MSN).
*/
static inline bool
-sord_has_index(SordModel sord, SordOrder* order, int* n_prefix, bool graph_search)
+sord_has_index(SordModel* sord, SordOrder* order, int* n_prefix, bool graph_search)
{
if (graph_search) {
*order += GSPO;
@@ -501,7 +501,7 @@ sord_has_index(SordModel sord, SordOrder* order, int* n_prefix, bool graph_searc
* (for @a mode == RANGE and @a mode == FILTER_RANGE)
*/
static inline SordOrder
-sord_best_index(SordModel sord, const SordQuad pat, SearchMode* mode, int* n_prefix)
+sord_best_index(SordModel* sord, const SordQuad pat, SearchMode* mode, int* n_prefix)
{
const bool graph_search = (pat[TUP_G] != 0);
@@ -559,10 +559,10 @@ sord_best_index(SordModel sord, const SordQuad pat, SearchMode* mode, int* n_pre
}
}
-SordModel
-sord_new(SordWorld world, unsigned indices, bool graphs)
+SordModel*
+sord_new(SordWorld* world, unsigned indices, bool graphs)
{
- SordModel sord = (SordModel)malloc(sizeof(struct _SordModel));
+ SordModel* sord = (SordModel*)malloc(sizeof(struct SordModelImpl));
sord->world = world;
sord->n_quads = 0;
@@ -588,7 +588,7 @@ sord_new(SordWorld world, unsigned indices, bool graphs)
}
static void
-sord_add_quad_ref(SordModel sord, const SordNode node)
+sord_add_quad_ref(SordModel* sord, SordNode* node)
{
if (node) {
assert(node->refs > 0);
@@ -597,24 +597,24 @@ sord_add_quad_ref(SordModel sord, const SordNode node)
}
static void
-sord_drop_quad_ref(SordModel sord, SordNode node)
+sord_drop_quad_ref(SordModel* sord, SordNode* node)
{
sord_node_free(sord_get_world(sord), node);
}
void
-sord_free(SordModel sord)
+sord_free(SordModel* sord)
{
if (!sord)
return;
// Free nodes
SordQuad tup;
- SordIter i = sord_begin(sord);
+ SordIter* i = sord_begin(sord);
for (; !sord_iter_end(i); sord_iter_next(i)) {
sord_iter_get(i, tup);
for (int i = 0; i < TUP_LEN; ++i) {
- sord_drop_quad_ref(sord, tup[i]);
+ sord_drop_quad_ref(sord, (SordNode*)tup[i]);
}
}
sord_iter_free(i);
@@ -626,26 +626,26 @@ sord_free(SordModel sord)
free(sord);
}
-SordWorld
-sord_get_world(SordModel sord)
+SordWorld*
+sord_get_world(SordModel* sord)
{
return sord->world;
}
int
-sord_num_quads(SordModel sord)
+sord_num_quads(const SordModel* sord)
{
return sord->n_quads;
}
int
-sord_num_nodes(SordWorld world)
+sord_num_nodes(const SordWorld* world)
{
return world->n_nodes;
}
-SordIter
-sord_begin(SordModel sord)
+SordIter*
+sord_begin(const SordModel* sord)
{
if (sord_num_quads(sord) == 0) {
return NULL;
@@ -656,21 +656,15 @@ sord_begin(SordModel sord)
}
}
-SordIter
-sord_graphs_begin(SordModel model)
-{
- return NULL;
-}
-
static inline GSequenceIter*
-index_search(SordModel sord, GSequence* db, const SordQuad search_key)
+index_search(SordModel* sord, GSequence* db, const SordQuad search_key)
{
return g_sequence_search(
db, (void*)search_key, sord_quad_compare, sord);
}
static inline GSequenceIter*
-index_lower_bound(SordModel sord, GSequence* db, const SordQuad search_key)
+index_lower_bound(SordModel* sord, GSequence* db, const SordQuad search_key)
{
GSequenceIter* i = g_sequence_search(
db, (void*)search_key, sord_quad_compare, sord);
@@ -714,8 +708,8 @@ index_lower_bound(SordModel sord, GSequence* db, const SordQuad search_key)
return i;
}
-SordIter
-sord_find(SordModel sord, const SordQuad pat)
+SordIter*
+sord_find(SordModel* sord, const SordQuad pat)
{
if (!pat[0] && !pat[1] && !pat[2] && !pat[3])
return sord_begin(sord);
@@ -732,10 +726,10 @@ sord_find(SordModel sord, const SordQuad pat)
// It's easiest to think about this algorithm in terms of (S P O) ordering,
// assuming (A B C) == (S P O). For other orderings this is not actually
// the case, but it works the same way.
- const SordNode a = pat[ordering[0]]; // Most Significant Node (MSN)
- const SordNode b = pat[ordering[1]]; // ...
- const SordNode c = pat[ordering[2]]; // ...
- const SordNode d = pat[ordering[3]]; // Least Significant Node (LSN)
+ SordNode* a = pat[ordering[0]]; // Most Significant Node (MSN)
+ SordNode* b = pat[ordering[1]]; // ...
+ SordNode* c = pat[ordering[2]]; // ...
+ SordNode* d = pat[ordering[3]]; // Least Significant Node (LSN)
if (a && b && c && d)
mode = SINGLE; // No duplicate quads (Sord is a set)
@@ -747,7 +741,7 @@ sord_find(SordModel sord, const SordQuad pat)
SORD_FIND_LOG("No match found\n");
return NULL;
}
- const SordNode* const key = (const SordNode*)g_sequence_get(cur);
+ SordNode** const key = (SordNode**)g_sequence_get(cur);
if (!key || ( (mode == RANGE || mode == SINGLE)
&& !sord_quad_match_inline(search_key, key) )) {
SORD_FIND_LOG("No match found\n");
@@ -757,16 +751,16 @@ sord_find(SordModel sord, const SordQuad pat)
return sord_iter_new(sord, cur, pat, index_order, mode, prefix_len);
}
-static SordNode
-sord_lookup_name(SordWorld world, const uint8_t* str, size_t str_len)
+static SordNode*
+sord_lookup_name(SordWorld* world, const uint8_t* str, size_t str_len)
{
return g_hash_table_lookup(world->names, str);
}
-static SordNode
+static SordNode*
sord_new_node(SordNodeType type, const uint8_t* data, size_t n_bytes)
{
- SordNode node = malloc(sizeof(struct _SordNode));
+ SordNode* node = malloc(sizeof(struct SordNodeImpl));
node->type = type;
node->n_bytes = n_bytes;
node->refs = 1;
@@ -777,7 +771,7 @@ sord_new_node(SordNodeType type, const uint8_t* data, size_t n_bytes)
}
const char*
-sord_intern_lang(SordWorld world, const char* lang)
+sord_intern_lang(SordWorld* world, const char* lang)
{
if (lang) {
char* ilang = g_hash_table_lookup(world->langs, lang);
@@ -791,24 +785,24 @@ sord_intern_lang(SordWorld world, const char* lang)
return lang;
}
-static SordNode
-sord_new_literal_node(SordWorld world, SordNode datatype,
+static SordNode*
+sord_new_literal_node(SordWorld* world, SordNode* datatype,
const uint8_t* str, int str_len,
const char* lang, uint8_t lang_len)
{
- SordNode node = sord_new_node(SORD_LITERAL, str, str_len + 1);
+ SordNode* node = sord_new_node(SORD_LITERAL, str, str_len + 1);
node->datatype = sord_node_copy(datatype);
node->lang = sord_intern_lang(world, lang);
return node;
}
-static SordNode
-sord_lookup_literal(SordWorld world, SordNode type,
+static SordNode*
+sord_lookup_literal(SordWorld* world, SordNode* type,
const uint8_t* str, int str_len,
const char* lang, uint8_t lang_len)
{
// Make search key (FIXME: ick)
- struct _SordNode key;
+ struct SordNodeImpl key;
key.type = SORD_LITERAL;
key.n_bytes = str_len;
key.refs = 1;
@@ -816,7 +810,7 @@ sord_lookup_literal(SordWorld world, SordNode type,
key.lang = sord_intern_lang(world, lang);
key.buf = (uint8_t*)str;
- SordNode id = g_hash_table_lookup(world->literals, &key);
+ SordNode* id = g_hash_table_lookup(world->literals, &key);
if (id) {
return id;
} else {
@@ -825,46 +819,46 @@ sord_lookup_literal(SordWorld world, SordNode type,
}
SordNodeType
-sord_node_get_type(SordNode ref)
+sord_node_get_type(const SordNode* ref)
{
return ref->type;
}
const uint8_t*
-sord_node_get_string(SordNode ref)
+sord_node_get_string(const SordNode* ref)
{
return (const uint8_t*)ref->buf;
}
const uint8_t*
-sord_node_get_string_counted(SordNode ref, size_t* n_bytes)
+sord_node_get_string_counted(const SordNode* ref, size_t* n_bytes)
{
*n_bytes = ref->n_bytes;
return ref->buf;
}
const char*
-sord_node_get_language(SordNode ref)
+sord_node_get_language(const SordNode* ref)
{
return ref->lang;
}
-SordNode
-sord_node_get_datatype(SordNode ref)
+SordNode*
+sord_node_get_datatype(const SordNode* ref)
{
return ref->datatype;
}
static void
-sord_add_node(SordWorld world, SordNode node)
+sord_add_node(SordWorld* world, SordNode* node)
{
++world->n_nodes;
}
-SordNode
-sord_new_uri_counted(SordWorld world, const uint8_t* str, size_t str_len)
+SordNode*
+sord_new_uri_counted(SordWorld* world, const uint8_t* str, size_t str_len)
{
- SordNode node = sord_lookup_name(world, str, str_len);
+ SordNode* node = sord_lookup_name(world, str, str_len);
if (node) {
++node->refs;
return node;
@@ -877,16 +871,16 @@ sord_new_uri_counted(SordWorld world, const uint8_t* str, size_t str_len)
return node;
}
-SordNode
-sord_new_uri(SordWorld world, const uint8_t* str)
+SordNode*
+sord_new_uri(SordWorld* world, const uint8_t* str)
{
return sord_new_uri_counted(world, str, strlen((const char*)str));
}
-SordNode
-sord_new_blank_counted(SordWorld world, const uint8_t* str, size_t str_len)
+SordNode*
+sord_new_blank_counted(SordWorld* world, const uint8_t* str, size_t str_len)
{
- SordNode node = sord_lookup_name(world, str, str_len);
+ SordNode* node = sord_lookup_name(world, str, str_len);
if (node) {
++node->refs;
return node;
@@ -898,41 +892,41 @@ sord_new_blank_counted(SordWorld world, const uint8_t* str, size_t str_len)
return node;
}
-SordNode
-sord_new_blank(SordWorld world, const uint8_t* str)
+SordNode*
+sord_new_blank(SordWorld* world, const uint8_t* str)
{
return sord_new_blank_counted(world, str, strlen((const char*)str));
}
-SordNode
-sord_new_literal_counted(SordWorld world, SordNode type,
+SordNode*
+sord_new_literal_counted(SordWorld* world, SordNode* datatype,
const uint8_t* str, size_t str_len,
const char* lang, uint8_t lang_len)
{
- SordNode node = sord_lookup_literal(world, type, str, str_len, lang, lang_len);
+ SordNode* node = sord_lookup_literal(world, datatype, str, str_len, lang, lang_len);
if (node) {
++node->refs;
return node;
}
- node = sord_new_literal_node(world, type, str, str_len, lang, lang_len);
+ node = sord_new_literal_node(world, datatype, str, str_len, lang, lang_len);
g_hash_table_insert(world->literals, node, node); // FIXME: correct?
sord_add_node(world, node);
assert(node->refs == 1);
return node;
}
-SordNode
-sord_new_literal(SordWorld world, SordNode type,
+SordNode*
+sord_new_literal(SordWorld* world, SordNode* datatype,
const uint8_t* str, const char* lang)
{
- return sord_new_literal_counted(world, type,
+ return sord_new_literal_counted(world, datatype,
str, strlen((const char*)str),
lang, lang ? strlen(lang) : 0);
}
void
-sord_node_free(SordWorld world, SordNode node)
+sord_node_free(SordWorld* world, SordNode* node)
{
if (!node) {
return;
@@ -957,8 +951,8 @@ sord_node_free(SordWorld world, SordNode node)
}
}
-SordNode
-sord_node_copy(SordNode node)
+SordNode*
+sord_node_copy(SordNode* node)
{
if (node) {
++node->refs;
@@ -967,7 +961,7 @@ sord_node_copy(SordNode node)
}
static inline bool
-sord_add_to_index(SordModel sord, const SordQuad tup, SordOrder order)
+sord_add_to_index(SordModel* sord, const SordQuad tup, SordOrder order)
{
assert(sord->indices[order]);
const int* const ordering = orderings[order];
@@ -982,14 +976,14 @@ sord_add_to_index(SordModel sord, const SordQuad tup, SordOrder order)
// FIXME: would be nice to share quads and just use a different comparator
// for each index (save significant space overhead per quad)
- SordNode* key_copy = malloc(sizeof(SordQuad));
+ SordNode** key_copy = malloc(sizeof(SordQuad));
memcpy(key_copy, key, sizeof(SordQuad));
g_sequence_insert_before(cur, key_copy);
return true;
}
bool
-sord_add(SordModel sord, const SordQuad tup)
+sord_add(SordModel* sord, const SordQuad tup)
{
SORD_WRITE_LOG("Add " TUP_FMT "\n", TUP_FMT_ARGS(tup));
if (!tup[0] || !tup[1] || !tup[2]) {
@@ -998,7 +992,8 @@ sord_add(SordModel sord, const SordQuad tup)
}
// FIXME: Remove double search
- SordIter existing = sord_find(sord, tup);
+ SordQuad pat = { tup[0], tup[1], tup[2], tup[3] };
+ SordIter* existing = sord_find(sord, pat);
if (existing) {
sord_iter_free(existing);
return false;
@@ -1022,7 +1017,7 @@ sord_add(SordModel sord, const SordQuad tup)
}
void
-sord_remove(SordModel sord, const SordQuad tup)
+sord_remove(SordModel* sord, const SordQuad tup)
{
SORD_WRITE_LOG("Remove " TUP_FMT "\n", TUP_FMT_ARGS(tup));
diff --git a/src/sord_internal.h b/src/sord_internal.h
index 8f6f9e8..567b56c 100644
--- a/src/sord_internal.h
+++ b/src/sord_internal.h
@@ -25,16 +25,16 @@
typedef intptr_t SordCount; ///< Count of nodes or triples
/** Node */
-struct _SordNode {
+struct SordNodeImpl {
uint8_t* buf; ///< Value (string)
const char* lang; ///< Literal language (interned string)
- SordNode datatype; ///< Literal data type (ID of a URI node, or 0)
+ SordNode* datatype; ///< Literal data type (ID of a URI node, or 0)
size_t n_bytes; ///< Length of data in bytes (including terminator)
SordCount refs; ///< Reference count (i.e. number of containing quads)
SordNodeType type; ///< SordNodeType
};
const char*
-sord_intern_lang(SordWorld world, const char* lang);
+sord_intern_lang(SordWorld* world, const char* lang);
#endif /* SORD_SORD_INTERNAL_H_ */
diff --git a/src/sord_test.c b/src/sord_test.c
index e89d939..ef8f85c 100644
--- a/src/sord_test.c
+++ b/src/sord_test.c
@@ -28,8 +28,8 @@ typedef struct { SordQuad query; int expected_num_results; } QueryTest;
#define USTR(s) ((const uint8_t*)(s))
-static SordNode
-uri(SordWorld world, int num)
+static SordNode*
+uri(SordWorld* world, int num)
{
if (num == 0)
return 0;
@@ -49,7 +49,7 @@ test_fail()
}
int
-generate(SordWorld world, SordModel sord, size_t n_quads, size_t n_objects_per)
+generate(SordWorld* world, SordModel* sord, size_t n_quads, size_t n_objects_per)
{
fprintf(stderr, "Generating %zu (S P *) quads with %zu objects each\n",
n_quads, n_objects_per);
@@ -57,7 +57,7 @@ generate(SordWorld world, SordModel sord, size_t n_quads, size_t n_objects_per)
for (size_t i = 0; i < n_quads; ++i) {
int num = (i * n_objects_per) + 1;
- SordNode ids[2 + n_objects_per];
+ SordNode* ids[2 + n_objects_per];
for (size_t j = 0; j < 2 + n_objects_per; ++j) {
ids[j] = uri(world, num++);
}
@@ -129,13 +129,13 @@ generate(SordWorld world, SordModel sord, size_t n_quads, size_t n_objects_per)
((t)[2] ? sord_node_get_string((t)[2]) : USTR("*"))
int
-test_read(SordWorld world, SordModel sord, const size_t n_quads, const int n_objects_per)
+test_read(SordWorld* world, SordModel* sord, const size_t n_quads, const int n_objects_per)
{
int ret = EXIT_SUCCESS;
SordQuad id;
- SordIter iter = sord_begin(sord);
+ SordIter* iter = sord_begin(sord);
if (sord_iter_get_model(iter) != sord) {
fprintf(stderr, "Fail: Iterator has incorrect sord pointer\n");
return test_fail();
@@ -221,7 +221,7 @@ test_read(SordWorld world, SordModel sord, const size_t n_quads, const int n_obj
// Test nested queries
fprintf(stderr, "Nested Queries... ");
pat[0] = pat[1] = pat[2] = 0;
- SordNode last_subject = 0;
+ SordNode* last_subject = 0;
iter = sord_find(sord, pat);
for (; !sord_iter_end(iter); sord_iter_next(iter)) {
sord_iter_get(iter, id);
@@ -229,7 +229,7 @@ test_read(SordWorld world, SordModel sord, const size_t n_quads, const int n_obj
continue;
SordQuad subpat = { id[0], 0, 0 };
- SordIter subiter = sord_find(sord, subpat);
+ SordIter* subiter = sord_find(sord, subpat);
int num_sub_results = 0;
for (; !sord_iter_end(subiter); sord_iter_next(subiter)) {
SordQuad subid;
@@ -264,10 +264,10 @@ main(int argc, char** argv)
sord_free(NULL); // Shouldn't crash
- SordWorld world = sord_world_new();
+ SordWorld* world = sord_world_new();
// Create with minimal indexing
- SordModel sord = sord_new(world, SORD_SPO, false);
+ SordModel* sord = sord_new(world, SORD_SPO, false);
generate(world, sord, n_quads, n_objects_per);
if (test_read(world, sord, n_quads, n_objects_per)) {
@@ -277,13 +277,13 @@ main(int argc, char** argv)
}
// Check interning merges equivalent values
- SordNode uri_id = sord_new_uri(world, USTR("http://example.org"));
- SordNode blank_id = sord_new_uri(world, USTR("testblank"));
- SordNode lit_id = sord_new_literal(world, uri_id, USTR("hello"), NULL);
+ SordNode* uri_id = sord_new_uri(world, USTR("http://example.org"));
+ SordNode* blank_id = sord_new_uri(world, USTR("testblank"));
+ SordNode* lit_id = sord_new_literal(world, uri_id, USTR("hello"), NULL);
//sord_clear_cache(write);
- SordNode uri_id2 = sord_new_uri(world, USTR("http://example.org"));
- SordNode blank_id2 = sord_new_uri(world, USTR("testblank"));
- SordNode lit_id2 = sord_new_literal(world, uri_id, USTR("hello"), NULL);
+ SordNode* uri_id2 = sord_new_uri(world, USTR("http://example.org"));
+ SordNode* blank_id2 = sord_new_uri(world, USTR("testblank"));
+ SordNode* lit_id2 = sord_new_literal(world, uri_id, USTR("hello"), NULL);
if (uri_id2 != uri_id) {
fprintf(stderr, "Fail: URI interning failed (duplicates)\n");
goto fail;
@@ -296,9 +296,9 @@ main(int argc, char** argv)
}
// Check interning doesn't clash non-equivalent values
- SordNode uri_id3 = sord_new_uri(world, USTR("http://example.orgX"));
- SordNode blank_id3 = sord_new_uri(world, USTR("testblankX"));
- SordNode lit_id3 = sord_new_literal(world, uri_id, USTR("helloX"), NULL);
+ SordNode* uri_id3 = sord_new_uri(world, USTR("http://example.orgX"));
+ SordNode* blank_id3 = sord_new_uri(world, USTR("testblankX"));
+ SordNode* lit_id3 = sord_new_literal(world, uri_id, USTR("helloX"), NULL);
if (uri_id3 == uri_id) {
fprintf(stderr, "Fail: URI interning failed (clash)\n");
goto fail;
diff --git a/src/sordi.c b/src/sordi.c
index 48f3065..123752a 100644
--- a/src/sordi.c
+++ b/src/sordi.c
@@ -27,7 +27,7 @@ typedef struct {
SerdEnv* env;
SerdNode base_uri_node;
SerdURI base_uri;
- SordModel sord;
+ SordModel* sord;
} State;
int
@@ -61,7 +61,7 @@ file_sink(const void* buf, size_t len, void* stream)
}
static inline SerdNode
-serd_node_from_sord_node(const SordNode n)
+serd_node_from_sord_node(const SordNode* n)
{
size_t n_bytes = 0;
const uint8_t* buf = sord_node_get_string_counted(n, &n_bytes);
@@ -116,8 +116,8 @@ main(int argc, char** argv)
const uint8_t* input = (const uint8_t*)argv[a++];
- SordWorld world = sord_world_new();
- SordModel sord = sord_new(world, SORD_SPO|SORD_OPS, false);
+ SordWorld* world = sord_world_new();
+ SordModel* sord = sord_new(world, SORD_SPO|SORD_OPS, false);
bool success = sord_read_file(sord, input, NULL, NULL);
@@ -135,16 +135,16 @@ main(int argc, char** argv)
// Query
SordQuad pat = { 0, 0, 0, 0 };
- SordIter iter = sord_find(sord, pat);
+ SordIter* iter = sord_find(sord, pat);
for (; !sord_iter_end(iter); sord_iter_next(iter)) {
- SordQuad tup;
+ SordQuadConst tup;
sord_iter_get(iter, tup);
- SordNode s = tup[SORD_SUBJECT];
- SordNode p = tup[SORD_PREDICATE];
- SordNode o = tup[SORD_OBJECT];
- SerdNode ss = serd_node_from_sord_node(s);
- SerdNode sp = serd_node_from_sord_node(p);
- SerdNode so = serd_node_from_sord_node(o);
+ const SordNode* s = tup[SORD_SUBJECT];
+ const SordNode* p = tup[SORD_PREDICATE];
+ const SordNode* o = tup[SORD_OBJECT];
+ SerdNode ss = serd_node_from_sord_node(s);
+ SerdNode sp = serd_node_from_sord_node(p);
+ SerdNode so = serd_node_from_sord_node(o);
serd_writer_write_statement(
writer, NULL, &ss, &sp, &so, NULL, NULL);
}
diff --git a/src/syntax.c b/src/syntax.c
index 8a31a28..23c537b 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -29,9 +29,9 @@ typedef struct {
SerdReader* reader;
SerdEnv* env;
SerdReadState* read_state;
- SordNode graph_uri_node;
- SordWorld world;
- SordModel sord;
+ SordNode* graph_uri_node;
+ SordWorld* world;
+ SordModel* sord;
} ReadState;
static uint8_t*
@@ -63,12 +63,12 @@ event_prefix(void* handle,
return serd_read_state_set_prefix(state->read_state, name, uri_node);
}
-static inline SordNode
+static inline SordNode*
sord_node_from_serd_node(ReadState* state, const SerdNode* sn,
const SerdNode* datatype, const SerdNode* lang)
{
- SordNode datatype_node = NULL;
- SordNode ret = NULL;
+ SordNode* datatype_node = NULL;
+ SordNode* ret = NULL;
switch (sn->type) {
case SERD_NOTHING:
return NULL;
@@ -87,7 +87,7 @@ sord_node_from_serd_node(ReadState* state, const SerdNode* sn,
SerdURI abs_uri;
SerdNode abs_uri_node = serd_node_new_uri_from_node(
sn, &base_uri, &abs_uri);
- SordNode ret = sord_new_uri(state->world, abs_uri_node.buf);
+ SordNode* ret = sord_new_uri(state->world, abs_uri_node.buf);
serd_node_free(&abs_uri_node);
return ret;
}
@@ -103,8 +103,8 @@ sord_node_from_serd_node(ReadState* state, const SerdNode* sn,
memcpy(buf, uri_prefix.buf, uri_prefix.len);
memcpy(buf + uri_prefix.len, uri_suffix.buf, uri_suffix.len);
buf[uri_len] = '\0';
- SordNode ret = sord_new_uri_counted(state->world,
- buf, uri_prefix.len + uri_suffix.len);
+ SordNode* ret = sord_new_uri_counted(state->world,
+ buf, uri_prefix.len + uri_suffix.len);
free(buf);
return ret;
}
@@ -117,7 +117,7 @@ sord_node_from_serd_node(ReadState* state, const SerdNode* sn,
}
static inline void
-sord_node_to_serd_node(const SordNode node, SerdNode* out)
+sord_node_to_serd_node(const SordNode* node, SerdNode* out)
{
if (!node) {
*out = SERD_NODE_NULL;
@@ -160,7 +160,7 @@ event_statement(void* handle,
if (state->graph_uri_node) {
assert(graph->type == SERD_NOTHING);
tup[3] = sord_node_copy(state->graph_uri_node);
- } else {
+ } else if (graph && graph->buf) {
tup[3] = (graph && graph->buf)
? sord_node_from_serd_node(state, graph, NULL, NULL)
: NULL;
@@ -202,9 +202,9 @@ sord_file_uri_to_path(const uint8_t* uri)
SORD_API
bool
-sord_read_file(SordModel model,
+sord_read_file(SordModel* model,
const uint8_t* uri,
- const SordNode graph,
+ SordNode* graph,
const uint8_t* blank_prefix)
{
const uint8_t* const path = sord_file_uri_to_path(uri);
@@ -226,10 +226,10 @@ sord_read_file(SordModel model,
SORD_API
bool
-sord_read_file_handle(SordModel model,
+sord_read_file_handle(SordModel* model,
FILE* fd,
const uint8_t* base_uri_str_in,
- const SordNode graph,
+ SordNode* graph,
const uint8_t* blank_prefix)
{
size_t base_uri_n_bytes = 0;
@@ -267,7 +267,7 @@ sord_read_file_handle(SordModel model,
SORD_API
bool
-sord_read_string(SordModel model,
+sord_read_string(SordModel* model,
const uint8_t* str,
const uint8_t* base_uri_str_in)
{
@@ -302,10 +302,10 @@ sord_read_string(SordModel model,
SORD_API
bool
-sord_write_file(SordModel model,
+sord_write_file(SordModel* model,
SerdEnv* env,
const uint8_t* uri,
- const SordNode graph,
+ SordNode* graph,
const uint8_t* blank_prefix)
{
const uint8_t* const path = sord_file_uri_to_path(uri);
@@ -332,13 +332,13 @@ file_sink(const void* buf, size_t len, void* stream)
}
static void
-sord_write(const SordModel model,
- const SordNode graph,
- SerdWriter* writer)
+sord_write(const SordModel* model,
+ const SordNode* graph,
+ SerdWriter* writer)
{
SerdNode s_graph;
sord_node_to_serd_node(graph, &s_graph);
- for (SordIter i = sord_begin(model); !sord_iter_end(i); sord_iter_next(i)) {
+ for (SordIter* i = sord_begin(model); !sord_iter_end(i); sord_iter_next(i)) {
SordQuad quad;
sord_iter_get(i, quad);
@@ -397,11 +397,11 @@ make_writer(SerdEnv* env,
SORD_API
bool
-sord_write_file_handle(SordModel model,
+sord_write_file_handle(SordModel* model,
SerdEnv* env,
FILE* fd,
const uint8_t* base_uri_str_in,
- const SordNode graph,
+ SordNode* graph,
const uint8_t* blank_prefix)
{
SerdWriter* writer = make_writer(env, base_uri_str_in, file_sink, fd);
@@ -427,7 +427,7 @@ string_sink(const void* buf, size_t len, void* stream)
SORD_API
uint8_t*
-sord_write_string(SordModel model,
+sord_write_string(SordModel* model,
SerdEnv* env,
const uint8_t* base_uri)
{