#ifndef _SDB_SDB_HEADER_FILE_ #define _SDB_SDB_HEADER_FILE_ #include #include #include #include #include #include namespace cr = CppReadline; using ret = cr::Console::ReturnCode; namespace SDB { enum SDBStatus { SDB_SUCCESS, SDB_WRONG_ARGUMENT, SDB_DIFFTEST_FAILED }; class SDBHandlers; struct Handler { const std::vector names; // cr::Console::CommandFunction f; std::function f; }; class SDBHandlers { private: const TrmInterface &funcs; std::vector all_handlers = { Handler{{"c", "continue"}, &SDBHandlers::cmd_continue}, Handler{{"si", "step-instruction"}, &SDBHandlers::cmd_step}, Handler{{"info-r"}, &SDBHandlers::cmd_info_registers}, Handler{{"p", "print"}, &SDBHandlers::cmd_print}, }; int cmd_continue(const cr::Console::Arguments &input); int cmd_step(const std::vector &input); int cmd_info_registers(const std::vector &input); int cmd_print(const std::vector &input); public: SDBHandlers(const TrmInterface &funcs) : funcs(funcs){}; void registerHandlers(cr::Console *c); }; class SDB { private: std::unique_ptr c; const TrmInterface &funcs; SDBHandlers handlers; public: SDB(const TrmInterface &funcs, std::string const &greeting = "\033[1;34m(npc)\033[0m ") : handlers(SDBHandlers{funcs}), funcs(funcs) { c = std::make_unique(greeting); handlers.registerHandlers(c.get()); }; int main_loop() { int retCode; funcs.init(0); do { retCode = c->readLine(); // We can also change the prompt based on last return value: if (retCode == ret::Ok) c->setGreeting("\033[1;34m(npc)\033[0m "); else c->setGreeting("\033[1;31m(npc)\033[0m "); if (retCode == SDB_WRONG_ARGUMENT) { std::cout << "Wrong argument give to command\n"; } } while (retCode != ret::Quit); return 0; } }; } // namespace SDB #endif