Hi I'm trying implement commands in a c++ console app The app has a command prompt , basically does nothing until you type a specific command , now the problem is I can't find an efficient way to do this, the only solution I can think of is implementing thousands of if else statements which are not exactly efficient, also switch statements don't work on strings, The commands are separate functions with different arguments and all commands are preprocessor definitions,
I tried implementing if else statements but they were silly
one other way i also could think of was using a scripting language and implementing my own functions, for example i could use chaiscript and implement my own function called 'new' which takes two parameters (first what type of file and second the name of the file) and i could give it the command line inputs instead of a script file, this approach could save me from creating my own scripting language or command line interface(whatever it is called)
std::string cmd;std::getline(std::cin, cmd);if(cmd == "secret") { /* do stuff */ }or use astd::unordered_mapto map from your commands to whatever function you want ot execute for each commandifchain is hardly going to be noticeable. Don't bother with performance until it is actually not meeting requirements.std::unordered_map<std::string, std::function>could be what you are looking for.