arg_router  1.4.0
C++ command line argument parsing and routing
arg_router Namespace Reference

Namespaces

 algorithm
 
 config
 
 dependency
 
 math
 
 multi_lang
 
 parsing
 
 policy
 
 traits
 
 utility
 

Classes

class  arg_t
 
class  counting_flag_t
 
struct  default_error_code_translations
 
class  multi_lang_exception
 
class  parse_exception
 
class  flag_t
 
class  forwarding_arg_t
 
class  help_t
 
class  list
 
class  mode_t
 
class  multi_arg_t
 
class  multi_arg_base_t
 
struct  parser
 
class  add_missing_min_max_policy
 
class  positional_arg_t
 
class  root_t
 
class  tree_node
 
struct  runtime_help_data
 
struct  is_tree_node
 

Typedefs

using string = std::basic_string< char, std::char_traits< char >, config::allocator< char > >
 
using ostringstream = std::basic_ostringstream< char, std::char_traits< char >, config::allocator< char > >
 
template<typename T >
using vector = std::vector< T, config::allocator< T > >
 
template<typename T , auto Extent = nonstd::span_lite::dynamic_extent>
using span = nonstd::span_lite::span< T, Extent >
 

Enumerations

enum class  error_code : std::size_t {
  unknown_argument = 0 , unhandled_arguments , argument_has_already_been_set , failed_to_parse ,
  no_arguments_passed , minimum_value_not_reached , maximum_value_exceeded , minimum_count_not_reached ,
  maximum_count_exceeded , unknown_argument_with_suggestion , mode_requires_arguments = 100 , missing_required_argument ,
  too_few_values_for_alias , dependent_argument_missing , one_of_selected_type_mismatch , missing_value_separator
}
 

Functions

template<typename T , typename... Policies>
constexpr auto arg (Policies... policies) noexcept
 
template<typename T , typename... Policies>
constexpr auto counting_flag (Policies... policies) noexcept
 
template<typename... Policies>
constexpr auto flag (Policies... policies) noexcept
 
template<typename... Policies>
constexpr auto forwarding_arg (Policies... policies) noexcept
 
template<typename... Policies>
constexpr auto help (Policies... policies) noexcept
 
template<typename... Params>
constexpr auto list_expander (Params... params) noexcept
 
template<typename... Params>
constexpr auto list_expander (std::tuple< Params... > params) noexcept
 
template<typename... Params>
constexpr auto mode (Params... params)
 
template<typename T , typename... Policies>
constexpr auto multi_arg (Policies... policies) noexcept
 
template<typename T , typename... Policies>
constexpr auto positional_arg (Policies... policies) noexcept
 
template<typename... Params>
constexpr auto root (Params... params) noexcept
 

Variables

template<typename T >
constexpr bool is_tree_node_v = is_tree_node<T>::value
 
constexpr auto version_string = "1.4.0"
 

Detailed Description

Namespace for all arg_router types and functions.

Typedef Documentation

◆ ostringstream

using arg_router::ostringstream = typedef std::basic_ostringstream<char, std::char_traits<char>, config::allocator<char> >

arg_router ostringstream.

Same as a std::ostringstream, except that it uses the config::allocator.

Definition at line 31 of file basic_types.hpp.

◆ span

template<typename T , auto Extent = nonstd::span_lite::dynamic_extent>
using arg_router::span = typedef nonstd::span_lite::span<T, Extent>

An alias for std::span if compiling with >= C++20 support, otherwise nonstd::span_lite::span.

Definition at line 49 of file basic_types.hpp.

◆ string

using arg_router::string = typedef std::basic_string<char, std::char_traits<char>, config::allocator<char> >

arg_router string.

Same as a std::string, except that it uses the config::allocator.

Definition at line 25 of file basic_types.hpp.

◆ vector

template<typename T >
using arg_router::vector = typedef std::vector<T, config::allocator<T> >

arg_router vector.

Same as a std::vector, except that it uses the config::allocator.

Definition at line 39 of file basic_types.hpp.

Enumeration Type Documentation

◆ error_code

enum arg_router::error_code : std::size_t
strong

Error code type.

These are used as keys into an error string translation table, either a default internal en_GB one, or user provided.

It can be extended by node or policy developers, but to avoid clashes please start at 1000 or higher, eg:

enum class my_error_code : std::size_t {
some_error = 1000,
...
};
// Or if there is only one, this may be more desirable:
constexpr auto some_error = std::size_t{1000};
some_ec_sink(static_cast<ar::error_code>(some_error));
Enumerator
unknown_argument 

A token was passed on the command line that cannot be consumed by any node

unhandled_arguments 

