arg_router  1.4.0
C++ command line argument parsing and routing
custom_parser.hpp
1 // Copyright (C) 2022 by Camden Mannett.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
4 
5 #pragma once
6 
7 #include "arg_router/parsing/token_type.hpp"
8 #include "arg_router/policy/policy.hpp"
9 
10 #include <functional>
11 #include <string_view>
12 
13 namespace arg_router::policy
14 {
19 template <typename T>
21 {
22 public:
24  using value_type = T;
25 
27  using parser_type = std::function<value_type(std::string_view)>;
28 
33  constexpr explicit custom_parser(parser_type p) noexcept : parser_{std::move(p)} {}
34 
44  template <typename ValueType, typename... Parents>
45  [[nodiscard]] constexpr ValueType parse_phase(std::string_view token,
46  [[maybe_unused]] const Parents&... parents) const
47  {
48  return parser_(token);
49  }
50 
51 private:
52  parser_type parser_;
53 };
54 
55 template <typename... Args>
56 struct is_policy<custom_parser<Args...>> : std::true_type {
57 };
58 } // namespace arg_router::policy
constexpr custom_parser(parser_type p) noexcept
constexpr ValueType parse_phase(std::string_view token, [[maybe_unused]] const Parents &... parents) const
std::function< value_type(std::string_view)> parser_type