Ookii.CommandLine for C++  2.0.0
Public Types | Public Member Functions | Static Public Member Functions | List of all members
ookii::command_info< CharType, Traits, Alloc > Class Template Reference

Provides information about a subcommand. More...

#include <ookii/subcommand.h>

Public Types

using builder_type = typename command_type::builder_type
 The concrete type of basic_parser_builder used.
 
using command_type = basic_command< CharType, Traits, Alloc >
 The concrete type of basic_command used.
 
using command_with_custom_parsing_type = basic_command_with_custom_parsing< CharType, Traits, Alloc >
 The concrete type of basic_command_with_custom_parsing used.
 
using creator = std::function< std::unique_ptr< command_type >(builder_type *)>
 The type of a function that instantiates a subcommand.
 
using string_type = std::basic_string< CharType, Traits, Alloc >
 The concrete string type used.
 

Public Member Functions

 command_info (string_type name, string_type description, creator creator, bool use_custom_argument_parsing=false)
 Initializes a new instance of the command_info class. More...
 
std::unique_ptr< command_typecreate (builder_type &builder) const
 Creates an instance of the subcommand type. More...
 
std::unique_ptr< command_typecreate_custom_parsing () const
 Creates an instance of the subcommand type for commands that use custom argument parsing. More...
 
const string_typedescription () const noexcept
 Gets the description of the subcommand.
 
const string_typename () const noexcept
 Gets the name of the subcommand.
 
bool use_custom_argument_parsing () const noexcept
 Gets a value that indicates whether the command uses custom argument parsing. More...
 

Static Public Member Functions

template<typename T , std::enable_if_t<!std::is_base_of_v< command_with_custom_parsing_type, T >, int > = 0>
static command_info create (string_type name, string_type description)
 Creates a command_info instance for the specified command type. More...
 
template<typename T , std::enable_if_t< std::is_base_of_v< command_with_custom_parsing_type, T >, int > = 0>
static command_info create (string_type name, string_type description)
 Creates a command_info instance for a command type that uses custom argument parsing. More...
 

Detailed Description

template<typename CharType, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
class ookii::command_info< CharType, Traits, Alloc >

Provides information about a subcommand.

Template Parameters
CharTypeThe character type used for arguments and other strings.
TraitsThe character traits to use for strings. Defaults to std::char_traits<CharType>.
AllocThe allocator to use for strings. Defaults to std::allocator<CharType>.

Constructor & Destructor Documentation

◆ command_info()

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
ookii::command_info< CharType, Traits, Alloc >::command_info ( string_type  name,
string_type  description,
creator  creator,
bool  use_custom_argument_parsing = false 
)
inline

Initializes a new instance of the command_info class.

Parameters
nameThe name of the subcommand.
descriptionThe description of the subcommand.
creatorA function that instantiates the subcommand.
use_custom_argument_parsingIndicates whether this command uses basic_command_with_custom_parsing as a base type.

Member Function Documentation

◆ create() [1/3]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
std::unique_ptr<command_type> ookii::command_info< CharType, Traits, Alloc >::create ( builder_type builder) const
inline

Creates an instance of the subcommand type.

Parameters
builderThe basic_parser_builder to pass to the subcommand type's constructor.
Returns
An instance of the subcommand type.

This function returns nullptr if this command uses custom argument parsing.

◆ create() [2/3]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename T , std::enable_if_t<!std::is_base_of_v< command_with_custom_parsing_type, T >, int > = 0>
static command_info ookii::command_info< CharType, Traits, Alloc >::create ( string_type  name,
string_type  description 
)
inlinestatic

Creates a command_info instance for the specified command type.

Template Parameters
TThe type of the subcommand, which must derive from basic_command.
Parameters
nameThe name of the subcommand.
descriptionThe description of the subcommand.

◆ create() [3/3]

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
template<typename T , std::enable_if_t< std::is_base_of_v< command_with_custom_parsing_type, T >, int > = 0>
static command_info ookii::command_info< CharType, Traits, Alloc >::create ( string_type  name,
string_type  description 
)
inlinestatic

Creates a command_info instance for a command type that uses custom argument parsing.

Template Parameters
TThe type of the subcommand, which must derive from basic_command.
Parameters
nameThe name of the subcommand.
descriptionThe description of the subcommand.

◆ create_custom_parsing()

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
std::unique_ptr<command_type> ookii::command_info< CharType, Traits, Alloc >::create_custom_parsing ( ) const
inline

Creates an instance of the subcommand type for commands that use custom argument parsing.

Returns
An instance of the subcommand type. This can safely be cast to the basic_command_with_custom_parsing class.

This function returns nullptr if this command does not use custom argument parsing.

◆ use_custom_argument_parsing()

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
bool ookii::command_info< CharType, Traits, Alloc >::use_custom_argument_parsing ( ) const
inlinenoexcept

Gets a value that indicates whether the command uses custom argument parsing.

Returns
true if the command type derives from the basic_command_with_custom_parsing class; otherwise, false.

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