diff options
author | 2020-08-02 21:58:26 +0200 | |
---|---|---|
committer | 2020-08-04 10:18:37 +0200 | |
commit | 259afa5353de2d799829ff85dde7194a6e119ddc (patch) | |
tree | c09f2e763a0e9f54fb366b91ec697f42acfde988 /src/configparser.cpp | |
parent | 08f485903867744cedc3f0382903865057cb9e70 (diff) | |
download | newsboat-259afa5353de2d799829ff85dde7194a6e119ddc.tar.gz newsboat-259afa5353de2d799829ff85dde7194a6e119ddc.tar.zst newsboat-259afa5353de2d799829ff85dde7194a6e119ddc.zip |
Store config handlers as non-nullable references
Diffstat (limited to 'src/configparser.cpp')
-rw-r--r-- | src/configparser.cpp | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/configparser.cpp b/src/configparser.cpp index 870e13e0..3c0a9a86 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -19,7 +19,7 @@ namespace newsboat { ConfigParser::ConfigParser() { - register_handler("include", this); + register_handler("include", *this); } ConfigParser::~ConfigParser() {} @@ -101,25 +101,22 @@ bool ConfigParser::parse(const std::string& tmp_filename) if (!tokens.empty()) { std::string cmd = tokens[0]; - ConfigActionHandler* handler = action_handlers[cmd]; - if (handler) { - tokens.erase( - tokens.begin()); // delete first element - try { - handler->handle_action(cmd, tokens); - } catch (const ConfigHandlerException& e) { - throw ConfigException(strprintf::fmt( - _("Error while processing " - "command `%s' (%s line %u): " - "%s"), - line, - filename, - linecounter, - e.what())); - } - } else { + if (action_handlers.count(cmd) < 1) { + throw ConfigException(strprintf::fmt(_("unknown command `%s'"), cmd)); + } + ConfigActionHandler& handler = action_handlers.at(cmd); + tokens.erase(tokens.begin()); // delete first element + try { + handler.handle_action(cmd, tokens); + } catch (const ConfigHandlerException& e) { throw ConfigException(strprintf::fmt( - _("unknown command `%s'"), cmd)); + _("Error while processing " + "command `%s' (%s line %u): " + "%s"), + line, + filename, + linecounter, + e.what())); } } } @@ -128,9 +125,10 @@ bool ConfigParser::parse(const std::string& tmp_filename) } void ConfigParser::register_handler(const std::string& cmd, - ConfigActionHandler* handler) + ConfigActionHandler& handler) { - action_handlers[cmd] = handler; + action_handlers.erase(cmd); + action_handlers.insert({cmd, handler}); } /* Note that this function not only finds next backtick that isn't prefixed |