123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #ifndef argparse_hpp
- #define argparse_hpp
- #include <algorithm>
- #include <string>
- #include <vector>
- namespace fv::util{
- class ArgParser{
- private:
- std::vector <std::string> tokens;
- std::string empty_string;
- public:
- ArgParser (int &argc, char **argv){
- for (int i=1; i < argc; ++i)
- this->tokens.push_back(std::string(argv[i]));
- }
-
- const std::string& getCmdOption(const std::string &option) const{
- std::vector<std::string>::const_iterator itr;
- itr = std::find(this->tokens.begin(), this->tokens.end(), option);
- if (itr != this->tokens.end() && ++itr != this->tokens.end()){
- return *itr;
- }
- return empty_string;
- }
-
- bool cmdOptionExists(const std::string &option) const{
- return std::find(this->tokens.begin(), this->tokens.end(), option)
- != this->tokens.end();
- }
- };
- }
- #endif
|