diff options
Diffstat (limited to 'src/Parser.cpp')
-rw-r--r-- | src/Parser.cpp | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/src/Parser.cpp b/src/Parser.cpp index 58801dba..c03f0abf 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -14,38 +14,39 @@ along with Ingen. If not, see <http://www.gnu.org/licenses/>. */ -#include "ingen/Parser.hpp" - -#include "ingen/Atom.hpp" -#include "ingen/AtomForge.hpp" -#include "ingen/Forge.hpp" -#include "ingen/Interface.hpp" -#include "ingen/Log.hpp" -#include "ingen/Properties.hpp" -#include "ingen/Resource.hpp" -#include "ingen/URI.hpp" -#include "ingen/URIMap.hpp" -#include "ingen/URIs.hpp" -#include "ingen/World.hpp" -#include "ingen/paths.hpp" -#include "lv2/atom/atom.h" -#include "lv2/core/lv2.h" -#include "raul/Path.hpp" -#include "raul/Symbol.hpp" -#include "serd/serd.h" -#include "sord/sord.h" -#include "sord/sordmm.hpp" - +#include <ingen/Parser.hpp> + +#include <ingen/Atom.hpp> +#include <ingen/AtomForge.hpp> +#include <ingen/FilePath.hpp> +#include <ingen/Forge.hpp> +#include <ingen/Interface.hpp> +#include <ingen/Log.hpp> +#include <ingen/Properties.hpp> +#include <ingen/Resource.hpp> +#include <ingen/URI.hpp> +#include <ingen/URIMap.hpp> +#include <ingen/URIs.hpp> +#include <ingen/World.hpp> +#include <ingen/ingen.h> +#include <ingen/paths.hpp> +#include <lv2/atom/atom.h> +#include <lv2/core/lv2.h> +#include <raul/Path.hpp> +#include <raul/Symbol.hpp> +#include <serd/serd.h> +#include <sord/sord.h> +#include <sord/sordmm.hpp> + +#include <algorithm> #include <cassert> #include <cstdint> #include <cstring> #include <filesystem> #include <map> #include <set> -#include <sstream> #include <string> #include <string_view> -#include <type_traits> #include <utility> #define NS_RDF "http://www.w3.org/1999/02/22-rdf-syntax-ns#" @@ -91,7 +92,7 @@ Parser::find_resources(Sord::World& world, static std::optional<raul::Path> get_path(const URI& base, const URI& uri) { - const URI relative = uri.make_relative(base); + const URI relative = uri.make_relative(base, base); const std::string uri_str = "/" + relative.string(); return raul::Path::is_valid(uri_str) ? raul::Path(uri_str) : std::optional<raul::Path>(); @@ -284,8 +285,8 @@ parse_block(ingen::World& world, serd_uri_parse(reinterpret_cast<const uint8_t*>(base_uri.c_str()), &base_uri_parts); - SerdURI ignored; - SerdNode sub_uri = + SerdURI ignored; + const SerdNode sub_uri = serd_node_new_uri_from_string(type_uri, &base_uri_parts, &ignored); const std::string sub_uri_str = @@ -300,7 +301,7 @@ parse_block(ingen::World& world, sub_model.load_file(env, SERD_TURTLE, sub_file); serd_env_free(env); - Sord::URI sub_node(*world.rdf_world(), sub_file); + const Sord::URI sub_node{*world.rdf_world(), sub_file}; parse_graph(world, target, sub_model, @@ -358,7 +359,7 @@ parse_graph(ingen::World& world, } // Create graph - Properties props = get_properties(world, model, subject, ctx, data); + const Properties props = get_properties(world, model, subject, ctx, data); target.put(path_to_uri(graph_path), props, ctx); // For each port on this graph @@ -397,8 +398,8 @@ parse_graph(ingen::World& world, // For each block in this graph for (auto n = model.find(subject, ingen_block, nil); !n.end(); ++n) { - Sord::Node node = n.get_object(); - URI node_uri = node; + const Sord::Node node = n.get_object(); + const URI node_uri = node; assert(!node_uri.path().empty() && node_uri.path() != "/"); const raul::Path block_path = graph_path.child( raul::Symbol(FilePath(node_uri.path()).stem().string())); @@ -583,19 +584,19 @@ parse(ingen::World& world, symbol, data); } else if (types.find(block_class) != types.end()) { - const raul::Path rel_path(*get_path(base_uri, s)); + const raul::Path rel_path{*get_path(base_uri, s)}; const raul::Path path = parent ? parent->child(rel_path) : rel_path; ret = parse_block(world, target, model, base_uri, s, path, data); } else if (types.find(in_port_class) != types.end() || types.find(out_port_class) != types.end()) { - const raul::Path rel_path(*get_path(base_uri, s)); + const raul::Path rel_path{*get_path(base_uri, s)}; const raul::Path path = parent ? parent->child(rel_path) : rel_path; const Properties properties = get_properties(world, model, s, Resource::Graph::DEFAULT, data); target.put(path_to_uri(path), properties); ret = path; } else if (types.find(arc_class) != types.end()) { - raul::Path parent_path(parent ? parent.value() : raul::Path("/")); + const raul::Path parent_path{parent ? parent.value() : raul::Path("/")}; parse_arc(world, target, model, base_uri, s, parent_path); } else { world.log().error("Subject has no known types\n"); @@ -624,7 +625,7 @@ Parser::parse_file(ingen::World& world, const FilePath manifest_path = (is_bundle ? file_path / "manifest.ttl" : file_path); - URI manifest_uri(manifest_path); + const URI manifest_uri{manifest_path}; // Find graphs in manifest const std::set<ResourceRecord> resources = @@ -635,19 +636,18 @@ Parser::parse_file(ingen::World& world, return false; } - /* Choose the graph to load. If this is a manifest, then there should only - be one, but if this is a graph file, subgraphs will be returned as well. - In this case, choose the one with the file URI. */ - URI uri; - for (const ResourceRecord& r : resources) { - if (r.uri == URI(manifest_path)) { - uri = r.uri; - file_path = r.filename; - break; - } - } + // Try to find the graph with the manifest path for a URI + const auto m = std::find_if(resources.begin(), + resources.end(), + [manifest_path](const auto& r) { + return r.uri == URI(manifest_path); + }); - if (uri.empty()) { + URI uri; + if (m != resources.end()) { + uri = m->uri; + file_path = m->filename; + } else { // Didn't find a graph with the same URI as the file, use the first uri = (*resources.begin()).uri; file_path = (*resources.begin()).filename; @@ -659,10 +659,10 @@ Parser::parse_file(ingen::World& world, } // Initialise parsing environment - const URI file_uri = URI(file_path); - const auto* uri_c_str = reinterpret_cast<const uint8_t*>(uri.c_str()); - SerdNode base_node = serd_node_from_string(SERD_URI, uri_c_str); - SerdEnv* env = serd_env_new(&base_node); + const URI file_uri = URI(file_path); + const auto* uri_c_str = reinterpret_cast<const uint8_t*>(uri.c_str()); + const SerdNode base_node = serd_node_from_string(SERD_URI, uri_c_str); + SerdEnv* env = serd_env_new(&base_node); // Load graph into model Sord::Model model(*world.rdf_world(), |