arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::tree_node< Params > Class Template Reference

#include <arg_router/tree_node.hpp>

Inheritance diagram for arg_router::tree_node< Params >:
[legend]

Classes

class  any_phases
 
class  default_leaf_help_data_type
 
struct  phase_finder
 

Public Types

using parameters_type = std::tuple< std::decay_t< Params >... >
 
using policies_type = boost::mp11::mp_filter< policy::is_policy, parameters_type >
 
using priority_ordered_policies_type = boost::mp11::mp_sort< policies_type, priority_order >
 
using children_type = boost::mp11::mp_filter< is_tree_node, std::decay_t< decltype(list_expander(std::declval< std::decay_t< Params > >()...))> >
 
template<template< typename... > typename PolicyChecker, typename... Args>
using phase_finder_t = typename phase_finder< PolicyChecker, Args... >::type
 

Public Member Functions

children_typechildren () noexcept
 
constexpr const children_typechildren () const noexcept
 

Static Public Attributes

constexpr static auto is_named
 
template<typename ValueType , template< typename... > typename... PolicyCheckers>
constexpr static bool any_phases_v = any_phases<ValueType, PolicyCheckers...>::value
 

Protected Member Functions

constexpr tree_node (Params... params) noexcept
 
template<typename Validator , bool HasTarget, typename Node , typename... Parents>
std::optional< parsing::parse_targetpre_parse (parsing::pre_parse_data< Validator, HasTarget > pre_parse_data, const Node &node, const Parents &... parents) const
 
template<typename ValueType , typename Node , typename... Parents>
auto parse (std::string_view token, const Node &node, const Parents &... parents) const
 

Detailed Description

template<typename... Params>
class arg_router::tree_node< Params >

Base type of all nodes of a parse tree, not including policies.

Template Parameters
ParamsParameter types

Definition at line 25 of file tree_node.hpp.

Member Typedef Documentation

◆ children_type

template<typename... Params>
using arg_router::tree_node< Params >::children_type = boost::mp11::mp_filter< is_tree_node, std::decay_t<decltype(list_expander(std::declval<std::decay_t<Params> >()...))> >

A tuple of all the child tree node types in parameters_type, with any lists expanded.

Definition at line 57 of file tree_node.hpp.

◆ parameters_type

template<typename... Params>
using arg_router::tree_node< Params >::parameters_type = std::tuple<std::decay_t<Params>...>

The policies and child node types.

Definition at line 48 of file tree_node.hpp.

◆ phase_finder_t

template<typename... Params>
template<template< typename... > typename PolicyChecker, typename... Args>
using arg_router::tree_node< Params >::phase_finder_t = typename phase_finder<PolicyChecker, Args...>::type

Helper alias for phase_finder.

Template Parameters
PolicyCheckerPolicy predicate, use one of policy::has_*_phase_method
ArgsAuxiliary arguments to pass to PolicyChecker

Definition at line 97 of file tree_node.hpp.

◆ policies_type

template<typename... Params>
using arg_router::tree_node< Params >::policies_type = boost::mp11::mp_filter<policy::is_policy, parameters_type>

A tuple of all the policy types in parameters_type.

Definition at line 51 of file tree_node.hpp.

◆ priority_ordered_policies_type

template<typename... Params>
using arg_router::tree_node< Params >::priority_ordered_policies_type = boost::mp11::mp_sort<policies_type, priority_order>

policies_type ordered by priority

Definition at line 54 of file tree_node.hpp.

Constructor & Destructor Documentation

◆ tree_node()

template<typename... Params>
constexpr arg_router::tree_node< Params >::tree_node ( Params...  params)
inlineexplicitconstexprprotectednoexcept

Constructor.

Parameters
paramsPolicy and child instances

Definition at line 435 of file tree_node.hpp.

Member Function Documentation

◆ children() [1/2]

template<typename... Params>
constexpr const children_type& arg_router::tree_node< Params >::children ( ) const
inlineconstexprnoexcept

Const overload.

Returns
Children

Definition at line 154 of file tree_node.hpp.

◆ children() [2/2]

template<typename... Params>
children_type& arg_router::tree_node< Params >::children ( )
inlinenoexcept

Returns a reference to the children.

Returns
Children

Definition at line 148 of file tree_node.hpp.

◆ parse()

template<typename... Params>
template<typename ValueType , typename Node , typename... Parents>
auto arg_router::tree_node< Params >::parse ( std::string_view  token,
const Node &  node,
const Parents &...  parents 
) const
inlineprotected

Generic parse call, uses a policy that supports the parse phase if present, or the global parser.

Template Parameters
ValueTypeParsed type
NodeThis node's derived type
ParentsPack of parent tree nodes in ascending ancestry order
Parameters
tokenToken to parse
nodeThis node instance
parentsParents instances pack
Returns
Parsed result
Exceptions
multi_lang_exceptionThrown if parsing failed

Definition at line 488 of file tree_node.hpp.

◆ pre_parse()

template<typename... Params>
template<typename Validator , bool HasTarget, typename Node , typename... Parents>
std::optional<parsing::parse_target> arg_router::tree_node< Params >::pre_parse ( parsing::pre_parse_data< Validator, HasTarget >  pre_parse_data,
const Node &  node,
const Parents &...  parents 
) const
inlineprotected

Default pre-parse implementation.

This implementation simply iterates over the pre-parse phase implementing policies, and uses the results to update args and generate a parse_target.

The validator is called just before args is updated, and allows the caller to run a custom verification the on the node and parents. If the validator returns true then the result is kept, otherwise an empty result is returned from this method.

Note
The implementation does not prepend *this into parents, so derived types are expected to reimplement this so @ node is the correct type (remember there are no virtual methods in this library)
Template Parameters
ValidatorValidator type
HasTargetTrue if pre_parse_data contains the parent's parse_target
NodeThis node's derived type
ParentsPack of parent tree nodes in ascending ancestry order
Parameters
pre_parse_dataPre-parse data aggregate
nodeThis node instance
parentsParent node instances
Returns
Non-empty if the leading tokens in args are consumable by this node
Exceptions
multi_lang_exceptionThrown if any of the policies' pre-parse implementations have returned an exception

Definition at line 465 of file tree_node.hpp.

Member Data Documentation

◆ any_phases_v

template<typename... Params>
template<typename ValueType , template< typename... > typename... PolicyCheckers>
constexpr static bool arg_router::tree_node< Params >::any_phases_v = any_phases<ValueType, PolicyCheckers...>::value
staticconstexpr

Helper alias for has_phases.

Template Parameters
ValueTypeSome policy checkers require a value type template parameter, if a particular policy doesn't need it then it is not used
PolicyCheckersParameter pack type of policy predicates, use policy::has_*_phase_method

Definition at line 142 of file tree_node.hpp.

◆ is_named

template<typename... Params>
constexpr static auto arg_router::tree_node< Params >::is_named
staticconstexpr
Initial value:
= traits::has_short_name_method_v<tree_node> ||
traits::has_long_name_method_v<tree_node> ||
traits::has_none_name_method_v<tree_node>

Evaluates to true if this node has a name token that appears on the command line.

Definition at line 68 of file tree_node.hpp.


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