7 #include "arg_router/multi_lang/translation.hpp"
8 #include "arg_router/parsing/token_type.hpp"
9 #include "arg_router/utility/tuple_iterator.hpp"
89 template <
typename RootFactory,
typename DefaultLanguageID,
typename... SupportedLanguageIDs>
92 using supported_language_ids = std::tuple<DefaultLanguageID, SupportedLanguageIDs...>;
93 constexpr
static auto num_supported_ids = std::tuple_size_v<supported_language_ids>;
95 static_assert(num_supported_ids > 1,
"Must be more than one language supported");
96 static_assert(num_supported_ids ==
97 std::tuple_size_v<boost::mp11::mp_unique<supported_language_ids>>,
98 "Supported languages must be unique");
100 using root_variant_t =
101 std::variant<std::decay_t<decltype(std::declval<RootFactory>()(
102 std::declval<translation<DefaultLanguageID>>()))>,
103 std::decay_t<decltype(std::declval<RootFactory>()(
104 std::declval<translation<SupportedLanguageIDs>>()))>...>;
113 explicit root_t(std::string_view language_id,
const RootFactory& f)
115 utility::tuple_type_iterator<supported_language_ids>([&](
auto I) {
116 using id = std::tuple_element_t<I, supported_language_ids>;
118 if (root_ || (language_id != id::get())) {
139 std::visit([&](
const auto&
root) {
root.parse(std::move(args)); }, *root_);
150 template <
typename Iter,
typename = std::enable_if_t<!std::is_same_v<std::decay_t<Iter>,
int>>>
151 void parse(Iter begin, Iter end)
const
153 std::visit([&](
const auto&
root) {
root.parse(begin, end); }, *root_);
164 template <
typename Container,
165 typename = std::enable_if_t<
167 void parse(
const Container& c)
const
169 std::visit([&](
const auto&
root) {
root.parse(c); }, *root_);
177 void parse(
int argc,
char** argv)
const
179 std::visit([&](
const auto&
root) {
root.parse(argc, argv); }, *root_);
186 void help(std::ostream& stream)
const
188 std::visit([&](
const auto&
root) {
root.help(stream); }, *root_);
195 [[nodiscard]]
string help()
const
197 return std::visit([](
const auto&
root) {
root.help(); }, *root_);
202 std::optional<root_variant_t> root_;
220 template <
typename DefaultLanguageID,
typename... SupportedLanguageIDs,
typename RootFactory>
221 auto root(std::string_view language_id,
const RootFactory& f)
223 return root_t<RootFactory, DefaultLanguageID, SupportedLanguageIDs...>{language_id, f};
void parse(vector< parsing::token_type > args) const
void help(std::ostream &stream) const
void parse(int argc, char **argv) const
root_t(std::string_view language_id, const RootFactory &f)
void parse(const Container &c) const
void parse(Iter begin, Iter end) const
auto root(std::string_view language_id, const RootFactory &f)
std::vector< T, config::allocator< T > > vector