diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-21 01:17:49 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-21 01:17:49 +0100 |
commit | 6decad0b8e7e369bd8215f31a45dd3eae982d2a9 (patch) | |
tree | 96d22db47629956c554d11a9e56bc68a2fc9b40b /src/core/Registry.hpp | |
parent | 311a770805dff2cdffc1ecbfbbf0c5aae44c8878 (diff) |
Some further refactoring -- renamed Scope to ParserScope, got rid of parser namespace, added new functionality to RegistryClass, wrote documentation, added function for extracting file extensions to Utils
Diffstat (limited to 'src/core/Registry.hpp')
-rw-r--r-- | src/core/Registry.hpp | 115 |
1 files changed, 102 insertions, 13 deletions
diff --git a/src/core/Registry.hpp b/src/core/Registry.hpp index 40eede1..965f336 100644 --- a/src/core/Registry.hpp +++ b/src/core/Registry.hpp @@ -16,37 +16,126 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +/** + * @file Registry.hpp + * + * Class used for registering plugin classes. The Registry is one of the central + * classes needed for parsing and transforming an Ousía document. + * + * @author Andreas Stöckel (astoecke@techfak.uni-bielefeld.de) + */ + #ifndef _OUSIA_REGISTRY_HPP_ #define _OUSIA_REGISTRY_HPP_ #include <map> +#include <set> #include <vector> +#include <core/common/Rtti.hpp> #include <core/resource/Resource.hpp> namespace ousia { -// TODO: Add support for ScriptEngine type - -namespace parser { +// Forward declarations class Parser; -} class ResourceLocator; +/** + * The Registry class is the central class which is used to store references to + * all available plugins. + */ class Registry { private: - std::vector<parser::Parser *> parsers; - std::map<std::string, parser::Parser *> parserMimetypes; - + /** + * Mapping between parser mimetypes and pairs of parsers and their supported + * Rtti types. + */ + std::map<std::string, std::pair<Parser *, RttiSet>> parsers; + + /** + * Map from file extensions to registered mimetypes. + */ + std::map<std::string, std::string> extensions; + + /** + * List containing all registered ResourceLocator instances. + */ std::vector<ResourceLocator *> locators; public: - void registerParser(parser::Parser &parser); - - parser::Parser *getParserForMimetype(const std::string &mimetype) const; - - void registerResourceLocator(ResourceLocator &locator); - + /** + * Registers a new parser instance for the given set of mimetypes. Throws + * an exception if a parser is already registered for one of the mimetypes. + * + * @param mimetypes is a set of mimetypes for which the Parser should be + * registered. + * @param types is a set of node the parser is known to return. This + * information is needed in order to prevent inclusion of the wrong Node + * types + * @param parser is the parser instance that is registered for the given + * mimetypes. + */ + void registerParser(const std::set<std::string> &mimetypes, + const RttiSet &types, Parser *parser); + + /** + * Returns a pointer pointing at a Parser that was registered for handling + * the given mimetype. + * + * @param mimetype is the mimetype for which a Parser instance should be + * looked up. + * @return a pair containing a pointer at the parser and the RttiTypes + * supported by the parser. The pointer is set to a nullptr if no such + * parser could be found. + */ + const std::pair<Parser *, RttiSet> &getParserForMimetype( + const std::string &mimetype) const; + + /** + * Registers a file extension with a certain mimetype. Throws an exception + * if a mimetype is already registered for this extension. + * + * @param extension is the file extension for which the mimetype should be + * registered. The extension has to be provided without a leading dot. The + * extensions are handled case insensitive. + * @param mimetype is the mimetype that should be registered for the + * extension. + */ + void registerExtension(const std::string &extension, + const std::string &mimetype); + + /** + * Returns the mimetype for the given extension. + * + * @param extension is the file extension for which the mimetype should be + * looked up. The extension has to be provided without a leading dot. The + * extensions are handled case insensitive. + * @return the registered mimetype or an empty string of none was found. + */ + std::string getMimetypeForExtension(const std::string &extension) const; + + /** + * Registers a ResourceLocator instance that should be used for locating + * resources. Two registered ResourceLocator should not be capable of + * accessing Resources at the same location. If this happens, the resource + * locator that was registered first has precedence. + * + * @param locator is the ResourceLocator instance that should be registered. + */ + void registerResourceLocator(ResourceLocator *locator); + + /** + * Locates a resource using the registered ResourceLocator instances. + * + * @param resource is the resource descriptor to which the result will be + * written. + * @param path is the path under which the resource should be looked up. + * @param type is the ResourceType. Specifying a resource type may help to + * locate the resource. + * @param relativeTo is another resource relative to which the resource may + * be looked up. + */ bool locateResource(Resource &resource, const std::string &path, ResourceType type = ResourceType::UNKNOWN, const Resource &relativeTo = NullResource) const; |