Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

54 рядки
1.8 KiB

  1. #pragma once
  2. #include <cpputils/mp.h>
  3. #include <cppargs/parser/parser.h>
  4. #include <cppargs/group/simple_group.inl>
  5. namespace cppargs
  6. {
  7. template<typename... T_args>
  8. simple_parser::simple_parser(
  9. option_ptr_type&& p_default,
  10. T_args&&... args)
  11. : base_type (std::move(p_default), _group)
  12. , _group ({ }, std::forward<T_args>(args)...)
  13. { update_map(); }
  14. void simple_parser::parse(int argc, char const * argv[]) const
  15. { parser::parse(argc, argv); }
  16. template<typename... T_args>
  17. constexpr decltype(auto) simple_parser::make_group(const group_meta& meta, T_args&&... args)
  18. {
  19. return std::make_unique<simple_group>(meta, std::forward<T_args>(args)...);
  20. }
  21. template<typename T_predicate>
  22. constexpr decltype(auto) simple_parser::make_predicate_option(const option_meta& meta, T_predicate&& predicate)
  23. {
  24. using predicate_type = T_predicate;
  25. using simple_predicate_option_type = simple_predicate_option<predicate_type>;
  26. return std::make_unique<simple_predicate_option_type>(meta, std::forward<predicate_type>(predicate));
  27. }
  28. template<typename T_value>
  29. constexpr decltype(auto) simple_parser::make_reference_option(const option_meta& meta, T_value& value)
  30. {
  31. using value_type = T_value;
  32. auto predicate = [&value](context& c)
  33. {
  34. using executor_type = option_parser<value_type>;
  35. executor_type { c, value } ( );
  36. };
  37. using predicate_type = decltype(predicate);
  38. using simple_predicate_option_type = simple_predicate_option<predicate_type>;
  39. return std::make_unique<simple_predicate_option_type>(
  40. option_meta::prepare_arguments<T_value>(meta),
  41. std::move(predicate));
  42. }
  43. }