aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-12 17:56:27 +0200
committerDavid Robillard <d@drobilla.net>2018-11-25 22:12:46 +0100
commit5683b00d0487f9ae7710653a03523714f6ff50ee (patch)
tree25aae24944da934982fc88e33bff3fff99579d95
parent54ceea1115d9dfd77542d9b3551277b499c41d1f (diff)
downloadserd-5683b00d0487f9ae7710653a03523714f6ff50ee.tar.gz
serd-5683b00d0487f9ae7710653a03523714f6ff50ee.tar.bz2
serd-5683b00d0487f9ae7710653a03523714f6ff50ee.zip
Add serd_world_get_blank()
-rw-r--r--serd/serd.h10
-rw-r--r--src/world.c20
-rw-r--r--src/world.h2
3 files changed, 31 insertions, 1 deletions
diff --git a/serd/serd.h b/serd/serd.h
index 6228211b..41b03fbd 100644
--- a/serd/serd.h
+++ b/serd/serd.h
@@ -750,6 +750,16 @@ void
serd_world_free(SerdWorld* world);
/**
+ Return a unique blank node.
+
+ The returned node is valid only until the next time serd_world_get_blank()
+ is called or the world is destroyed.
+*/
+SERD_API
+const SerdNode*
+serd_world_get_blank(SerdWorld* world);
+
+/**
Set a function to be called when errors occur.
The `error_sink` will be called with `handle` as its first argument. If
diff --git a/src/world.c b/src/world.c
index c35cdd55..205646f2 100644
--- a/src/world.c
+++ b/src/world.c
@@ -18,6 +18,7 @@
#include "world.h"
+#include "node.h"
#include "serd_config.h"
#include <errno.h>
@@ -29,6 +30,8 @@
# include <fcntl.h>
#endif
+#define BLANK_CHARS 11
+
FILE*
serd_world_fopen(SerdWorld* world, const char* path, const char* mode)
{
@@ -71,15 +74,30 @@ serd_world_errorf(const SerdWorld* world, SerdStatus st, const char* fmt, ...)
SerdWorld*
serd_world_new(void)
{
- return (SerdWorld*)calloc(1, sizeof(SerdWorld));
+ SerdWorld* world = (SerdWorld*)calloc(1, sizeof(SerdWorld));
+
+ world->blank_node = serd_node_new_blank("b0000000000");
+
+ return world;
}
void
serd_world_free(SerdWorld* world)
{
+ serd_node_free(world->blank_node);
free(world);
}
+const SerdNode*
+serd_world_get_blank(SerdWorld* world)
+{
+ char* buf = serd_node_buffer(world->blank_node);
+ memset(buf, 0, BLANK_CHARS + 1);
+ world->blank_node->n_bytes = snprintf(
+ buf, BLANK_CHARS, "b%u", ++world->next_blank_id);
+ return world->blank_node;
+}
+
void
serd_world_set_error_sink(SerdWorld* world,
SerdErrorSink error_sink,
diff --git a/src/world.h b/src/world.h
index 85b676ee..99ef27b8 100644
--- a/src/world.h
+++ b/src/world.h
@@ -24,6 +24,8 @@
struct SerdWorldImpl {
SerdErrorSink error_sink;
void* error_handle;
+ uint32_t next_blank_id;
+ SerdNode* blank_node;
};
FILE* serd_world_fopen(SerdWorld* world, const char* path, const char* mode);