diff options
author | David Robillard <d@drobilla.net> | 2011-04-28 04:45:59 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-04-28 04:45:59 +0000 |
commit | 86e095df809f8d15b54ee62801f3deb829adfae9 (patch) | |
tree | a514dd90d72621c315d78ecda973ee7500989d85 /src | |
parent | 688537cf5ccb709c23359eb855946bedd5b65fcf (diff) | |
download | sord-86e095df809f8d15b54ee62801f3deb829adfae9.tar.gz sord-86e095df809f8d15b54ee62801f3deb829adfae9.tar.bz2 sord-86e095df809f8d15b54ee62801f3deb829adfae9.zip |
Const-correct node API.
git-svn-id: http://svn.drobilla.net/sord/trunk@98 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'src')
-rw-r--r-- | src/sord.c | 33 | ||||
-rw-r--r-- | src/syntax.c | 24 |
2 files changed, 30 insertions, 27 deletions
@@ -314,7 +314,7 @@ sord_iter_seek_match(SordIter* iter) for (iter->end = true; !g_sequence_iter_is_end(iter->cur); sord_iter_forward(iter)) { - SordNode** const key = (SordNode**)g_sequence_get(iter->cur); + const SordNode** const key = (const SordNode**)g_sequence_get(iter->cur); if (sord_quad_match_inline(key, iter->pat)) return (iter->end = false); } @@ -332,7 +332,7 @@ sord_iter_seek_match_range(SordIter* iter) return true; do { - SordNode** key = (SordNode**)g_sequence_get(iter->cur); + const SordNode** key = (const SordNode**)g_sequence_get(iter->cur); if (sord_quad_match_inline(key, iter->pat)) return false; // Found match @@ -371,7 +371,7 @@ sord_iter_new(const SordModel* sord, GSequenceIter* cur, const SordQuad pat, case SINGLE: case RANGE: assert( - sord_quad_match_inline((SordNode**)g_sequence_get(iter->cur), + sord_quad_match_inline((const SordNode**)g_sequence_get(iter->cur), iter->pat)); break; case FILTER_RANGE: @@ -588,18 +588,18 @@ sord_new(SordWorld* world, unsigned indices, bool graphs) } static void -sord_add_quad_ref(SordModel* sord, SordNode* node) +sord_add_quad_ref(SordModel* sord, const SordNode* node) { if (node) { assert(node->refs > 0); - ++node->refs; + ++((SordNode*)node)->refs; } } static void -sord_drop_quad_ref(SordModel* sord, SordNode* node) +sord_drop_quad_ref(SordModel* sord, const SordNode* node) { - sord_node_free(sord_get_world(sord), node); + sord_node_free(sord_get_world(sord), (SordNode*)node); } void @@ -731,10 +731,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. - 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) + 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) if (a && b && c && d) mode = SINGLE; // No duplicate quads (Sord is a set) @@ -746,7 +746,7 @@ sord_find(SordModel* sord, const SordQuad pat) SORD_FIND_LOG("No match found\n"); return NULL; } - SordNode** const key = (SordNode**)g_sequence_get(cur); + const SordNode** const key = (const 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"); @@ -957,12 +957,13 @@ sord_node_free(SordWorld* world, SordNode* node) } SordNode* -sord_node_copy(SordNode* node) +sord_node_copy(const SordNode* node) { - if (node) { - ++node->refs; + SordNode* copy = (SordNode*)node; + if (copy) { + ++copy->refs; } - return node; + return copy; } static inline bool diff --git a/src/syntax.c b/src/syntax.c index daeec69..a0198c3 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -151,26 +151,28 @@ event_statement(void* handle, { ReadState* const state = (ReadState*)handle; - SordQuad tup; - tup[0] = sord_node_from_serd_node(state, subject, NULL, NULL); - tup[1] = sord_node_from_serd_node(state, predicate, NULL, NULL); - tup[2] = sord_node_from_serd_node(state, object, - object_datatype, object_lang); + SordNode* s = sord_node_from_serd_node(state, subject, NULL, NULL); + SordNode* p = sord_node_from_serd_node(state, predicate, NULL, NULL); + SordNode* o = sord_node_from_serd_node(state, object, + object_datatype, object_lang); + SordNode* g = NULL; if (state->graph_uri_node) { assert(graph->type == SERD_NOTHING); - tup[3] = sord_node_copy(state->graph_uri_node); + g = sord_node_copy(state->graph_uri_node); } else { - tup[3] = (graph && graph->buf) + g = (graph && graph->buf) ? sord_node_from_serd_node(state, graph, NULL, NULL) : NULL; } + const SordQuad tup = { s, p, o, g }; sord_add(state->sord, tup); - sord_node_free(state->world, tup[0]); - sord_node_free(state->world, tup[1]); - sord_node_free(state->world, tup[2]); - sord_node_free(state->world, tup[3]); + + sord_node_free(state->world, s); + sord_node_free(state->world, p); + sord_node_free(state->world, o); + sord_node_free(state->world, g); return true; } |