summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-20 18:32:09 +0100
committerAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-01-20 18:32:09 +0100
commitfaa8c03b69464f31fb419f7e4e4c4c1bd2e6907f (patch)
tree94dd1b59a5c8c1bceb68dc545a72d0952d6f1502 /src/core
parent8755bbe309d2f00c7bc73a6a6304ed8860a9a94d (diff)
Adapted FileLocator unit tests, searching in the "UNKNOWN" ResourceType search paths directly in ResoruceLocator instead of Registry
Diffstat (limited to 'src/core')
-rw-r--r--src/core/Registry.cpp10
-rw-r--r--src/core/resource/ResourceLocator.cpp24
2 files changed, 18 insertions, 16 deletions
diff --git a/src/core/Registry.cpp b/src/core/Registry.cpp
index 9427aed..86665a2 100644
--- a/src/core/Registry.cpp
+++ b/src/core/Registry.cpp
@@ -70,16 +70,6 @@ bool Registry::locateResource(Resource &resource, const std::string &path,
}
}
- // If this did not work out, retry but use the UNKNOWN type.
- if (type != ResourceType::UNKNOWN) {
- for (auto &locator : locators) {
- if (locator->locate(resource, path, ResourceType::UNKNOWN,
- relativeTo)) {
- return true;
- }
- }
- }
-
return false;
}
}
diff --git a/src/core/resource/ResourceLocator.cpp b/src/core/resource/ResourceLocator.cpp
index 1b8490d..b19542e 100644
--- a/src/core/resource/ResourceLocator.cpp
+++ b/src/core/resource/ResourceLocator.cpp
@@ -29,17 +29,28 @@ bool ResourceLocator::locate(Resource &resource, const std::string &path,
const ResourceType type,
const Resource &relativeTo) const
{
+ // If the locator of the given relative resource is this locator instance,
+ // use the location specified in the resource, otherwise just use no
+ // "relativeTo" path.
if (&relativeTo.getLocator() == this) {
- return doLocate(resource, path, type, relativeTo.getLocation());
+ return locate(resource, path, type, relativeTo.getLocation());
}
- return doLocate(resource, path, type, "");
+ return locate(resource, path, type, "");
}
bool ResourceLocator::locate(Resource &resource, const std::string &path,
const ResourceType type,
const std::string &relativeTo) const
{
- return doLocate(resource, path, type, relativeTo);
+ // Try to locate the resource for the specified type, if not found, use
+ // the "UNKNOWN" type.
+ if (doLocate(resource, path, type, relativeTo)) {
+ return true;
+ }
+ if (type != ResourceType::UNKNOWN) {
+ return doLocate(resource, path, ResourceType::UNKNOWN, relativeTo);
+ }
+ return false;
}
std::unique_ptr<std::istream> ResourceLocator::stream(
@@ -50,9 +61,10 @@ std::unique_ptr<std::istream> ResourceLocator::stream(
/* Class StaticResourceLocator */
-bool StaticResourceLocator::doLocate(
- Resource &resource, const std::string &path, const ResourceType type,
- const std::string &relativeTo) const
+bool StaticResourceLocator::doLocate(Resource &resource,
+ const std::string &path,
+ const ResourceType type,
+ const std::string &relativeTo) const
{
auto it = resources.find(path);
if (it != resources.end()) {