#include <iostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <string>
#include <unordered_map>
#include <memory>
struct command {
using args_type = std::vector<std::string>;
virtual void exec(args_type const& args) const = 0;
virtual ~command() {}
};
struct read_file : command {
virtual void exec(args_type const& args) const override {
std::clog << "'read_file'";
for (auto const& arg : args) {
std::clog << ' ' << arg;
}
std::clog << std::endl;
}
};
struct write_file : command {
virtual void exec(args_type const& args) const override {
std::clog << "'write_file'";
for (auto const& arg : args) {
std::clog << ' ' << arg;
}
std::clog << std::endl;
}
};
using command_ptr = std::unique_ptr<command>;
using command_map = std::unordered_map<std::string, command_ptr>;
int main() {
// ассоциативный массив команд
command_map commandMap;
commandMap["read_file" ] = command_ptr(new read_file);
commandMap["write_file"] = command_ptr(new write_file);
for (std::string line; std::getline(std::cin, line); ) {
std::istringstream iss(line);
std::string commandName;
iss >> commandName;
auto const it = commandMap.find(commandName);
if (it != std::end(commandMap)) {
command::args_type const commandArgs(
std::istream_iterator<std::string>{iss}
, std::istream_iterator<std::string>{});
it->second->exec(commandArgs);
} else {
std::cerr << "'" << commandName << "' - unrecognized command" << std::endl;
}
}
}