From 6decad0b8e7e369bd8215f31a45dd3eae982d2a9 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 21 Jan 2015 01:17:49 +0100 Subject: 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 --- src/core/Registry.hpp | 115 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 102 insertions(+), 13 deletions(-) (limited to 'src/core/Registry.hpp') 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 . */ +/** + * @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 +#include #include +#include #include 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 parsers; - std::map parserMimetypes; - + /** + * Mapping between parser mimetypes and pairs of parsers and their supported + * Rtti types. + */ + std::map> parsers; + + /** + * Map from file extensions to registered mimetypes. + */ + std::map extensions; + + /** + * List containing all registered ResourceLocator instances. + */ std::vector 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 &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 &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; -- cgit v1.2.3