argparse.h (864B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef argparse_h__ 6 #define argparse_h__ 7 8 #include <string> 9 #include <unordered_map> 10 #include <vector> 11 12 class ArgParser { 13 public: 14 ArgParser(const std::vector<std::string>& arguments); 15 16 bool Has(std::string arg) const { return programArgs_.count(arg) > 0; } 17 18 std::string Get(std::string arg) const { return programArgs_.at(arg); } 19 20 size_t GetPositionalArgumentCount() const { return positionalArgs_.size(); } 21 std::string GetPositionalArgument(size_t pos) const { 22 return positionalArgs_.at(pos); 23 } 24 25 private: 26 std::unordered_map<std::string, std::string> programArgs_; 27 std::vector<std::string> positionalArgs_; 28 }; 29 30 #endif // argparse_h__