#include <iostream>
#include <map>
#include <vector>
#include <memory>
#include <cctype>
class ICommand
{
public:
virtual ~ICommand(){}
virtual void Execute() = 0;
};
class ProcessSingleStatusCommand : public ICommand
{
public:
void Execute()
{
std::cout << "ProcessSingleStatusCommand" << std::endl;
}
};
class ProcessMarriedStatusCommand : public ICommand
{
public:
void Execute()
{
std::cout << "ProcessMarriedStatusCommand" << std::endl;
}
};
int main()
{
typedef std::map<char, std::unique_ptr<ICommand>> TCommandMap;
TCommandMap commandMap;
commandMap.insert(std::make_pair('s', std::unique_ptr<ICommand>(new ProcessSingleStatusCommand())));
commandMap.insert(std::make_pair('m', std::unique_ptr<ICommand>(new ProcessMarriedStatusCommand())));
// Assume we've captured inputs 's' & 'M'
std::vector<char> inputs {'s', 'M'};
for (const auto& input : inputs)
{
auto it = commandMap.find(tolower(input));
if (it != commandMap.end())
{
it->second->Execute();
}
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWVtb3J5PgojaW5jbHVkZSA8Y2N0eXBlPgoKY2xhc3MgSUNvbW1hbmQKewpwdWJsaWM6Cgl2aXJ0dWFsIH5JQ29tbWFuZCgpe30KCXZpcnR1YWwgdm9pZCBFeGVjdXRlKCkgPSAwOwp9OwoKY2xhc3MgUHJvY2Vzc1NpbmdsZVN0YXR1c0NvbW1hbmQgOiBwdWJsaWMgSUNvbW1hbmQKewpwdWJsaWM6Cgl2b2lkIEV4ZWN1dGUoKQoJewoJCXN0ZDo6Y291dCA8PCAiUHJvY2Vzc1NpbmdsZVN0YXR1c0NvbW1hbmQiIDw8IHN0ZDo6ZW5kbDsKCX0KfTsKCmNsYXNzIFByb2Nlc3NNYXJyaWVkU3RhdHVzQ29tbWFuZCA6IHB1YmxpYyBJQ29tbWFuZAp7CnB1YmxpYzoKCXZvaWQgRXhlY3V0ZSgpCgl7CgkJc3RkOjpjb3V0IDw8ICJQcm9jZXN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