summaryrefslogtreecommitdiff
path: root/src/core/resource/ResourceLocator.cpp
diff options
context:
space:
mode:
authorAndreas Stöckel <astoecke@techfak.uni-bielefeld.de>2015-02-16 18:56:48 +0100
committerAndreas Stöckel <andreas@somweyr.de>2015-02-16 18:56:48 +0100
commitf6069914af0d47bfea343b0babb734c9fd6d432d (patch)
treec5af9664dddcbe0a18b2edbf9074325b6af4a2af /src/core/resource/ResourceLocator.cpp
parentf69518b192ba5015e7ececddbfcf3a3695487d00 (diff)
Added "autocomplete" function to ResourceLocator and Registry
Diffstat (limited to 'src/core/resource/ResourceLocator.cpp')
-rw-r--r--src/core/resource/ResourceLocator.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/core/resource/ResourceLocator.cpp b/src/core/resource/ResourceLocator.cpp
index b19542e..da38cbd 100644
--- a/src/core/resource/ResourceLocator.cpp
+++ b/src/core/resource/ResourceLocator.cpp
@@ -25,6 +25,37 @@ namespace ousia {
/* Class ResourceLocator */
+std::vector<std::string> ResourceLocator::autocomplete(
+ 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 autocomplete(path, type, relativeTo.getLocation());
+ }
+ return autocomplete(path, type, "");
+}
+
+std::vector<std::string> ResourceLocator::autocomplete(
+ const std::string &path, const ResourceType type,
+ const std::string &relativeTo) const
+{
+ // Try to locate the resource for the specified type, if not found, use
+ // the "UNKNOWN" type.
+ std::vector<std::string> res = doAutocomplete(path, type, relativeTo);
+ if (!res.empty()) {
+ return res;
+ }
+
+ // Use the "UNKNOWN" type
+ if (type != ResourceType::UNKNOWN) {
+ return doAutocomplete(path, ResourceType::UNKNOWN, relativeTo);
+ }
+ return std::vector<std::string>{};
+}
+
bool ResourceLocator::locate(Resource &resource, const std::string &path,
const ResourceType type,
const Resource &relativeTo) const
@@ -59,6 +90,14 @@ std::unique_ptr<std::istream> ResourceLocator::stream(
return doStream(location);
}
+std::vector<std::string> ResourceLocator::doAutocomplete(
+ const std::string &path, const ResourceType type,
+ const std::string &relativeTo) const
+{
+ // Default implementation
+ return std::vector<std::string>{};
+}
+
/* Class StaticResourceLocator */
bool StaticResourceLocator::doLocate(Resource &resource,