summaryrefslogtreecommitdiff
path: root/src/plugins/boost/FileLocator.cpp
diff options
context:
space:
mode:
authorBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2014-12-11 18:45:21 +0100
committerBenjamin Paassen <bpaassen@techfak.uni-bielefeld.de>2014-12-11 18:45:21 +0100
commit3d1e59ff0b3116255b70f6247137009903cd530b (patch)
treebf59e2c22b8000729161db5b4f8db7254e48bf1d /src/plugins/boost/FileLocator.cpp
parent0e2d827e5c0b47e3c8604e94b773f31dcd448ff1 (diff)
finished FileLocator implementation and tests for it.
Diffstat (limited to 'src/plugins/boost/FileLocator.cpp')
-rw-r--r--src/plugins/boost/FileLocator.cpp27
1 files changed, 24 insertions, 3 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);
}
}