arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::multi_lang::root_wrapper_t< Fn, SupportedISOLanguageCodes > Class Template Reference

#include <arg_router/multi_lang/root_wrapper.hpp>

Public Member Functions

 root_wrapper_t (std::string_view iso_language, Fn &&f)
 
void parse (int argc, char **argv) const
 
void help (std::ostream &stream) const
 
string help () const
 

Detailed Description

template<typename Fn, typename... SupportedISOLanguageCodes>
class arg_router::multi_lang::root_wrapper_t< Fn, SupportedISOLanguageCodes >

A wrapper around a root node that provides multi-language support.

The wrapper relies on the use of string_selector (or SM_) to provide compile-time selection of language variants for strings. The wrapper simply creates a root variant for the given ISO language code. If the given ISO language code does not match any of the supporting ones, then the first supported language is used as a fallback.

namespace ar = arg_router;
namespace arp = ar::policy;
ar::multi_lang::root_wrapper<S_("en_GB"), S_("fr"), S_("es")>{
ar::multi_lang::iso_locale(std::locale("").name()),
[&](auto I) {
return ar::root(my_validator{},
ar::help(arp::long_name<SM_(I, "help", "aider", "ayuda")>,
arp::short_name<'h'>,
arp::program_name<S_("is_even")>,
arp::program_version<S_(version)>,
arp::program_addendum<SM_(I, "An example program for arg_router.",
"Un exemple de programme pour arg_router.",
"Un programa de ejemplo para arg_router")>,
...
#define S_(tok)
#define SM_(I,...)

As implied by the above example, the supported language is given by index to the function object that returns the root instance. This means that each use of string_selector must have the same number of language options, in the same order. The latter requirement is especially important as this cannot be checked by arg_router.

Fn is a function object used to return a given root type from a supported language index, its signature must match:

template <typename IntegralConstant>
auto operator()(IntegralConstant I) {
...
};

The SupportedISOLanguageCodes parameters can be any set of unique strings, but as they are compared against an input that would usually come from a std::locale() call, then ISO language codes are least troublesome and easiest to read.

Note
This has now been superceded by multi_lang::root_t, and will be removed in v2
Template Parameters
FnFunction object type that accepts an integral constant (the supported language index) and returns a root instance
SupportedISOLanguageCodesThe supported ISO language codes as compile time strings

Definition at line 67 of file root_wrapper.hpp.

Constructor & Destructor Documentation

◆ root_wrapper_t()

template<typename Fn , typename... SupportedISOLanguageCodes>
arg_router::multi_lang::root_wrapper_t< Fn, SupportedISOLanguageCodes >::root_wrapper_t ( std::string_view  iso_language,
Fn &&  f 
)
inlineexplicit

Constructor

Parameters
iso_languageThe runtime language selection, if it doesn't match any of SupportedISOLanguageCodes, then the first language in SupportedISOLanguageCodes is used
fFunction object that returns the root instance for a given supported language index

Definition at line 92 of file root_wrapper.hpp.

Member Function Documentation

◆ help() [1/2]

template<typename Fn , typename... SupportedISOLanguageCodes>
string arg_router::multi_lang::root_wrapper_t< Fn, SupportedISOLanguageCodes >::help ( ) const
inline

Calls the help method on the selected root.

Returns
String holding the help output

Definition at line 132 of file root_wrapper.hpp.

◆ help() [2/2]

template<typename Fn , typename... SupportedISOLanguageCodes>
void arg_router::multi_lang::root_wrapper_t< Fn, SupportedISOLanguageCodes >::help ( std::ostream &  stream) const
inline

Calls the help method on the selected root.

Parameters
streamOutput stream to write into

Definition at line 123 of file root_wrapper.hpp.

◆ parse()

template<typename Fn , typename... SupportedISOLanguageCodes>
void arg_router::multi_lang::root_wrapper_t< Fn, SupportedISOLanguageCodes >::parse ( int  argc,
char **  argv 
) const
inline

Calls the parse method on the selected root.

Parameters
argcNumber of arguments
argvArray of char pointers to the command line tokens

Definition at line 114 of file root_wrapper.hpp.


The documentation for this class was generated from the following file: