diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-27 01:39:19 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-27 01:39:19 +0100 |
commit | 84f0004cdf45f6fbad6461676897aa27f03cbb93 (patch) | |
tree | acb15536b40d7389c3c65df1567084bb57da416e /src/core/parser | |
parent | 495e2de57e587450e9532c7fe4ae0c2bfb196e6c (diff) |
Removed dependency between "Project" model class and parser/resources. This reduces coupling and was stupid beforehand.
Diffstat (limited to 'src/core/parser')
-rw-r--r-- | src/core/parser/ParserContext.cpp | 39 | ||||
-rw-r--r-- | src/core/parser/ParserContext.hpp | 108 |
2 files changed, 117 insertions, 30 deletions
diff --git a/src/core/parser/ParserContext.cpp b/src/core/parser/ParserContext.cpp index 0a75fdf..b0d04d4 100644 --- a/src/core/parser/ParserContext.cpp +++ b/src/core/parser/ParserContext.cpp @@ -16,32 +16,55 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <core/resource/ResourceManager.hpp> +#include <core/Registry.hpp> + +#include "ParserScope.hpp" #include "ParserContext.hpp" namespace ousia { /* Class ParserContext */ -ParserContext::ParserContext(Handle<Project> project, ParserScope &scope, - SourceId sourceId, Logger &logger) - : project(project), scope(scope), sourceId(sourceId), logger(logger) +ParserContext::ParserContext(Registry ®istry, + ResourceManager &resourceManager, + ParserScope &scope, Handle<Project> project, + Logger &logger, SourceId sourceId) + : registry(registry), + resourceManager(resourceManager), + scope(scope), + project(project), + logger(logger), + sourceId(sourceId) +{ +} + +Rooted<Node> ParserContext::link(const std::string &path, + const std::string mimetype, + const std::string rel, + const RttiSet &supportedTypes) { + return resourceManager.link(*this, path, mimetype, rel, supportedTypes); } -ParserContext::ParserContext(Handle<Project> project, ParserScope &scope, - Logger &logger) - : project(project), scope(scope), sourceId(InvalidSourceId), logger(logger) +Rooted<Node> ParserContext::include(const std::string &path, + const std::string mimetype, + const std::string rel, + const RttiSet &supportedTypes) { + return resourceManager.include(*this, path, mimetype, rel, supportedTypes); } ParserContext ParserContext::clone(ParserScope &scope, SourceId sourceId) const { - return ParserContext{project, scope, sourceId, logger}; + return ParserContext{registry, resourceManager, scope, + project, logger, sourceId}; } ParserContext ParserContext::clone(SourceId sourceId) const { - return ParserContext{project, scope, sourceId, logger}; + return ParserContext{registry, resourceManager, scope, + project, logger, sourceId}; } Manager &ParserContext::getManager() const { return project->getManager(); } diff --git a/src/core/parser/ParserContext.hpp b/src/core/parser/ParserContext.hpp index e36c0d9..f422e10 100644 --- a/src/core/parser/ParserContext.hpp +++ b/src/core/parser/ParserContext.hpp @@ -29,7 +29,7 @@ #define _OUSIA_PARSER_CONTEXT_HPP_ #include <core/common/Location.hpp> -#include <core/managed/Managed.hpp> +#include <core/common/Rtti.hpp> #include <core/model/Project.hpp> namespace ousia { @@ -37,6 +37,8 @@ namespace ousia { // Forward declaration class Logger; class ParserScope; +class Registry; +class ResourceManager; /** * Class containing the objects that are passed to a parser instance. @@ -44,9 +46,14 @@ class ParserScope; class ParserContext { private: /** - * Project instance into which the new content should be parsed. + * Reference at the internally used Registry instance. */ - Rooted<Project> project; + Registry ®istry; + + /** + * ResourceManager used to manage all resources used by the project. + */ + ResourceManager &resourceManager; /** * Reference to the ParserScope instance that should be used within the @@ -55,42 +62,83 @@ private: ParserScope &scope; /** - * SourceId is the ID of the resource that is currently being processed. + * Project instance into which the new content should be parsed. */ - SourceId sourceId; + Rooted<Project> project; /** * Reference to the Logger the parser should log any messages to. */ Logger &logger; + /** + * SourceId is the ID of the resource that is currently being processed. + */ + SourceId sourceId; + public: /** * Constructor of the ParserContext class. * - * @param project is the project into which the content should be parsed. + * @param registry is the registry instance that should be used for locating + * files and finding parsers for these files. + * @param resourceManager is a reference at the ResourceManager which + * manages the inclusion of source files. * @param scope is a reference to the ParserScope instance that should be * used to lookup names. - * @param sourceId is a SourceId instance specifying the source the parser - * is reading from. + * @param project is the project into which the content should be parsed. * @param logger is a reference to the Logger instance that should be used * to log error messages and warnings that occur while parsing the document. + * @param sourceId is a SourceId instance specifying the source the parser + * is reading from. */ - ParserContext(Handle<Project> project, ParserScope &scope, - SourceId sourceId, Logger &logger); + ParserContext(Registry ®istry, ResourceManager &resourceManager, + ParserScope &scope, Handle<Project> project, Logger &logger, + SourceId sourceId = InvalidSourceId); /** - * Constructor of the ParserContext class with the sourceId being set - * to the InvalidSourceId value. + * Parses a file with ParserContext and an empty ParserScope. The parsed + * object graph of files that are parsed using the "link" function is + * cached (in contrast to the "include" function). A copy of this parser + * context will be passed to the called parser, with the ParserScope + * reference stored in the "scope" variable exchanged by an empty scope. * - * @param project is the project into which the content should be parsed. - * @param scope is a reference to the ParserScope instance that should be - * used to lookup names. - * @param logger is a reference to the Logger instance that should be used - * to log error messages and warnings that occur while parsing the document. + * @param path is the path of the file that should be parsed. + * @param mimetype is the mimetype of the resource that should be parsed + * (may be empty, in which case the mimetype is deduced from the file + * extension). + * @param rel is a "relation string" supplied by the user which specifies + * the relationship of the specified resource. May be empty, in which case + * the relation is deduced from the supported types and the types of the + * parser for the given mimetype. + * @param supportedTypes contains the types of the returned Node the caller + * can deal with. Note that only the types the parser claims to return are + * checked, not the actual result. + * @return the parsed node or nullptr if something goes wrong. */ - ParserContext(Handle<Project> project, ParserScope &scope, - Logger &logger); + Rooted<Node> link(const std::string &path, const std::string mimetype, + const std::string rel, const RttiSet &supportedTypes); + + /** + * Parses a file with ParserContext and the current ParserScope. In contrast + * to the "link" function, include() does not cache the parsed node (as it + * depends on the current ParserScope). + * + * @param path is the path of the file that should be parsed. + * @param mimetype is the mimetype of the resource that should be parsed + * (may be empty, in which case the mimetype is deduced from the file + * extension). + * @param rel is a "relation string" supplied by the user which specifies + * the relationship of the specified resource. May be empty, in which case + * the relation is deduced from the supported types and the types of the + * parser for the given mimetype. + * @param supportedTypes contains the types of the returned Node the caller + * can deal with. Note that only the types the parser claims to return are + * checked, not the actual result. + * @return the parsed node or nullptr if something goes wrong. + */ + Rooted<Node> include(const std::string &path, const std::string mimetype, + const std::string rel, const RttiSet &supportedTypes); /** * Clones the ParserContext instance but exchanges the ParserScope instance @@ -111,11 +159,20 @@ public: ParserContext clone(SourceId sourceId) const; /** - * Returns a handle pointing at the Project node. + * Returns a reference pointing at the Registry used within this parser + * context. * - * @return a project node handle. + * @return a reference at the registry instance. */ - Rooted<Project> getProject() const { return project; } + Registry &getRegistry() const { return registry; } + + /** + * Returns a reference pointing at the ResourceManager used within this + * parser context. + * + * @return a reference at the ResourceManager instance. + */ + ResourceManager &getResourceManager() const { return resourceManager; } /** * Returns a reference pointing at the current ParserScope instance. @@ -126,6 +183,13 @@ public: ParserScope &getScope() const { return scope; } /** + * Returns a handle pointing at the Project node. + * + * @return a project node handle. + */ + Rooted<Project> getProject() const { return project; } + + /** * Returns a reference pointing at the current LoggerInstance. * * @return a reference at LoggerInstance to which all error messages should |