From faa8c03b69464f31fb419f7e4e4c4c1bd2e6907f Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 20 Jan 2015 18:32:09 +0100 Subject: Adapted FileLocator unit tests, searching in the "UNKNOWN" ResourceType search paths directly in ResoruceLocator instead of Registry --- src/core/Registry.cpp | 10 ---------- src/core/resource/ResourceLocator.cpp | 24 ++++++++++++++++++------ 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src/core') 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 ResourceLocator::stream( @@ -50,9 +61,10 @@ std::unique_ptr 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()) { -- cgit v1.2.3