summaryrefslogtreecommitdiffstats
path: root/sord
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-05-18 02:17:20 +0000
committerDavid Robillard <d@drobilla.net>2011-05-18 02:17:20 +0000
commit602ad00d48276646ce85a9b472da6462eb323bae (patch)
tree66eee25ad4020219d450834559626ff242a6cef2 /sord
parentd6b69d9930b6bd918db346f8a03a99ed1e25cf65 (diff)
downloadsord-602ad00d48276646ce85a9b472da6462eb323bae.tar.gz
sord-602ad00d48276646ce85a9b472da6462eb323bae.tar.bz2
sord-602ad00d48276646ce85a9b472da6462eb323bae.zip
Add sordi-i option to select input syntax.
Add syntax parameter to sord_write_string and sord_write_file. Remove read functions in favour of sord_new_reader and direct use of SerdReader API. Bump version to 0.3.0. git-svn-id: http://svn.drobilla.net/sord/trunk@121 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'sord')
-rw-r--r--sord/sord.h62
-rw-r--r--sord/sordmm.hpp51
2 files changed, 42 insertions, 71 deletions
diff --git a/sord/sord.h b/sord/sord.h
index 62bef78..5796a6a 100644
--- a/sord/sord.h
+++ b/sord/sord.h
@@ -265,10 +265,20 @@ bool
sord_node_equals(const SordNode* a,
const SordNode* b);
+/**
+ Return a SordNode as a SerdNode.
+
+ The returned node is shared and must not be freed or modified.
+*/
SORD_API
const SerdNode*
sord_node_to_serd_node(const SordNode* node);
+/**
+ Create a new SordNode from a SerdNode.
+
+ The returned node must be freed using sord_node_free.
+*/
SORD_API
SordNode*
sord_node_from_serd_node(SordWorld* world,
@@ -426,41 +436,14 @@ sord_quad_match(const SordQuad x, const SordQuad y);
*/
/**
- Read a file into a model.
-
- The @c base_uri may be NULL, in which case @c uri will be used.
-*/
-SORD_API
-bool
-sord_read_file(SordModel* model,
- SerdEnv* env,
- const uint8_t* uri,
- const uint8_t* base_uri,
- SordNode* graph,
- const uint8_t* blank_prefix);
-
-/**
- Read a file handle into a model.
-*/
-SORD_API
-bool
-sord_read_file_handle(SordModel* model,
- SerdEnv* env,
- FILE* fd,
- const uint8_t* name,
- const uint8_t* base_uri,
- SordNode* graph,
- const uint8_t* blank_prefix);
-
-/**
- Read a string into a model.
+ Return a reader that will read into @c model.
*/
SORD_API
-bool
-sord_read_string(SordModel* model,
- SerdEnv* env,
- const uint8_t* str,
- const uint8_t* base_uri);
+SerdReader*
+sord_new_reader(SordModel* model,
+ SerdEnv* env,
+ SerdSyntax syntax,
+ SordNode* graph);
/**
Write a model to a file.
@@ -469,24 +452,16 @@ SORD_API
bool
sord_write_file(SordModel* model,
SerdEnv* env,
+ SerdSyntax syntax,
const uint8_t* uri,
SordNode* graph,
const uint8_t* blank_prefix);
/**
- Write a model to a file handle.
+ Write a model to a writer.
*/
SORD_API
bool
-sord_write_file_handle(SordModel* model,
- SerdEnv* env,
- FILE* fd,
- const uint8_t* base_uri,
- SordNode* graph,
- const uint8_t* blank_prefix);
-
-SORD_API
-bool
sord_write_writer(SordModel* model,
SerdWriter* writer,
SordNode* graph);
@@ -500,6 +475,7 @@ SORD_API
uint8_t*
sord_write_string(SordModel* model,
SerdEnv* env,
+ SerdSyntax syntax,
const uint8_t* base_uri);
/**
diff --git a/sord/sordmm.hpp b/sord/sordmm.hpp
index 6f9391b..75e4a21 100644
--- a/sord/sordmm.hpp
+++ b/sord/sordmm.hpp
@@ -63,7 +63,7 @@ protected:
/** Collection of RDF namespaces with prefixes. */
class Namespaces : public Wrapper<SerdEnv*> {
public:
- Namespaces() : Wrapper<SerdEnv*>(serd_env_new()) {}
+ Namespaces() : Wrapper<SerdEnv*>(serd_env_new(NULL)) {}
static inline SerdNode string_to_node(SerdType type, const std::string& s) {
SerdNode ret = {
@@ -391,19 +391,19 @@ public:
inline const Node& base_uri() const { return _base; }
inline void load_file(SerdEnv* env,
+ SerdSyntax syntax,
const std::string& uri,
const std::string& base_uri="");
inline void load_string(SerdEnv* env,
+ SerdSyntax syntax,
const char* str,
size_t len,
- const std::string& base_uri,
- const std::string lang="turtle");
+ const std::string& base_uri);
- inline void write_to_file_handle(FILE* fd, const char* lang);
- inline void write_to_file(const std::string& uri, const char* lang);
+ inline void write_to_file(const std::string& uri, SerdSyntax syntax);
- inline std::string write_to_string(const char* lang);
+ inline std::string write_to_string(SerdSyntax syntax);
inline void add_statement(const Node& subject,
const Node& predicate,
@@ -436,15 +436,14 @@ Model::Model(World& world, const std::string& base_uri)
inline void
Model::load_string(SerdEnv* env,
+ SerdSyntax syntax,
const char* str,
size_t len,
- const std::string& base_uri,
- const std::string lang)
+ const std::string& base_uri)
{
- sord_read_string(_c_obj,
- env,
- (const uint8_t*)str,
- (const uint8_t*)base_uri.c_str());
+ SerdReader* reader = sord_new_reader(_c_obj, env, syntax, NULL);
+ serd_reader_read_string(reader, (const uint8_t*)str);
+ serd_reader_free(reader);
}
inline Model::~Model()
@@ -454,41 +453,37 @@ inline Model::~Model()
inline void
Model::load_file(SerdEnv* env,
+ SerdSyntax syntax,
const std::string& data_uri,
const std::string& base_uri)
{
- // FIXME: blank prefix
- sord_read_file(_c_obj, env, (const uint8_t*)data_uri.c_str(),
- (base_uri == "") ? NULL : (const uint8_t*)base_uri.c_str(),
- NULL, (const uint8_t*)"b");
-}
+ if (data_uri.substr(0, 5) != "file:") {
+ return;
+ }
-inline void
-Model::write_to_file_handle(FILE* fd, const char* lang)
-{
- sord_write_file_handle(_c_obj,
- _world.prefixes().c_obj(),
- fd,
- _base.to_u_string(),
- NULL,
- NULL);
+ // FIXME: blank prefix parameter?
+ SerdReader* reader = sord_new_reader(_c_obj, env, syntax, NULL);
+ serd_reader_read_file(reader, (const uint8_t*)(data_uri.c_str() + 5));
+ serd_reader_free(reader);
}
inline void
-Model::write_to_file(const std::string& uri, const char* lang)
+Model::write_to_file(const std::string& uri, SerdSyntax syntax)
{
sord_write_file(_c_obj,
_world.prefixes().c_obj(),
+ syntax,
(const uint8_t*)uri.c_str(),
NULL,
NULL);
}
inline std::string
-Model::write_to_string(const char* lang)
+Model::write_to_string(SerdSyntax syntax)
{
uint8_t* const c_str = sord_write_string(_c_obj,
_world.prefixes().c_obj(),
+ syntax,
base_uri().to_u_string());
std::string ret((const char*)c_str);
free(c_str);