ulfben icon

command line options parser

ulfben | PRO | 01/02/18 10:21:57 PM UTC | 0 ⭐ | 1149 👁️ | Never ⏰ | []
C++ |

1.05 KB

|

None

|

0 👍

/

0 👎

//(incomplete!) command line options utility
#pragma once
#include <string>
#include <algorithm>
#include <vector>
 
class ProgramOptions{
private:
    const std::string EMPTY{""};
    std::vector<std::string> _tokens;
public:
    ProgramOptions(const int argc, char* argv[]){
        _tokens.reserve(argc);
        for(int i = 0; i < argc; ++i){
            _tokens.emplace_back(argv[i]);
        }
    }
    const std::string& getOption(const size_t index) const{
        if(index >= _tokens.size()){
            return EMPTY;
        }
        return _tokens[index];      
    }
    const std::string& getOption(const std::string& option) const{
        auto itr = std::find(_tokens.begin(), _tokens.end(), option);
        if(itr != _tokens.end() && ++itr != _tokens.end()){
            return *itr;
        }       
        return EMPTY;
    }
    std::string toString() const{
        std::string out;
        static const std::string newLine{"\n"};
        for(const auto& str : _tokens){
            out += str+newLine;
        }
        return out;
    }
    bool optionExists(const std::string& option) const {
        return std::find(_tokens.begin(), _tokens.end(), option) != _tokens.end();
    }
};

Comments

  • Gyqizv icon
    04/02/26 06:17:23 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best t33n active cpx link daily updates!
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.@xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400
     Remove the @ 
  • Yuizcko icon
    05/18/26 01:13:01 PM UTC
    text |

    0 B

    |

    0 👍

    /

    0 👎

    Best Pastebin.com alternatives paste sites list
     Copy and paste the link in a new browser tab and then hit enter!
     https://crazyporn.xxx/members/157354/?asgtbndr=1&play=true&spon=adworld&zone=400