#ifndef PARAMETERS_HPP #define PARAMETERS_HPP #include #include #include class Parameters { public: Parameters(): workerCount_(std::thread::hardware_concurrency()), searchPattern_("") {}; ~Parameters() {}; bool parseCmdLine(int argc, char** argv) { for (int i = 1; i < argc; i++) { std::string arg = argv[i]; if (0 == arg.compare(0, 2, "-w")) { workerCount_ = std::stoi(arg.substr(2)); } else if (0 == arg.compare(0, 1, "-")) { // invalid option return false; } else { // no leading dash ... must be pattern searchPattern_ = arg; } } return true; } void show_usage(const char* cmd) { std::cerr << "Invalid command line args" << std::endl; std::cerr << "Usage: " << cmd << " [options] [search_pattern]" << std::endl << "Options" << std::endl << " -wX Number of parallel workers" << std::endl << std::endl; }; unsigned WorkerCount() const { return workerCount_; }; std::string SearchPattern() const { return searchPattern_; }; private: unsigned workerCount_; std::string searchPattern_; }; #endif