All tokens were matched to nodes, but not all tokens were processed by them

argument_has_already_been_set 

A token has been matched to a node that has already accepted one or more tokens and cannot accept any more

failed_to_parse 

A value token could not be converted into its target value.

no_arguments_passed 

No tokens were passed to the root when one or more nodes were expecting them

minimum_value_not_reached 

Parsed value is below the minimum.

maximum_value_exceeded 

Parsed value is above the maximum.

minimum_count_not_reached 

Minimum number of value tokens for node not reached.

maximum_count_exceeded 

Maximum number of value tokens exceeded.

unknown_argument_with_suggestion 

Same as unknown_argument, but also gives the nearest node name as a suggestion

mode_requires_arguments 

The mode only consists of child modes, but there are no more tokens to consume

missing_required_argument 

A node has been marked as required but no token matches it.

too_few_values_for_alias 

An alias for a fixed sized node has not been given enough value tokens

dependent_argument_missing 

A node has dependency, but that dependency is not specified on the command line

one_of_selected_type_mismatch 

A one_of child node has already been selected, and it does not match the current selection

missing_value_separator 

A token that expects a value separator character was not given one on the command line

Definition at line 33 of file exception.hpp.

Function Documentation

◆ arg()

template<typename T , typename... Policies>
constexpr auto arg_router::arg ( Policies...  policies)
constexprnoexcept

Constructs an arg_t with the given policies and value type.

This is necessary due to CTAD being required for all template parameters or none, and unfortunately in our case we need T to be explicitly set by the user whilst Policies should be deduced.

Compile-time strings can be passed in directly and will be converted to the appropriate policies automatically. The rules are:

  1. The first multi-character string becomes a policy::long_name_t
  2. The second multi-character string becomes a policy::description_t
  3. The first single-charcter string becomes a policy::short_name_t

The above are unicode aware. The strings can be passed in any order relative to the other policies, but it is recommended to put them first to ease reading.

Template Parameters
TArgument value type
PoliciesPack of policies that define its behaviour
Parameters
policiesPack of policy instances
Returns
Argument instance

Definition at line 98 of file arg.hpp.

◆ counting_flag()

template<typename T , typename... Policies>
constexpr auto arg_router::counting_flag ( Policies...  policies)
constexprnoexcept

Constructs a counting_flag_t with the given policies.

Just like 'normal' flags, counting flags with shortnames can be concatenated or 'collapsed' on the command line, e.g.

foo -a -b -c
foo -abc

Compile-time strings can be passed in directly and will be converted to the appropriate policies automatically. The rules are:

  1. The first multi-character string becomes a policy::long_name_t
  2. The second multi-character string becomes a policy::description_t
  3. The first single-charcter string becomes a policy::short_name_t

The above are unicode aware. The strings can be passed in any order relative to the other policies, but it is recommended to put them first to ease reading.

Template Parameters
PoliciesPack of policies that define its behaviour
Parameters
policiesPack of policy instances
Returns
Flag instance

Definition at line 144 of file counting_flag.hpp.

◆ flag()

template<typename... Policies>
constexpr auto arg_router::flag ( Policies...  policies)
constexprnoexcept

Constructs a flag_t with the given policies.

Flags with shortnames can be concatenated or 'collapsed' on the command line, e.g.

foo -a -b -c
foo -abc

Compile-time strings can be passed in directly and will be converted to the appropriate policies automatically. The rules are:

  1. The first multi-character string becomes a policy::long_name_t
  2. The second multi-character string becomes a policy::description_t
  3. The first single-charcter string becomes a policy::short_name_t

The above are unicode aware. The strings can be passed in any order relative to the other policies, but it is recommended to put them first to ease reading.

Template Parameters
PoliciesPack of policies that define its behaviour
Parameters
policiesPack of policy instances
Returns
Flag instance

Definition at line 136 of file flag.hpp.

◆ forwarding_arg()

template<typename... Policies>
constexpr auto arg_router::forwarding_arg ( Policies...  policies)
constexprnoexcept

Constructs a forwarding_arg_t with the given policies and value type.

Compile-time strings can be passed in directly and will be converted to the appropriate policies automatically. The rules are:

  1. The first multi-character string becomes a policy::none_name_t
  2. The second multi-character string becomes a policy::description_t

The above are unicode aware. The strings can be passed in any order relative to the other policies, but it is recommended to put them first to ease reading.

Template Parameters
PoliciesPack of policies that define its behaviour
Parameters
policiesPack of policy instances
Returns
Argument instance

Definition at line 100 of file forwarding_arg.hpp.

◆ help()

