summaryrefslogtreecommitdiffstats
path: root/sord
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-02-19 07:13:59 +0000
committerDavid Robillard <d@drobilla.net>2011-02-19 07:13:59 +0000
commitd4b996a4149f2e303e4ef16c67804c8ad49524bb (patch)
tree0e13e2a9a55ea312cf74f03a24dc2acc29a762c1 /sord
parent36d5e18e931ffdb0b203178a7a5acc3e909a9536 (diff)
downloadsord-d4b996a4149f2e303e4ef16c67804c8ad49524bb.tar.gz
sord-d4b996a4149f2e303e4ef16c67804c8ad49524bb.tar.bz2
sord-d4b996a4149f2e303e4ef16c67804c8ad49524bb.zip
String reading/writing.
git-svn-id: http://svn.drobilla.net/sord/trunk@39 3d64ff67-21c5-427c-a301-fe4f08042e5a
Diffstat (limited to 'sord')
-rw-r--r--sord/sord.h13
-rw-r--r--sord/sordmm.hpp23
2 files changed, 27 insertions, 9 deletions
diff --git a/sord/sord.h b/sord/sord.h
index f1169f9..c632815 100644
--- a/sord/sord.h
+++ b/sord/sord.h
@@ -338,6 +338,12 @@ sord_read_file_handle(SordModel model,
SORD_API
bool
+sord_read_string(SordModel model,
+ const uint8_t* str,
+ const uint8_t* base_uri);
+
+SORD_API
+bool
sord_write_file(SordModel model,
SerdEnv env,
const uint8_t* uri,
@@ -353,6 +359,13 @@ sord_write_file_handle(SordModel model,
const SordNode graph,
const uint8_t* blank_prefix);
+SORD_API
+uint8_t*
+sord_write_string(SordModel model,
+ SerdEnv env,
+ const uint8_t* base_uri);
+
+
/** @} */
/** @} */
diff --git a/sord/sordmm.hpp b/sord/sordmm.hpp
index 78fc14c..259e2c2 100644
--- a/sord/sordmm.hpp
+++ b/sord/sordmm.hpp
@@ -202,7 +202,7 @@ private:
inline std::ostream&
operator<<(std::ostream& os, const Node& node)
{
- return os << node.to_string() << std::endl;
+ return os << node.to_string();
}
class URI : public Node {
@@ -284,14 +284,12 @@ Node::~Node()
}
}
-
inline std::string
Node::to_string() const
{
- return std::string(to_c_string());
+ return _c_obj ? (const char*)sord_node_get_string(_c_obj) : "";
}
-
inline const char*
Node::to_c_string() const
{
@@ -391,7 +389,8 @@ public:
inline void write_to_file_handle(FILE* fd, const char* lang);
inline void write_to_file(const Glib::ustring& uri, const char* lang);
- inline char* write_to_string(const char* lang);
+
+ inline std::string write_to_string(const char* lang);
inline void add_statement(const Node& subject,
const Node& predicate,
@@ -428,7 +427,9 @@ Model::load_string(const char* str,
const Glib::ustring& base_uri,
const std::string lang)
{
- // TODO
+ sord_read_string(_c_obj,
+ (const uint8_t*)str,
+ (const uint8_t*)base_uri.c_str());
}
inline Model::~Model()
@@ -465,11 +466,15 @@ Model::write_to_file(const Glib::ustring& uri, const char* lang)
NULL);
}
-inline char*
+inline std::string
Model::write_to_string(const char* lang)
{
- std::cerr << "TODO: serialise" << std::endl;
- return NULL;
+ uint8_t* const c_str = sord_write_string(_c_obj,
+ _world.prefixes().c_obj(),
+ base_uri().to_u_string());
+ std::string ret((const char*)c_str);
+ free(c_str);
+ return ret;
}
inline void