ArgParser.hpp 1016 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * libdatachannel streamer example
  3. * Copyright (c) 2020 Filip Klembara (in2core)
  4. *
  5. * This Source Code Form is subject to the terms of the Mozilla Public
  6. * License, v. 2.0. If a copy of the MPL was not distributed with this
  7. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
  8. */
  9. #ifndef ArgParser_hpp
  10. #define ArgParser_hpp
  11. #include <functional>
  12. #include <vector>
  13. #include <utility>
  14. #include <string>
  15. #include <set>
  16. #include <unordered_map>
  17. #include <optional>
  18. struct ArgParser {
  19. private:
  20. std::set<std::string> options{};
  21. std::set<std::string> flags{};
  22. std::unordered_map<std::string, std::string> shortToLongMap{};
  23. public:
  24. ArgParser(std::vector<std::pair<std::string, std::string>> options, std::vector<std::pair<std::string, std::string>> flags);
  25. std::optional<std::string> toKey(std::string prefixedKey);
  26. bool parse(int argc, char **argv, std::function<bool (std::string, std::string)> onOption, std::function<bool (std::string)> onFlag);
  27. };
  28. #endif /* ArgParser_hpp */