#ifndef NEWSBEUTER_CONFIGPARSER__H #define NEWSBEUTER_CONFIGPARSER__H #include #include #include #include namespace newsbeuter { enum action_handler_status { AHS_OK = 0, AHS_INVALID_PARAMS, AHS_TOO_FEW_PARAMS, AHS_INVALID_COMMAND, AHS_FILENOTFOUND }; struct config_action_handler { virtual void handle_action(const std::string& action, const std::vector& params) = 0; virtual void dump_config(std::vector& config_output) = 0; config_action_handler() { } virtual ~config_action_handler() { } }; class configparser : public config_action_handler { public: configparser(); virtual ~configparser(); void register_handler(const std::string& cmd, config_action_handler * handler); void unregister_handler(const std::string& cmd); virtual void handle_action(const std::string& action, const std::vector& params); virtual void dump_config(std::vector& ) { /* nothing because configparser itself only handles include */ } bool parse(const std::string& filename, bool double_include = true); static std::string evaluate_backticks(std::string token); private: void evaluate_backticks(std::vector& tokens); static std::string evaluate_cmd(const std::string& cmd); std::vector> parsed_content; std::map action_handlers; std::set included_files; }; class null_config_action_handler : public config_action_handler { public: null_config_action_handler() { } virtual ~null_config_action_handler() { } virtual void handle_action(const std::string& , const std::vector& ) { } virtual void dump_config(std::vector& ) { } }; } #endif