summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-08-13 12:46:31 -0400
committerDavid Robillard <d@drobilla.net>2021-08-13 12:46:31 -0400
commit6a2962128761c4579877b86f6aeb2adc30f8e9ce (patch)
tree0b0101a905fe31f18f160913e6c0fae7e2774565
parentc37e9cccb6a8dfee42bb50ec2646ecc41f353ae2 (diff)
downloadsratom-6a2962128761c4579877b86f6aeb2adc30f8e9ce.tar.gz
sratom-6a2962128761c4579877b86f6aeb2adc30f8e9ce.tar.bz2
sratom-6a2962128761c4579877b86f6aeb2adc30f8e9ce.zip
WIP
-rw-r--r--bindings/cpp/include/sratom/sratom.hpp10
-rw-r--r--bindings/cpp/meson.build4
-rw-r--r--doc/c/overview.rst6
-rw-r--r--src/dumper.c70
-rw-r--r--src/loader.c53
-rw-r--r--test/test_sratom.c15
6 files changed, 80 insertions, 78 deletions
diff --git a/bindings/cpp/include/sratom/sratom.hpp b/bindings/cpp/include/sratom/sratom.hpp
index 8be6644..9bb9c1f 100644
--- a/bindings/cpp/include/sratom/sratom.hpp
+++ b/bindings/cpp/include/sratom/sratom.hpp
@@ -69,14 +69,14 @@ enum class Flag {
terse = SRATOM_TERSE,
};
-using Flags = serd::detail::Flags<Flag>;
+using Flags = serd::Flags<Flag>;
class Dumper
- : public serd::detail::BasicWrapper<SratomDumper, sratom_dumper_free>
+ : public serd::detail::StaticWrapper<SratomDumper, sratom_dumper_free>
{
public:
Dumper(serd::World& world, LV2_URID_Map& map, LV2_URID_Unmap& unmap)
- : BasicWrapper(sratom_dumper_new(world.cobj(), &map, &unmap))
+ : StaticWrapper(sratom_dumper_new(world.cobj(), &map, &unmap))
{}
SratomStatus write(const serd::Env& env,
@@ -144,13 +144,13 @@ private:
};
class Loader
- : public serd::detail::BasicWrapper<SratomLoader, sratom_loader_free>
+ : public serd::detail::StaticWrapper<SratomLoader, sratom_loader_free>
{
public:
using AtomPtr = std::unique_ptr<LV2_Atom, detail::Deleter>;
Loader(serd::World& world, LV2_URID_Map& map)
- : BasicWrapper(sratom_loader_new(world.cobj(), &map))
+ : StaticWrapper(sratom_loader_new(world.cobj(), &map))
{}
SratomStatus load(const serd::Optional<serd::Node>& base_uri,
diff --git a/bindings/cpp/meson.build b/bindings/cpp/meson.build
index ea6d336..c99f3ec 100644
--- a/bindings/cpp/meson.build
+++ b/bindings/cpp/meson.build
@@ -53,9 +53,9 @@ cpp_headers = [
'include/sratom/sratom.hpp',
]
-serdpp_dep = dependency('serdxx-1',
+serdpp_dep = dependency('serdpp-1',
version: '>= 1.0.0',
- fallback: ['serd', 'serdxx_dep'])
+ fallback: ['serd', 'serdpp_dep'])
sratompp_dep = declare_dependency(
include_directories: include_directories(['include']),
diff --git a/doc/c/overview.rst b/doc/c/overview.rst
index 2ffcfd1..c6347d6 100644
--- a/doc/c/overview.rst
+++ b/doc/c/overview.rst
@@ -51,13 +51,13 @@ For example:
.. code-block:: c
- SerdStringView base = SERD_STATIC_STRING("file:///tmp/state/");
+ SerdStringView base = SERD_STRING("file:///tmp/state/");
SerdEnv* env = serd_env_new(base);
serd_env_set_prefix(
env,
- SERD_STATIC_STRING("atom"),
- SERD_STATIC_STRING("http://lv2plug.in/ns/ext/atom#"));
+ SERD_STRING("atom"),
+ SERD_STRING("http://lv2plug.in/ns/ext/atom#"));
With the environment configured,
:func:`sratom_to_string` can be used to convert atoms to strings:
diff --git a/src/dumper.c b/src/dumper.c
index 9936230..7628f0d 100644
--- a/src/dumper.c
+++ b/src/dumper.c
@@ -34,11 +34,11 @@
#define NS_XSD "http://www.w3.org/2001/XMLSchema#"
#define DUMP_WARN(msg) \
- serd_world_logf(writer->world, "sratom", SERD_LOG_LEVEL_WARNING, 0, NULL, msg)
+ serd_world_logf(writer->world, SERD_LOG_LEVEL_WARNING, 0, NULL, msg)
#define DUMP_ERRORF(msg, ...) \
serd_world_logf( \
- writer->world, "sratom", SERD_LOG_LEVEL_ERROR, 0, NULL, msg, __VA_ARGS__)
+ writer->world, SERD_LOG_LEVEL_ERROR, 0, NULL, msg, __VA_ARGS__)
struct SratomDumperImpl {
LV2_URID_Unmap* unmap;
@@ -103,9 +103,8 @@ sratom_dumper_new(SerdWorld* const world,
dumper->midi_MidiEvent = map->map(map->handle, LV2_MIDI__MidiEvent);
lv2_atom_forge_init(&dumper->forge, map);
-#define MANAGE_URI(uri) \
- serd_nodes_manage(serd_world_nodes(world), \
- serd_new_uri(SERD_STATIC_STRING(uri)))
+#define MANAGE_URI(uri) \
+ serd_nodes_uri(serd_world_nodes(world), SERD_STRING(uri))
dumper->nodes.atom_Path = MANAGE_URI(LV2_ATOM__Path);
dumper->nodes.atom_beatTime = MANAGE_URI(LV2_ATOM__beatTime);
@@ -193,7 +192,7 @@ start_object(StreamContext* const ctx,
}
if (type) {
- SerdNode* const o = serd_new_uri(SERD_MEASURE_STRING(type));
+ SerdNode* const o = serd_new_uri(SERD_STRING(type));
serd_sink_write(
ctx->sink, ctx->sflags, node, ctx->writer->nodes.rdf_type, o, NULL);
@@ -220,7 +219,7 @@ path_is_absolute(const char* const path)
(path[2] == '/' || path[2] == '\\')));
}
-static const SerdNode*
+static SerdStringView
number_type(const StreamContext* const ctx, const SerdNode* const type)
{
SratomDumper* const writer = ctx->writer;
@@ -228,15 +227,15 @@ number_type(const StreamContext* const ctx, const SerdNode* const type)
if (pretty) {
if (type == writer->nodes.xsd_int || type == writer->nodes.xsd_long) {
- return writer->nodes.xsd_integer;
+ return serd_node_string_view(writer->nodes.xsd_integer);
}
if (type == writer->nodes.xsd_float || type == writer->nodes.xsd_double) {
- return writer->nodes.xsd_decimal;
+ return serd_node_string_view(writer->nodes.xsd_decimal);
}
}
- return type;
+ return serd_node_string_view(type);
}
static bool
@@ -269,23 +268,24 @@ write_atom(StreamContext* const ctx,
if (type == 0 && size == 0) {
object = serd_node_copy(writer->nodes.rdf_nil);
} else if (type == writer->forge.String) {
- object = serd_new_string(SERD_MEASURE_STRING((const char*)body));
+ object = serd_new_string(SERD_STRING((const char*)body));
} else if (type == writer->forge.Chunk) {
- object = serd_new_blob(body, size, NULL);
+ object = serd_new_base64(body, size, SERD_EMPTY_STRING());
} else if (type == writer->forge.Literal) {
const LV2_Atom_Literal_Body* lit = (const LV2_Atom_Literal_Body*)body;
const char* str = (const char*)(lit + 1);
if (lit->datatype) {
const SerdStringView datatype_uri =
- SERD_MEASURE_STRING(unmap->unmap(unmap->handle, lit->datatype));
- object = serd_new_typed_literal(SERD_MEASURE_STRING(str), datatype_uri);
+ SERD_STRING(unmap->unmap(unmap->handle, lit->datatype));
+ object =
+ serd_new_literal(SERD_STRING(str), SERD_HAS_DATATYPE, datatype_uri);
} else if (lit->lang) {
const char* lang = unmap->unmap(unmap->handle, lit->lang);
const char* prefix = "http://lexvo.org/id/iso639-3/";
const size_t prefix_len = strlen(prefix);
if (lang && !strncmp(lang, prefix, prefix_len)) {
- object = serd_new_plain_literal(SERD_MEASURE_STRING(str),
- SERD_MEASURE_STRING(lang + prefix_len));
+ object = serd_new_literal(
+ SERD_STRING(str), SERD_HAS_LANGUAGE, SERD_STRING(lang + prefix_len));
} else {
DUMP_ERRORF("Unknown language URID %u\n", lit->lang);
}
@@ -294,9 +294,9 @@ write_atom(StreamContext* const ctx,
const uint32_t urid = *(const uint32_t*)body;
const char* str = unmap->unmap(unmap->handle, urid);
- object = serd_new_uri(SERD_MEASURE_STRING(str));
+ object = serd_new_uri(SERD_STRING(str));
} else if (type == writer->forge.Path) {
- const SerdStringView str = SERD_MEASURE_STRING((const char*)body);
+ const SerdStringView str = SERD_STRING((const char*)body);
if (path_is_absolute(str.buf)) {
object = serd_new_file_uri(str, SERD_EMPTY_STRING());
} else {
@@ -304,8 +304,10 @@ write_atom(StreamContext* const ctx,
if (!base_uri || strncmp(serd_node_string(base_uri), "file://", 7)) {
DUMP_WARN("Relative path but base is not a file URI.\n");
DUMP_WARN("Writing ambiguous atom:Path literal.\n");
- object = serd_new_typed_literal(
- str, serd_node_string_view(writer->nodes.atom_Path));
+ object =
+ serd_new_literal(str,
+ SERD_HAS_DATATYPE,
+ serd_node_string_view(writer->nodes.atom_Path));
} else {
SerdNode* const rel = serd_new_file_uri(str, SERD_EMPTY_STRING());
@@ -316,7 +318,7 @@ write_atom(StreamContext* const ctx,
}
}
} else if (type == writer->forge.URI) {
- object = serd_new_uri(SERD_MEASURE_STRING((const char*)body));
+ object = serd_new_uri(SERD_STRING((const char*)body));
} else if (type == writer->forge.Int) {
object = serd_new_integer(*(const int32_t*)body,
number_type(ctx, writer->nodes.xsd_int));
@@ -324,11 +326,9 @@ write_atom(StreamContext* const ctx,
object = serd_new_integer(*(const int64_t*)body,
number_type(ctx, writer->nodes.xsd_long));
} else if (type == writer->forge.Float) {
- object = serd_new_decimal(*(const float*)body,
- number_type(ctx, writer->nodes.xsd_float));
+ object = serd_new_float(*(const float*)body);
} else if (type == writer->forge.Double) {
- object = serd_new_decimal(*(const double*)body,
- number_type(ctx, writer->nodes.xsd_double));
+ object = serd_new_double(*(const double*)body);
} else if (type == writer->forge.Bool) {
object = serd_new_boolean(*(const int32_t*)body);
} else if (type == writer->midi_MidiEvent) {
@@ -341,9 +341,10 @@ write_atom(StreamContext* const ctx,
(unsigned)*((const uint8_t*)body + i));
}
- object = serd_new_typed_literal(
- SERD_STRING_VIEW(str, len),
- serd_node_string_view(writer->nodes.midi_MidiEvent));
+ object =
+ serd_new_literal(SERD_SUBSTRING(str, len),
+ SERD_HAS_DATATYPE,
+ serd_node_string_view(writer->nodes.midi_MidiEvent));
free(str);
} else if (type == writer->atom_Event) {
@@ -392,9 +393,9 @@ write_atom(StreamContext* const ctx,
SerdNode* id = serd_node_copy(serd_world_get_blank(writer->world));
start_object(ctx, subject, predicate, id, type_uri);
- const SerdNode* p = writer->nodes.atom_childType;
- SerdNode* const child_type = serd_new_uri(
- SERD_MEASURE_STRING(unmap->unmap(unmap->handle, vec->child_type)));
+ const SerdNode* p = writer->nodes.atom_childType;
+ SerdNode* const child_type =
+ serd_new_uri(SERD_STRING(unmap->unmap(unmap->handle, vec->child_type)));
serd_sink_write(sink, ctx->sflags, id, p, child_type, NULL);
p = writer->nodes.rdf_value;
@@ -421,14 +422,13 @@ write_atom(StreamContext* const ctx,
id = serd_node_copy(serd_world_get_blank(writer->world));
start_object(ctx, subject, predicate, id, otype);
} else {
- id =
- serd_new_uri(SERD_MEASURE_STRING(unmap->unmap(unmap->handle, obj->id)));
+ id = serd_new_uri(SERD_STRING(unmap->unmap(unmap->handle, obj->id)));
ctx->sflags = 0;
start_object(ctx, NULL, NULL, id, otype);
}
LV2_ATOM_OBJECT_BODY_FOREACH (obj, size, prop) {
const char* const key = unmap->unmap(unmap->handle, prop->key);
- SerdNode* const pred = serd_new_uri(SERD_MEASURE_STRING(key));
+ SerdNode* const pred = serd_new_uri(SERD_STRING(key));
write_atom(ctx,
id,
pred,
@@ -461,7 +461,7 @@ write_atom(StreamContext* const ctx,
const SerdNode* id = serd_world_get_blank(writer->world);
start_object(ctx, subject, predicate, id, type_uri);
const SerdNode* p = writer->nodes.rdf_value;
- SerdNode* o = serd_new_blob(body, size, NULL);
+ SerdNode* o = serd_new_base64(body, size, SERD_EMPTY_STRING());
serd_sink_write(sink, ctx->sflags, id, p, o, NULL);
end_object(ctx, subject, predicate, id);
serd_node_free(o);
diff --git a/src/loader.c b/src/loader.c
index c9b01a7..e0aa067 100644
--- a/src/loader.c
+++ b/src/loader.c
@@ -32,7 +32,7 @@
#define NS_XSD "http://www.w3.org/2001/XMLSchema#"
#define LOAD_ERROR(msg) \
- serd_world_logf(loader->world, "sratom", SERD_LOG_LEVEL_ERROR, 0, NULL, msg)
+ serd_world_logf(loader->world, SERD_LOG_LEVEL_ERROR, 0, NULL, msg)
typedef enum { MODE_SUBJECT, MODE_BODY, MODE_SEQUENCE } ReadMode;
@@ -86,9 +86,8 @@ sratom_loader_new(SerdWorld* const world, LV2_URID_Map* const map)
lv2_atom_forge_init(&loader->forge, map);
-#define MANAGE_URI(uri) \
- serd_nodes_manage(serd_world_nodes(world), \
- serd_new_uri(SERD_STATIC_STRING(uri)))
+#define MANAGE_URI(uri) \
+ serd_nodes_uri(serd_world_nodes(world), SERD_STRING(uri))
loader->nodes.atom_beatTime = MANAGE_URI(LV2_ATOM__beatTime);
loader->nodes.atom_childType = MANAGE_URI(LV2_ATOM__childType);
@@ -137,9 +136,9 @@ read_resource(LoadContext* const ctx,
const LV2_URID otype)
{
LV2_URID_Map* const map = ctx->loader->map;
- SerdRange* const r = serd_model_range(model, node, NULL, NULL, NULL);
- for (; !serd_range_empty(r); serd_range_next(r)) {
- const SerdStatement* match = serd_range_front(r);
+ SerdCursor* const r = serd_model_find(model, node, NULL, NULL, NULL);
+ for (; !serd_cursor_is_end(r); serd_cursor_advance(r)) {
+ const SerdStatement* match = serd_cursor_get(r);
if (match) {
const SerdNode* const p = serd_statement_predicate(match);
const SerdNode* const o = serd_statement_object(match);
@@ -153,7 +152,7 @@ read_resource(LoadContext* const ctx,
}
}
}
- serd_range_free(r);
+ serd_cursor_free(r);
}
static uint32_t
@@ -248,10 +247,15 @@ read_typed_literal(SratomLoader* const loader,
} else if (!strcmp(type_uri, NS_XSD "boolean")) {
ref = lv2_atom_forge_bool(forge, serd_get_boolean(node));
} else if (!strcmp(type_uri, NS_XSD "base64Binary")) {
- size_t size = 0;
- void* const body = serd_base64_decode(str, len, &size);
- if ((ref = lv2_atom_forge_atom(forge, size, forge->Chunk))) {
- ref = lv2_atom_forge_write(forge, body, size);
+ const size_t size = serd_get_base64_size(node);
+ void* const body = malloc(size);
+ const SerdWriteResult r = serd_get_base64(node, size, body);
+ if (r.status) {
+ return SRATOM_BAD_FORGE;
+ }
+
+ if ((ref = lv2_atom_forge_atom(forge, r.count, forge->Chunk))) {
+ ref = lv2_atom_forge_write(forge, body, r.count);
}
free(body);
} else if (!strcmp(type_uri, LV2_ATOM__Path)) {
@@ -404,12 +408,15 @@ read_object(LoadContext* const ctx,
} else if (value && serd_node_equals(serd_node_datatype(value),
loader->nodes.xsd_base64Binary)) {
- const char* const vstr = serd_node_string(value);
- const size_t vlen = serd_node_length(value);
- size_t size = 0;
- void* body = serd_base64_decode(vstr, vlen, &size);
- lv2_atom_forge_atom(forge, size, type_urid);
- lv2_atom_forge_write(forge, body, size);
+ const size_t size = serd_get_base64_size(value);
+ void* const body = malloc(size);
+ const SerdWriteResult r = serd_get_base64(value, size, body);
+ if (r.status) {
+ return SRATOM_BAD_FORGE;
+ }
+
+ lv2_atom_forge_atom(forge, r.count, type_urid);
+ lv2_atom_forge_write(forge, body, r.count);
free(body);
} else if (serd_node_type(node) == SERD_URI) {
@@ -467,10 +474,10 @@ model_from_string(SratomLoader* const loader,
SerdEnv* const env,
const char* const str)
{
- SerdModel* const model = serd_model_new(loader->world, SERD_INDEX_SPO);
+ SerdModel* const model = serd_model_new(loader->world, SERD_ORDER_SPO, 0u);
SerdSink* const inserter = serd_inserter_new(model, NULL);
- SerdNode* const name = serd_new_string(SERD_STATIC_STRING("string"));
+ SerdNode* const name = serd_new_string(SERD_STRING("string"));
SerdByteSource* const source = serd_byte_source_new_string(str, name);
SerdReader* const reader = serd_reader_new(
loader->world, SERD_TURTLE, SERD_READ_LAX, env, inserter, 4096);
@@ -504,8 +511,8 @@ sratom_from_string(SratomLoader* const loader,
}
const SerdNode* node = NULL;
- SerdIter* const begin = serd_model_begin(model);
- const SerdStatement* const s = serd_iter_get(begin);
+ SerdCursor* const begin = serd_model_begin(model);
+ const SerdStatement* const s = serd_cursor_get(begin);
assert(s);
if (serd_model_size(model) == 2 &&
@@ -525,7 +532,7 @@ sratom_from_string(SratomLoader* const loader,
LV2_Atom* atom =
sratom_from_model(loader, serd_env_base_uri(env), model, node);
- serd_iter_free(begin);
+ serd_cursor_free(begin);
serd_model_free(model);
return atom;
}
diff --git a/test/test_sratom.c b/test/test_sratom.c
index 11154d4..06c3512 100644
--- a/test/test_sratom.c
+++ b/test/test_sratom.c
@@ -323,19 +323,14 @@ test(SerdEnv* env, const char* name, const SratomDumperFlags flags)
int
main(void)
{
- SerdEnv* const env = serd_env_new(SERD_STATIC_STRING("file:///tmp/base/"));
+ SerdEnv* const env = serd_env_new(SERD_STRING("file:///tmp/base/"));
serd_env_set_prefix(
- env, SERD_STATIC_STRING("eg"), SERD_STATIC_STRING("http://example.org/"));
+ env, SERD_STRING("eg"), SERD_STRING("http://example.org/"));
- serd_env_set_prefix(
- env, SERD_STATIC_STRING("atom"), SERD_STATIC_STRING(NS_ATOM));
-
- serd_env_set_prefix(
- env, SERD_STATIC_STRING("rdf"), SERD_STATIC_STRING(NS_RDF));
-
- serd_env_set_prefix(
- env, SERD_STATIC_STRING("xsd"), SERD_STATIC_STRING(NS_XSD));
+ serd_env_set_prefix(env, SERD_STRING("atom"), SERD_STRING(NS_ATOM));
+ serd_env_set_prefix(env, SERD_STRING("rdf"), SERD_STRING(NS_RDF));
+ serd_env_set_prefix(env, SERD_STRING("xsd"), SERD_STRING(NS_XSD));
const int st =
(test(env, "Default", 0) || //