ArgParser.hpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * libdatachannel streamer example
  3. * Copyright (c) 2020 Filip Klembara (in2core)
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ArgParser_hpp
  19. #define ArgParser_hpp
  20. #include <functional>
  21. #include <vector>
  22. #include <utility>
  23. #include <string>
  24. #include <set>
  25. #include <unordered_map>
  26. #include <optional>
  27. struct ArgParser {
  28. private:
  29. std::set<std::string> options{};
  30. std::set<std::string> flags{};
  31. std::unordered_map<std::string, std::string> shortToLongMap{};
  32. public:
  33. ArgParser(std::vector<std::pair<std::string, std::string>> options, std::vector<std::pair<std::string, std::string>> flags);
  34. std::optional<std::string> toKey(std::string prefixedKey);
  35. bool parse(int argc, char **argv, std::function<bool (std::string, std::string)> onOption, std::function<bool (std::string)> onFlag);
  36. };
  37. #endif /* ArgParser_hpp */