summaryrefslogtreecommitdiffstats
path: root/src/serialisation
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-14 04:23:23 +0000
committerDavid Robillard <d@drobilla.net>2012-08-14 04:23:23 +0000
commit80fee5c311fdbdeda573ec81f59158a5fc87d0a1 (patch)
tree8e7e5a6c9bda32bbe0ae8e8c9f6ab23e44c7c181 /src/serialisation
parent058eaf65642268047a984a5c80d54a1f62a85130 (diff)
downloadingen-80fee5c311fdbdeda573ec81f59158a5fc87d0a1.tar.gz
ingen-80fee5c311fdbdeda573ec81f59158a5fc87d0a1.tar.bz2
ingen-80fee5c311fdbdeda573ec81f59158a5fc87d0a1.zip
Update for latest Raul.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4687 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/serialisation')
-rw-r--r--src/serialisation/Parser.cpp41
-rw-r--r--src/serialisation/Serialiser.cpp16
2 files changed, 29 insertions, 28 deletions
diff --git a/src/serialisation/Parser.cpp b/src/serialisation/Parser.cpp
index f67eaf7f..a32fa9fd 100644
--- a/src/serialisation/Parser.cpp
+++ b/src/serialisation/Parser.cpp
@@ -139,12 +139,12 @@ get_properties(Ingen::World* world,
typedef std::pair<Path, Resource::Properties> PortRecord;
-static int
+static boost::optional<PortRecord>
get_port(Ingen::World* world,
Sord::Model& model,
const Sord::Node& subject,
const Raul::Path& parent,
- PortRecord& record)
+ uint32_t& index)
{
const URIs& uris = world->uris();
@@ -156,22 +156,21 @@ get_port(Ingen::World* world,
if (i == props.end()
|| i->second.type() != world->forge().Int
|| i->second.get_int32() < 0) {
- LOG(error) << "Port " << subject << " has no valid lv2:index" << endl;
- return -1;
+ LOG(error) << "Port " << subject << " has no valid index" << endl;
+ return boost::optional<PortRecord>();
}
- const uint32_t index = i->second.get_int32();
+ index = i->second.get_int32();
// Get symbol
Resource::Properties::const_iterator s = props.find(uris.lv2_symbol);
if (s == props.end()) {
LOG(error) << "Port " << subject << " has no symbol" << endl;
- return -1;
+ return boost::optional<PortRecord>();
}
const Symbol port_sym(s->second.get_string());
const Path port_path = parent.child(port_sym);
- record = make_pair(port_path, props);
- return index;
+ return make_pair(port_path, props);
}
static boost::optional<Raul::Path>
@@ -278,7 +277,7 @@ parse_node(Ingen::World* world,
} else {
Resource::Properties props = get_properties(world, model, subject);
props.insert(make_pair(uris.rdf_type,
- uris.forge.alloc_uri(uris.ingen_Node.str())));
+ uris.forge.alloc_uri(uris.ingen_Node)));
target->put(GraphObject::path_to_uri(path), props);
}
return path;
@@ -311,7 +310,7 @@ parse_patch(Ingen::World* world,
string patch_path_str = relative_uri(base_uri, subject_node.to_string(), true);
if (parent && a_symbol)
- patch_path_str = parent->child(*a_symbol).str();
+ patch_path_str = parent->child(*a_symbol);
if (!Path::is_valid(patch_path_str)) {
LOG(error) << "Patch has invalid path: " << patch_path_str << endl;
@@ -338,16 +337,17 @@ parse_patch(Ingen::World* world,
Sord::Node port = p.get_object();
// Get all properties
- PortRecord port_record;
- const int index = get_port(world, model, port, node_path, port_record);
- if (index < 0) {
+ uint32_t index = 0;
+ boost::optional<PortRecord> port_record = get_port(
+ world, model, port, node_path, index);
+ if (!port_record) {
LOG(error) << "Invalid port " << port << endl;
return boost::optional<Path>();
}
// Create port and/or set all port properties
- target->put(GraphObject::path_to_uri(port_record.first),
- port_record.second);
+ target->put(GraphObject::path_to_uri(port_record->first),
+ port_record->second);
}
}
@@ -358,15 +358,16 @@ parse_patch(Ingen::World* world,
Sord::Node port = p.get_object();
// Get all properties
- PortRecord port_record;
- const int index = get_port(world, model, port, patch_path, port_record);
- if (index < 0) {
+ uint32_t index = 0;
+ boost::optional<PortRecord> port_record = get_port(
+ world, model, port, patch_path, index);
+ if (!port_record) {
LOG(Raul::error) << "Invalid port " << port << endl;
return boost::optional<Path>();
}
// Store port information in ports map
- ports[index] = port_record;
+ ports[index] = *port_record;
}
// Create ports in order by index
@@ -597,7 +598,7 @@ Parser::parse_file(Ingen::World* world,
if (parsed_path) {
target->set_property(GraphObject::path_to_uri(*parsed_path),
- "http://drobilla.net/ns/ingen#document",
+ Raul::URI("http://drobilla.net/ns/ingen#document"),
world->forge().alloc_uri(uri));
} else {
LOG(Raul::warn)("Document URI lost\n");
diff --git a/src/serialisation/Serialiser.cpp b/src/serialisation/Serialiser.cpp
index bd7dfed5..a6af8923 100644
--- a/src/serialisation/Serialiser.cpp
+++ b/src/serialisation/Serialiser.cpp
@@ -275,9 +275,9 @@ Serialiser::Impl::path_rdf_node(const Path& path)
{
assert(_model);
assert(path == _root_path || path.is_child_of(_root_path));
- const Path rel_path(path.relative_to_base(_root_path));
+ // FIXME: if path == root_path() then "/" ?
return Sord::URI(_model->world(),
- rel_path.substr(1).c_str(),
+ path.substr(_root_path.base().length()),
_base_uri);
}
@@ -290,7 +290,7 @@ Serialiser::serialise(SharedPtr<const GraphObject> object) throw (std::logic_err
if (object->graph_type() == GraphObject::PATCH) {
me->serialise_patch(object, me->path_rdf_node(object->path()));
} else if (object->graph_type() == GraphObject::NODE) {
- const Sord::URI plugin_id(me->_model->world(), object->plugin()->uri().str());
+ const Sord::URI plugin_id(me->_model->world(), object->plugin()->uri());
me->serialise_node(object, plugin_id, me->path_rdf_node(object->path()));
} else if (object->graph_type() == GraphObject::PORT) {
me->serialise_port(object.get(),
@@ -347,7 +347,7 @@ Serialiser::Impl::serialise_patch(SharedPtr<const GraphObject> patch,
// If the patch has no doap:name (required by LV2), use the symbol
if (patch->properties().find(uris.doap_name) == patch->properties().end())
_model->add_statement(patch_id,
- Sord::URI(world, uris.doap_name.str()),
+ Sord::URI(world, uris.doap_name),
Sord::Literal(world, symbol.c_str()));
const GraphObject::Properties props = patch->properties(Resource::INTERNAL);
@@ -395,7 +395,7 @@ Serialiser::Impl::serialise_patch(SharedPtr<const GraphObject> patch,
} else if (n->second->graph_type() == GraphObject::NODE) {
SharedPtr<const GraphObject> node = n->second;
- const Sord::URI class_id(world, node->plugin()->uri().str());
+ const Sord::URI class_id(world, node->plugin()->uri());
const Sord::Node node_id(path_rdf_node(n->second->path()));
_model->add_statement(patch_id,
Sord::Curie(world, "ingen:node"),
@@ -409,8 +409,8 @@ Serialiser::Impl::serialise_patch(SharedPtr<const GraphObject> patch,
const Sord::Node port_id = path_rdf_node(p->path());
// Ensure lv2:name always exists so Patch is a valid LV2 plugin
- if (p->properties().find(LV2_CORE__name) == p->properties().end())
- p->set_property(LV2_CORE__name,
+ if (p->properties().find(uris.lv2_name) == p->properties().end())
+ p->set_property(uris.lv2_name,
_world.forge().alloc(p->symbol().c_str()));
_model->add_statement(patch_id,
@@ -537,7 +537,7 @@ Serialiser::Impl::serialise_properties(Sord::Node id,
typedef GraphObject::Properties::const_iterator iterator;
for (iterator v = props.begin(); v != props.end(); ++v) {
- const Sord::URI key(_model->world(), v->first.str());
+ const Sord::URI key(_model->world(), v->first);
if (!skip_property(key)) {
sratom_write(_sratom, unmap, 0,
sord_node_to_serd_node(id.c_obj()),