summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-02-18 17:50:26 +0000
committerDavid Robillard <d@drobilla.net>2013-02-18 17:50:26 +0000
commitc97e250cd031b90befeb9ae7e1b68dfca768d1f3 (patch)
tree44e368349bbd71881202cb43cd48bc56f3b103be
parentd58aef47fd713d2f7d148c4200fb015401d47c9f (diff)
downloadsratom-c97e250cd031b90befeb9ae7e1b68dfca768d1f3.tar.gz
sratom-c97e250cd031b90befeb9ae7e1b68dfca768d1f3.tar.bz2
sratom-c97e250cd031b90befeb9ae7e1b68dfca768d1f3.zip
Make use of sord_get().
git-svn-id: http://svn.drobilla.net/lad/trunk/sratom@5055 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r--src/sratom.c58
1 files changed, 23 insertions, 35 deletions
diff --git a/src/sratom.c b/src/sratom.c
index bd778d8..78600a3 100644
--- a/src/sratom.c
+++ b/src/sratom.c
@@ -486,23 +486,6 @@ sratom_to_turtle(Sratom* sratom,
return (char*)serd_chunk_sink_finish(&str);
}
-static const SordNode*
-get_object(SordModel* model,
- const SordNode* subject,
- const SordNode* predicate)
-{
- const SordNode* object = NULL;
- SordQuad q = { subject, predicate, 0, 0 };
- SordIter* i = sord_find(model, q);
- if (!sord_iter_end(i)) {
- SordQuad quad;
- sord_iter_get(i, quad);
- object = quad[SORD_OBJECT];
- }
- sord_iter_free(i);
- return object;
-}
-
static void
read_list_value(Sratom* sratom,
LV2_Atom_Forge* forge,
@@ -511,12 +494,14 @@ read_list_value(Sratom* sratom,
const SordNode* node,
ReadMode mode)
{
- const SordNode* first = get_object(model, node, sratom->nodes.rdf_first);
- const SordNode* rest = get_object(model, node, sratom->nodes.rdf_rest);
- if (first && rest) {
- read_node(sratom, forge, world, model, first, mode);
- read_list_value(sratom, forge, world, model, rest, mode);
+ SordNode* fst = sord_get(model, node, sratom->nodes.rdf_first, NULL, NULL);
+ SordNode* rst = sord_get(model, node, sratom->nodes.rdf_rest, NULL, NULL);
+ if (fst && rst) {
+ read_node(sratom, forge, world, model, fst, mode);
+ read_list_value(sratom, forge, world, model, rst, mode);
}
+ sord_node_free(world, rst);
+ sord_node_free(world, fst);
}
static void
@@ -645,8 +630,10 @@ read_node(Sratom* sratom,
lv2_atom_forge_urid(forge, map->map(map->handle, str));
}
} else {
- const SordNode* type = get_object(model, node, sratom->nodes.rdf_type);
- const SordNode* value = get_object(model, node, sratom->nodes.rdf_value);
+ SordNode* type = sord_get(
+ model, node, sratom->nodes.rdf_type, NULL, NULL);
+ SordNode* value = sord_get(
+ model, node, sratom->nodes.rdf_value, NULL, NULL);
const uint8_t* type_uri = NULL;
uint32_t type_urid = 0;
@@ -657,13 +644,14 @@ read_node(Sratom* sratom,
LV2_Atom_Forge_Frame frame = { 0, 0 };
if (mode == MODE_SEQUENCE) {
- const SordNode* frame_time = get_object(
- model, node, sratom->nodes.atom_frameTime);
+ SordNode* frame_time = sord_get(
+ model, node, sratom->nodes.atom_frameTime, NULL, NULL);
const char* frame_time_str = frame_time
? (const char*)sord_node_get_string(frame_time)
: "";
lv2_atom_forge_frame_time(forge, serd_strtod(frame_time_str, NULL));
read_node(sratom, forge, world, model, value, MODE_BODY);
+ sord_node_free(world, frame_time);
} else if (type_urid == sratom->forge.Tuple) {
lv2_atom_forge_tuple(forge, &frame);
read_list_value(sratom, forge, world, model, value, MODE_BODY);
@@ -671,8 +659,8 @@ read_node(Sratom* sratom,
lv2_atom_forge_sequence_head(forge, &frame, 0);
read_list_value(sratom, forge, world, model, value, MODE_SEQUENCE);
} else if (type_urid == sratom->forge.Vector) {
- const SordNode* child_type_node = get_object(
- model, node, sratom->nodes.atom_childType);
+ SordNode* child_type_node = sord_get(
+ model, node, sratom->nodes.atom_childType, NULL, NULL);
uint32_t child_type = map->map(
map->handle, (const char*)sord_node_get_string(child_type_node));
uint32_t child_size = atom_size(sratom, child_type);
@@ -680,6 +668,7 @@ read_node(Sratom* sratom,
lv2_atom_forge_vector_head(forge, &frame, child_size, child_type);
read_list_value(sratom, forge, world, model, value, MODE_BODY);
}
+ sord_node_free(world, child_type_node);
} else if (value && sord_node_equals(sord_node_get_datatype(value),
sratom->nodes.xsd_base64Binary)) {
size_t vlen = 0;
@@ -700,6 +689,8 @@ read_node(Sratom* sratom,
if (frame.ref) {
lv2_atom_forge_pop(forge, &frame);
}
+ sord_node_free(world, value);
+ sord_node_free(world, type);
}
}
@@ -773,16 +764,13 @@ sratom_from_turtle(Sratom* sratom,
&sratom->forge, sratom_forge_sink, sratom_forge_deref, &out);
if (subject && predicate) {
SordNode* p = sord_node_from_serd_node(world, env, predicate, 0, 0);
- SordQuad q = { s, p, 0, 0 };
- SordIter* i = sord_find(model, q);
- if (!sord_iter_end(i)) {
- SordQuad result;
- sord_iter_get(i, result);
- sratom_read(sratom, &sratom->forge, world, model, result[SORD_OBJECT]);
+ SordNode* o = sord_get(model, s, p, NULL, NULL);
+ if (o) {
+ sratom_read(sratom, &sratom->forge, world, model, o);
+ sord_node_free(world, o);
} else {
fprintf(stderr, "Failed to find node\n");
}
- sord_iter_free(i);
} else {
sratom_read(sratom, &sratom->forge, world, model, s);
}