diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-29 22:52:29 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-29 22:52:29 +0100 |
commit | 90b2e9507e9d720452792b863b422221fe96d948 (patch) | |
tree | 407a271de4730d087de4132eab3921c44c65e400 /src/core/parser | |
parent | de0891c69166f6988e0b13137f9bf2b7b67449f2 (diff) |
Unified signature of resolve functions, passing the "owner" to the callback functions in ParserScope::resolve
Diffstat (limited to 'src/core/parser')
-rw-r--r-- | src/core/parser/ParserScope.cpp | 35 | ||||
-rw-r--r-- | src/core/parser/ParserScope.hpp | 89 |
2 files changed, 58 insertions, 66 deletions
diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp index 0de0dbf..b76bb28 100644 --- a/src/core/parser/ParserScope.cpp +++ b/src/core/parser/ParserScope.cpp @@ -31,12 +31,13 @@ ParserScopeBase::ParserScopeBase(const NodeVector<Node> &nodes) : nodes(nodes) { } -Rooted<Node> ParserScopeBase::resolve(const std::vector<std::string> &path, - const Rtti &type, Logger &logger) +Rooted<Node> ParserScopeBase::resolve(const Rtti &type, + const std::vector<std::string> &path, + Logger &logger) { // Go up the stack and try to resolve the for (auto it = nodes.rbegin(); it != nodes.rend(); it++) { - std::vector<ResolutionResult> res = (*it)->resolve(path, type); + std::vector<ResolutionResult> res = (*it)->resolve(type, path); // Abort if the object could not be resolved if (res.empty()) { @@ -79,14 +80,14 @@ bool DeferredResolution::resolve( // Fork the logger to prevent error messages from being shown if we actively // ignore the resolution result LoggerFork loggerFork = logger.fork(); - Rooted<Node> res = scope.resolve(path, type, loggerFork); + Rooted<Node> res = scope.resolve(type, path, loggerFork); if (res != nullptr) { if (!ignore.count(res.get())) { loggerFork.commit(); try { // Push the location onto the logger default location stack GuardedLogger loggerGuard(logger, *owner); - resultCallback(res, logger); + resultCallback(res, owner, logger); } catch (LoggableException ex) { logger.log(ex); @@ -227,29 +228,29 @@ bool ParserScope::getFlag(ParserFlag flag) return false; } -bool ParserScope::resolve(const std::vector<std::string> &path, - const Rtti &type, Logger &logger, +bool ParserScope::resolve(const Rtti &type, + const std::vector<std::string> &path, + Handle<Node> owner, Logger &logger, ResolutionImposterCallback imposterCallback, - ResolutionResultCallback resultCallback, - Handle<Node> owner) + ResolutionResultCallback resultCallback) { - if (!resolve(path, type, logger, resultCallback, owner)) { - resultCallback(imposterCallback(), logger); + if (!resolve(type, path, owner, logger, resultCallback)) { + resultCallback(imposterCallback(), owner, logger); return false; } return true; } -bool ParserScope::resolve(const std::vector<std::string> &path, - const Rtti &type, Logger &logger, - ResolutionResultCallback resultCallback, - Handle<Node> owner) +bool ParserScope::resolve(const Rtti &type, + const std::vector<std::string> &path, + Handle<Node> owner, Logger &logger, + ResolutionResultCallback resultCallback) { // Try to directly resolve the node - Rooted<Node> res = ParserScopeBase::resolve(path, type, logger); + Rooted<Node> res = ParserScopeBase::resolve(type, path, logger); if (res != nullptr && !awaitingResolution.count(res.get())) { try { - resultCallback(res, logger); + resultCallback(res, owner, logger); } catch (LoggableException ex) { logger.log(ex, *owner); diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp index 2378967..e01acfe 100644 --- a/src/core/parser/ParserScope.hpp +++ b/src/core/parser/ParserScope.hpp @@ -50,14 +50,18 @@ class ParserScope; * Callback function type used for creating a dummy object while no correct * object is available for resolution. */ -using ResolutionImposterCallback = std::function<Rooted<Node>()>; +using ResolutionImposterCallback = Rooted<Node>(*)(); /** * Callback function type called whenever the result of a resolution is * available. + * + * @param resolved is the new, resolved node. + * @param owner is the node that was passed as "owner". + * @param logger is the logger to which errors should be logged. */ -using ResolutionResultCallback = - std::function<void(Handle<Node>, Logger &logger)>; +using ResolutionResultCallback = void (*)(Handle<Node> resolved, + Handle<Node> owner, Logger &logger); /** * Base class for the @@ -90,14 +94,14 @@ public: * Tries to resolve a node for the given type and path for all nodes that * are currently in the stack, starting with the topmost node on the stack. * - * @param path is the path for which a node should be resolved. * @param type is the type of the node that should be resolved. + * @param path is the path for which a node should be resolved. * @param logger is the logger instance into which resolution problems * should be logged. * @return a reference at a resolved node or nullptr if no node could be * found. */ - Rooted<Node> resolve(const std::vector<std::string> &path, const Rtti &type, + Rooted<Node> resolve(const Rtti &type, const std::vector<std::string> &path, Logger &logger); }; @@ -396,8 +400,9 @@ public: * temporary) and another time if the resolution turned out to be * successful at a later point in time. * - * @param path is the path for which a node should be resolved. * @param type is the type of the node that should be resolved. + * @param path is the path for which a node should be resolved. + * @param owner is the node for which the resolution takes place. * @param logger is the logger instance into which resolution problems * should be logged. * @param imposterCallback is the callback function that is called if @@ -410,15 +415,14 @@ public: * the resolved object directly when this function is called. If the * resolution was not successful the first time, it may be called another * time later in the context of the "performDeferredResolution" function. - * @param owner is the node for which the resolution takes place. * @return true if the resolution was immediately successful. This does * not mean, that the resolved object does not exist, as it may be resolved * later. */ - bool resolve(const std::vector<std::string> &path, const Rtti &type, - Logger &logger, ResolutionImposterCallback imposterCallback, - ResolutionResultCallback resultCallback, - Handle<Node> owner = nullptr); + bool resolve(const Rtti &type, const std::vector<std::string> &path, + Handle<Node> owner, Logger &logger, + ResolutionImposterCallback imposterCallback, + ResolutionResultCallback resultCallback); /** * Tries to resolve a node for the given type and path for all nodes @@ -426,21 +430,21 @@ public: * The "resultCallback" is called when the resolution was successful, which * may be at a later point in time. * - * @param path is the path for which a node should be resolved. * @param type is the type of the node that should be resolved. + * @param path is the path for which a node should be resolved. + * @param owner is the node for which the resolution takes place. * @param logger is the logger instance into which resolution problems * should be logged. * @param resultCallback is the callback function to which the result of * the resolution process is passed. This function is called once the * resolution was successful. - * @param owner is the node for which the resolution takes place. * @return true if the resolution was immediately successful. This does not * mean, that the resolved object does not exist, as it may be resolved * later. */ - bool resolve(const std::vector<std::string> &path, const Rtti &type, - Logger &logger, ResolutionResultCallback resultCallback, - Handle<Node> owner = nullptr); + bool resolve(const Rtti &type, const std::vector<std::string> &path, + Handle<Node> owner, Logger &logger, + ResolutionResultCallback resultCallback); /** * Tries to resolve a node for the given type and path for all nodes @@ -453,6 +457,7 @@ public: * * @tparam T is the type of the node that should be resolved. * @param path is the path for which a node should be resolved. + * @param owner is the node for which the resolution takes place. * @param logger is the logger instance into which resolution problems * should be logged. * @param imposterCallback is the callback function that is called if @@ -465,24 +470,17 @@ public: * resolved object directly when this function is called. If the resolution * was not successful the first time, it may be called another time later * in the context of the "performDeferredResolution" function. - * @param owner is the node for which the resolution takes place. * @return true if the resolution was immediately successful. This does not * mean, that the resolved object does not exist, as it may be resolved * later. */ template <class T> - bool resolve(const std::vector<std::string> &path, Logger &logger, - std::function<Rooted<T>()> imposterCallback, - std::function<void(Handle<T>, Logger &)> resultCallback, - Handle<Node> owner = nullptr) + bool resolve(const std::vector<std::string> &path, Handle<Node> owner, + Logger &logger, ResolutionImposterCallback imposterCallback, + ResolutionResultCallback resultCallback) { - return resolve( - path, typeOf<T>(), logger, - [imposterCallback]() -> Rooted<Node> { return imposterCallback(); }, - [resultCallback](Handle<Node> node, Logger &logger) { - resultCallback(node.cast<T>(), logger); - }, - owner); + return resolve(typeOf<T>(), path, owner, logger, imposterCallback, + resultCallback); } /** @@ -493,26 +491,21 @@ public: * * @tparam T is the type of the node that should be resolved. * @param path is the path for which a node should be resolved. + * @param owner is the node for which the resolution takes place. * @param logger is the logger instance into which resolution problems * should be logged. * @param resultCallback is the callback function to which the result of * the resolution process is passed. This function is called once the * resolution was successful. - * @param owner is the node for which the resolution takes place. * @return true if the resolution was immediately successful. This does not * mean, that the resolved object does not exist, as it may be resolved * later. */ template <class T> - bool resolve(const std::vector<std::string> &path, Logger &logger, - std::function<void(Handle<T>, Logger &)> resultCallback, - Handle<Node> owner = nullptr) + bool resolve(const std::vector<std::string> &path, Handle<Node> owner, + Logger &logger, ResolutionResultCallback resultCallback) { - return resolve(path, typeOf<T>(), logger, - [resultCallback](Handle<Node> node, Logger &logger) { - resultCallback(node.cast<T>(), logger); - }, - owner); + return resolve(typeOf<T>(), path, owner, logger, resultCallback); } /** @@ -527,6 +520,7 @@ public: * @tparam T is the type of the node that should be resolved. * @param name is the path for which a node should be resolved. The name is * split at '.' to form a path. + * @param owner is the node for which the resolution takes place. * @param logger is the logger instance into which resolution problems * should be logged. * @param imposterCallback is the callback function that is called if @@ -539,19 +533,17 @@ public: * resolved object directly when this function is called. If the resolution * was not successful the first time, it may be called another time later * in the context of the "performDeferredResolution" function. - * @param owner is the node for which the resolution takes place. * @return true if the resolution was immediately successful. This does not * mean, that the resolved object does not exist, as it may be resolved * later. */ template <class T> - bool resolve(const std::string &name, Logger &logger, - std::function<Rooted<T>()> imposterCallback, - std::function<void(Handle<T>, Logger &)> resultCallback, - Handle<Node> owner = nullptr) + bool resolve(const std::string &name, Handle<Node> owner, Logger &logger, + ResolutionImposterCallback imposterCallback, + ResolutionResultCallback resultCallback) { - return resolve<T>(Utils::split(name, '.'), logger, imposterCallback, - resultCallback, owner); + return resolve<T>(Utils::split(name, '.'), owner, logger, + imposterCallback, resultCallback); } /** @@ -574,12 +566,11 @@ public: * later. */ template <class T> - bool resolve(const std::string &name, Logger &logger, - std::function<void(Handle<T>, Logger &)> resultCallback, - Handle<Node> owner = nullptr) + bool resolve(const std::string &name, Handle<Node> owner, Logger &logger, + ResolutionResultCallback resultCallback) { - return resolve<T>(Utils::split(name, '.'), logger, resultCallback, - owner); + return resolve<T>(Utils::split(name, '.'), owner, logger, + resultCallback); } /** |