diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-15 00:29:11 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-15 00:29:11 +0100 |
commit | e99a307bf76689e4e86f8ac1a4c545bcebbdb7ab (patch) | |
tree | b0365ed915763418dbe35485ad74ceb2f3649abc /src/core/parser | |
parent | f7326c640690cf5cfee89340db5569ef9b44a652 (diff) |
Using Arguments class in ParserStack for validation
Diffstat (limited to 'src/core/parser')
-rw-r--r-- | src/core/parser/ParserStack.cpp | 17 | ||||
-rw-r--r-- | src/core/parser/ParserStack.hpp | 30 |
2 files changed, 29 insertions, 18 deletions
diff --git a/src/core/parser/ParserStack.cpp b/src/core/parser/ParserStack.cpp index ff2647d..691b9d0 100644 --- a/src/core/parser/ParserStack.cpp +++ b/src/core/parser/ParserStack.cpp @@ -47,17 +47,14 @@ void Handler::child(std::shared_ptr<Handler> handler) HandlerInstance HandlerDescriptor::create(const ParserContext &ctx, std::string name, State parentState, bool isChild, - const Variant &args) const + Variant::mapType &args) const { Handler *h = ctor(ctx, name, targetState, parentState, isChild); // Canonicalize the arguments - Variant arguments = args; - if (argsType != nullptr) { - argsType->build(arguments, ctx.logger); - } + arguments.validateMap(args, ctx.logger, true); - h->start(arguments); + h->start(args); return HandlerInstance(h, this); } @@ -95,7 +92,7 @@ std::set<std::string> ParserStack::expectedCommands(State state) return res; } -void ParserStack::start(std::string name, const Variant &args) +void ParserStack::start(std::string name, Variant::mapType &args) { // Fetch the current handler and the current state const HandlerInstance *h = stack.empty() ? nullptr : &stack.top(); @@ -126,6 +123,12 @@ void ParserStack::start(std::string name, const Variant &args) stack.emplace(descr->create(ctx, name, curState, isChild, args)); } +void ParserStack::start(std::string name, const Variant::mapType &args) +{ + Variant::mapType argsCopy(args); + start(name, argsCopy); +} + void ParserStack::end() { // Check whether the current command could be ended diff --git a/src/core/parser/ParserStack.hpp b/src/core/parser/ParserStack.hpp index 93180b4..7602139 100644 --- a/src/core/parser/ParserStack.hpp +++ b/src/core/parser/ParserStack.hpp @@ -39,7 +39,7 @@ #include <core/common/Variant.hpp> #include <core/common/Logger.hpp> -#include <core/model/Typesystem.hpp> +#include <core/common/Argument.hpp> #include "Parser.hpp" @@ -128,7 +128,7 @@ public: * * @param args is a map from strings to variants (argument name and value). */ - virtual void start(const Variant &args) = 0; + virtual void start(const Variant::mapType &args) = 0; /** * Called whenever the command for which this handler is defined ends. @@ -212,10 +212,10 @@ struct HandlerDescriptor { const bool arbitraryChildren; /** - * Pointer pointing at a StructType describing the layout of the given when - * a new Handler instance is instantiated. + * Reference at an argument descriptor that should be used for validating + * the incomming arguments. */ - const Rooted<model::StructType> argsType; + const Arguments arguments; /** * Constructor of the HandlerDescriptor class. @@ -228,17 +228,17 @@ struct HandlerDescriptor { * instantiating an in instance of the described Handler instances. * @param arbitraryChildren allows the Handler instance to handle any child * node. - * @param argsType is a struct type describing the arguments that can be - * passed to the Handler or nullptr if no check should be performed. + * @param arguments is an optional argument descriptor used for validating + * the arguments that are passed to the instantiation of a handler function. */ HandlerDescriptor(std::set<State> parentStates, HandlerConstructor ctor, State targetState, bool arbitraryChildren = false, - Handle<model::StructType> argsType = nullptr) + Arguments arguments = Arguments::None) : parentStates(std::move(parentStates)), ctor(ctor), targetState(targetState), arbitraryChildren(arbitraryChildren), - argsType(argsType) + arguments(std::move(arguments)) { } @@ -248,7 +248,7 @@ struct HandlerDescriptor { */ HandlerInstance create(const ParserContext &ctx, std::string name, State parentState, bool isChild, - const Variant &args) const; + Variant::mapType &args) const; }; /** @@ -338,7 +338,15 @@ public: * @param name is the name of the command. * @param args is a map from strings to variants (argument name and value). */ - void start(std::string name, const Variant &args); + void start(std::string name, Variant::mapType &args); + + /** + * Function that should be called whenever a new command starts. + * + * @param name is the name of the command. + * @param args is a map from strings to variants (argument name and value). + */ + void start(std::string name, const Variant::mapType &args); /** * Function called whenever a command ends. |