From 8755bbe309d2f00c7bc73a6a6304ed8860a9a94d Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 20 Jan 2015 17:46:41 +0100 Subject: Implemented automatic generation of default search paths --- src/plugins/filesystem/FileLocator.hpp | 51 ++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 5 deletions(-) (limited to 'src/plugins/filesystem/FileLocator.hpp') diff --git a/src/plugins/filesystem/FileLocator.hpp b/src/plugins/filesystem/FileLocator.hpp index ffe5c8f..6d3bbf0 100644 --- a/src/plugins/filesystem/FileLocator.hpp +++ b/src/plugins/filesystem/FileLocator.hpp @@ -16,6 +16,15 @@ along with this program. If not, see . */ +/** + * @file FileLocator.hpp + * + * Contains the FileLocator class which is used to locate resources and to + * canonicalize file system paths. + * + * @author Benjamin Paaßen (bpassen@techfak.uni-bielefeld.de) + */ + #ifndef _OUSIA_FILE_LOCATOR_HPP_ #define _OUSIA_FILE_LOCATOR_HPP_ @@ -39,7 +48,7 @@ namespace ousia { class FileLocator : public ResourceLocator { public: /** - * Type alias representing a Res + * Type alias representing the internal search path list. */ using SearchPaths = std::map>; @@ -49,6 +58,25 @@ private: */ SearchPaths searchPaths; + /** + * Internally used to add a search path to the given vector without + * duplications. + * + * @parm path is the path that should be added to the vector (must be + * canonicalized). + * @parm paths is the list to which the path should be added. + */ + void addPath(const std::string &path, std::vector &paths); + + /** + * Internally used to add the default search paths for various resource + * types relative to a certain parent directory. + * + * @param relativeTo is the base directory relative to which the search + * paths ought to be setup. + */ + void addDefaultSearchPaths(const std::string &relativeTo); + protected: bool doLocate(Resource &resource, const std::string &path, const ResourceType type, @@ -74,11 +102,24 @@ public: * Adds a search path. Implicitly adds the search path for the "unknown" * * @param path is a fully qualified/canonical path to a directory. - * @param types is a set of Resource Types. The FileLocator will look for - * resources of the specified types at the given path in the - * future. + * @param type is a single type for which the path should be added. + */ + void addSearchPath(const std::string &path, + ResourceType type = ResourceType::UNKNOWN); + + /** + * Adds platform-specific default search paths. These include + * (in order of their precedence): + *
    + *
  • The user application data directory (~/.local/share/ousia/ on + * UNIX)
  • + *
  • The global application data directory used for make install + * (default is /usr/local/share on UNIX)
  • + *
+ * Resource type specific subdirectories (domain, typesytem, etc.) + * are automatically added to the aforementioned paths. */ - void addSearchPath(const std::string &path); + void addDefaultSearchPaths(); /** * Returns the backing map containing all search paths for a given type. -- cgit v1.2.3