template<typename... Policies>
constexpr auto arg_router::help ( Policies...  policies)
constexprnoexcept

Constructs a help_t with the given policies.

Compile-time strings can be passed in directly and will be converted to the appropriate policies automatically. The rules are:

  1. The first multi-character string becomes a policy::long_name_t
  2. The second multi-character string becomes a policy::description_t
  3. The first single-charcter string becomes a policy::short_name_t

The above are unicode aware. The strings can be passed in any order relative to the other policies, but it is recommended to put them first to ease reading.

Template Parameters
PoliciesPack of policies that define its behaviour
Parameters
policiesPack of policy instances
Returns
Help instance

Definition at line 294 of file help.hpp.

◆ list_expander() [1/2]

template<typename... Params>
constexpr auto arg_router::list_expander ( Params...  params)
constexprnoexcept

Takes a pack of node parameters and flattens any list types within it.

Template Parameters
ParamsParameter types
Parameters
paramsParameter instances
Returns
Flattened tuple of nodes

Definition at line 98 of file list.hpp.

◆ list_expander() [2/2]

template<typename... Params>
constexpr auto arg_router::list_expander ( std::tuple< Params... >  params)
constexprnoexcept

Takes a tuple of node parameters and flattens any list types within it.

Template Parameters
ParamsParameter types
Parameters
paramsParameter instances
Returns
Flattened tuple of nodes

Definition at line 110 of file list.hpp.

◆ mode()

template<typename... Params>
constexpr auto arg_router::mode ( Params...  params)
constexpr

Constructs a mode_t with the given policies.

Compile-time strings can be passed in directly and will be converted to the appropriate policies automatically. The rules are:

  1. The first string becomes a policy::none_name_t
  2. The second string becomes a policy::description_t

The above are unicode aware. The strings can be passed in any order relative to the other policies, but it is recommended to put them first to ease reading.

Template Parameters
ParamsPolicies and child node types for the mode
Parameters
paramsPack of policy and child node instances
Returns
Mode instance

Definition at line 570 of file mode.hpp.

◆ multi_arg()

template<typename T , typename... Policies>
constexpr auto arg_router::multi_arg ( Policies...  policies)
constexprnoexcept

Constructs a multi_arg_t with the given policies and value type.

This is necessary due to CTAD being required for all template parameters or none, and unfortunately in our case we need T to be explicitly set by the user whilst Policies should be deduced.

Compile-time strings can be passed in directly and will be converted to the appropriate policies automatically. The rules are:

  1. The first multi-character string becomes a policy::long_name_t
  2. The second multi-character string becomes a policy::description_t
  3. The first single-charcter string becomes a policy::short_name_t

The above are unicode aware. The strings can be passed in any order relative to the other policies, but it is recommended to put them first to ease reading.

Template Parameters
TArgument value type
PoliciesPack of policies that define its behaviour
Parameters
policiesPack of policy instances
Returns
Argument instance

Definition at line 111 of file multi_arg.hpp.

◆ positional_arg()

template<typename T , typename... Policies>
constexpr auto arg_router::positional_arg ( Policies...  policies)
constexprnoexcept

Constructs an positional_arg_t with the given policies and value type.

This is necessary due to CTAD being required for all template parameters or none, and unfortunately in our case we need T to be explicitly set by the user whilst Policies should be deduced.

Compile-time strings can be passed in directly and will be converted to the appropriate policies automatically. The rules are:

  1. The first string becomes a policy::display_name_t
  2. The second string becomes a policy::description_t

The above are unicode aware. The strings can be passed in any order relative to the other policies, but it is recommended to put them first to ease reading.

Template Parameters
TArgument value type, must have a push_back(..) method
PoliciesPack of policies that define its behaviour
Parameters
policiesPack of policy instances
Returns
Argument instance

Definition at line 116 of file positional_arg.hpp.

◆ root()

template<typename... Params>
constexpr auto arg_router::root ( Params...  params)
constexprnoexcept

Constructs a root_t with the given policies and children.

This is used for similarity with arg_t.

Template Parameters
ParamsPolicies and child node types for the mode
Parameters
paramsPack of policy and child node instances
Returns
Root instance

Definition at line 295 of file root.hpp.

Variable Documentation

◆ is_tree_node_v

template<typename T >
constexpr bool arg_router::is_tree_node_v = is_tree_node<T>::value
constexpr

Helper variable for is_tree_node.

Template Parameters
TType to test

Definition at line 50 of file tree_node_fwd.hpp.

◆ version_string

constexpr auto arg_router::version_string = "1.4.0"
constexpr

Library version as a SymVers-style string.

Definition at line 17 of file version.hpp.