-Callback implementation with STL (Modern C++)-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include "global.h" #include "core/interface.h" typedef std::function<void()> Callback; int main(int argc, char** argv) { std::map<std::string, Callback> mapCallback; mapCallback.insert(std::pair<std::string, Callback>("open", std::bind(MainInterface::setupUnkFile))); mapCallback.insert(std::pair<std::string, Callback>("procview", std::bind(MainInterface::logviewCurrentProc))); mapCallback.insert(std::pair<std::string, Callback>("history", std::bind(MainInterface::logviewHistoryProc))); mapCallback.insert(std::pair<std::string, Callback>("vmstatus", std::bind(MainInterface::logviewCurrentStat))); mapCallback.insert(std::pair<std::string, Callback>("procmgr", std::bind(MainInterface::ctrlProcMgr))); mapCallback.insert(std::pair<std::string, Callback>("imexport", std::bind(MainInterface::ctrlImExport))); mapCallback.insert(std::pair<std::string, Callback>("exit", std::bind([](){std::exit(0);}))); if (argc > 1) { std::string strArgv = argv[1]; auto it = mapCallback.find(strArgv); if (it != mapCallback.end()) it->second(); } else MainInterface::setupInterface(); } | cs |