///////////////////////////////////////// util functions for command line handling // /////////////////////////////////////////
| 25 | // util functions for command line handling // |
| 26 | ////////////////////////////////////////////// |
| 27 | struct CommandLine |
| 28 | { |
| 29 | typedef std::unordered_set<std::unique_ptr<std::string>> StringPool; |
| 30 | typedef std::unordered_set<std::unique_ptr<std::vector<char*>>> CommandLinePool; |
| 31 | |
| 32 | static StringPool string_pool; |
| 33 | static CommandLinePool command_line_pool; |
| 34 | |
| 35 | CommandLine() : cl(nullptr) { } |
| 36 | |
| 37 | CommandLine(int argc, char** argv) : cl(nullptr) |
| 38 | { |
| 39 | auto cl_iter = command_line_pool.emplace(std::unique_ptr<std::vector<char*>>(new std::vector<char*>())); |
| 40 | cl = cl_iter.first->get(); |
| 41 | for (size_t i = 0; i < argc; ++i) { |
| 42 | auto pair = string_pool.emplace(std::unique_ptr<std::string>{new std::string(argv[i])}); |
| 43 | cl->emplace_back(&(*pair.first->get())[0]); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void add(std::vector<std::string> const& args) |
| 48 | { |
| 49 | for (std::string const& str : args) { |
| 50 | auto pair = string_pool.emplace(std::unique_ptr<std::string>{new std::string(str)}); |
| 51 | cl->emplace_back(&(*pair.first->get())[0]); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | int argc() { return cl->size(); } |
| 56 | char** argv() { return cl->data(); } |
| 57 | |
| 58 | private: |
| 59 | std::vector<char*>* cl; |
| 60 | }; |
| 61 | |
| 62 | CommandLine::StringPool CommandLine::string_pool; |
| 63 | CommandLine::CommandLinePool CommandLine::command_line_pool; |