diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-15 00:14:12 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-15 00:14:12 +0100 |
commit | 22c9d5b5504c81902ccbfae386cf69351d7d0209 (patch) | |
tree | 92621add4cd725d2b2dd9f6e7723f4fd09865a34 /src/core | |
parent | 02995f1f9b5a0905ed8f79a5149f4b6375a622bf (diff) |
Commented out Callbacks in Handler, this is not implemented yet
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/parser/stack/Handler.cpp | 40 | ||||
-rw-r--r-- | src/core/parser/stack/Handler.hpp | 41 |
2 files changed, 66 insertions, 15 deletions
diff --git a/src/core/parser/stack/Handler.cpp b/src/core/parser/stack/Handler.cpp index 73084cd..54dfe3e 100644 --- a/src/core/parser/stack/Handler.cpp +++ b/src/core/parser/stack/Handler.cpp @@ -29,12 +29,12 @@ namespace parser_stack { /* Class HandlerData */ -HandlerData::HandlerData(ParserContext &ctx, Callbacks &callbacks, - std::string name, const State &state, +HandlerData::HandlerData(ParserContext &ctx, /*Callbacks &callbacks,*/ + const std::string &name, const State &state, const SourceLocation &location) : ctx(ctx), - callbacks(callbacks), - name(std::move(name)), + /*callbacks(callbacks),*/ + name(name), state(state), location(location) { @@ -42,7 +42,10 @@ HandlerData::HandlerData(ParserContext &ctx, Callbacks &callbacks, /* Class Handler */ -Handler::Handler(const HandlerData &handlerData) : handlerData(handlerData) {} +Handler::Handler(const HandlerData &handlerData) + : handlerData(handlerData), internalLogger(nullptr) +{ +} Handler::~Handler() {} @@ -52,29 +55,41 @@ ParserScope &Handler::scope() { return handlerData.ctx.getScope(); } Manager &Handler::manager() { return handlerData.ctx.getManager(); } -Logger &Handler::logger() { return handlerData.ctx.getLogger(); } +Logger &Handler::logger() +{ + if (internalLogger != nullptr) { + return *internalLogger; + } + return handlerData.ctx.getLogger(); +} -SourceLocation Handler::location() { return handlerData.location; } +const SourceLocation &Handler::location() const { return handlerData.location; } void Handler::setWhitespaceMode(WhitespaceMode whitespaceMode) { - handlerData.callbacks.setWhitespaceMode(whitespaceMode); + /*handlerData.callbacks.setWhitespaceMode(whitespaceMode);*/ } void Handler::registerToken(const std::string &token) { - handlerData.callbacks.registerToken(token); + /*handlerData.callbacks.registerToken(token);*/ } void Handler::unregisterToken(const std::string &token) { - handlerData.callbacks.unregisterToken(token); + /*handlerData.callbacks.unregisterToken(token);*/ } const std::string &Handler::getName() const { return handlerData.name; } const State &Handler::getState() const { return handlerData.state; } +void Handler::setLogger(Logger &logger) { internalLogger = &logger; } + +void Handler::resetLogger() { internalLogger = nullptr; } + +const SourceLocation &Handler::getLocation() const { return location(); } + /* Class EmptyHandler */ bool EmptyHandler::start(const Variant::mapType &args) @@ -119,6 +134,11 @@ bool EmptyHandler::data(const Variant &data) return true; } +Handler *EmptyHandler::create(const HandlerData &handlerData) +{ + return new EmptyHandler(handlerData); +} + /* Class StaticHandler */ bool StaticHandler::start(const Variant::mapType &args) diff --git a/src/core/parser/stack/Handler.hpp b/src/core/parser/stack/Handler.hpp index 8c3d8c4..eeaf555 100644 --- a/src/core/parser/stack/Handler.hpp +++ b/src/core/parser/stack/Handler.hpp @@ -23,10 +23,12 @@ #include <core/common/Location.hpp> #include <core/common/Variant.hpp> +#include <core/common/Whitespace.hpp> namespace ousia { // Forward declarations +class ParserScope; class ParserContext; class Logger; @@ -53,7 +55,7 @@ public: * modifying the behaviour of the parser (like registering tokens, setting * the data type or changing the whitespace handling mode). */ - Callbacks &callbacks; + // Callbacks &callbacks; /** * Contains the name of the command that is being handled. @@ -80,7 +82,8 @@ public: * @param state is the state this handler was called for. * @param location is the location at which the handler is created. */ - HandlerData(ParserContext &ctx, Callbacks &callbacks, std::string name, + HandlerData(ParserContext &ctx, + /*Callbacks &callbacks,*/ const std::string &name, const State &state, const SourceLocation &location); }; @@ -96,6 +99,12 @@ private: */ const HandlerData handlerData; + /** + * Reference at the current logger. If not nullptr, this will override the + * logger from the ParserContext specified in the handlerData. + */ + Logger *internalLogger; + protected: /** * Constructor of the Handler class. @@ -135,11 +144,12 @@ protected: Logger &logger(); /** - * Returns the current location in the source file. + * Returns the location of the element in the source file, for which this + * Handler was created. * - * @return the current location in the source file. + * @return the location of the Handler in the source file. */ - SourceLocation location(); + const SourceLocation &location() const; public: /** @@ -191,6 +201,27 @@ public: const State &getState() const; /** + * Sets the internal logger to the given logger instance. + * + * @param logger is the Logger instance to which the logger should be set. + */ + void setLogger(Logger &logger); + + /** + * Resets the logger instance to the logger instance provided in the + * ParserContext. + */ + void resetLogger(); + + /** + * Returns the location of the element in the source file, for which this + * Handler was created. + * + * @return the location of the Handler in the source file. + */ + const SourceLocation &getLocation() const; + + /** * Called when the command that was specified in the constructor is * instanciated. * |