diff options
author | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-12-11 18:45:21 +0100 |
---|---|---|
committer | Benjamin Paassen <bpaassen@techfak.uni-bielefeld.de> | 2014-12-11 18:45:21 +0100 |
commit | 3d1e59ff0b3116255b70f6247137009903cd530b (patch) | |
tree | bf59e2c22b8000729161db5b4f8db7254e48bf1d /src | |
parent | 0e2d827e5c0b47e3c8604e94b773f31dcd448ff1 (diff) |
finished FileLocator implementation and tests for it.
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/boost/FileLocator.cpp | 27 | ||||
-rw-r--r-- | src/plugins/boost/FileLocator.hpp | 2 |
2 files changed, 25 insertions, 4 deletions
diff --git a/src/plugins/boost/FileLocator.cpp b/src/plugins/boost/FileLocator.cpp index fdbe4d6..ed9d0c9 100644 --- a/src/plugins/boost/FileLocator.cpp +++ b/src/plugins/boost/FileLocator.cpp @@ -41,7 +41,29 @@ ResourceLocator::Location FileLocator::locate(const std::string &path, const std::string &relativeTo, const Type type) const { - // TODO: Implement Properly + boost::filesystem::path base(relativeTo); + // use the / operator to append the path. + base /= path; + // if we already found a fitting resource there, use that. + if (boost::filesystem::exists(base)) { + std::string location = + boost::filesystem::canonical(base).generic_string(); + return ResourceLocator::Location(true, *this, type, location); + } + // otherwise look in the search paths. + auto it = searchPaths.find(type); + if (it != searchPaths.end()) { + for (boost::filesystem::path p : it->second) { + p /= path; + if (boost::filesystem::exists(p)) { + std::string location = + boost::filesystem::canonical(p).generic_string(); + return ResourceLocator::Location(true, *this, type, location); + } + } + } + // if we find the resource in none of the search paths we return a location. + // with the found flag set to false. ResourceLocator::Location l(false, *this, type, ""); return l; } @@ -49,8 +71,7 @@ ResourceLocator::Location FileLocator::locate(const std::string &path, std::unique_ptr<std::istream> FileLocator::stream( const std::string &location) const { - std::unique_ptr<std::istream> ifs { - new std::ifstream(location)}; + std::unique_ptr<std::istream> ifs{new std::ifstream(location)}; return std::move(ifs); } } diff --git a/src/plugins/boost/FileLocator.hpp b/src/plugins/boost/FileLocator.hpp index 41826b8..9cb705c 100644 --- a/src/plugins/boost/FileLocator.hpp +++ b/src/plugins/boost/FileLocator.hpp @@ -25,7 +25,7 @@ #include <set> #include <vector> -#include <boost/filesystem/path.hpp> +#include <boost/filesystem.hpp> namespace ousia { |