Ookii.CommandLine for C++  1.0.0
Namespaces | Classes | Typedefs | Enumerations | Functions | Variables
ookii Namespace Reference

Namespace containing the core Ookii.CommandLine.Cpp types. More...

Namespaces

 format
 Namespace containing helper functions for formatting.
 

Classes

class  basic_command_line_parser
 Parses command line arguments into strongly-typed values. More...
 
class  basic_line_wrapping_ostream
 Output stream that wraps lines on white-space characters at the specified line length, and with support for indentation. More...
 
class  basic_line_wrapping_streambuf
 Stream buffer that wraps lines on white-space characters at the specified line length, and with support for indentation. More...
 
class  basic_parser_builder
 Provides functionality to specify options and arguments to create a new basic_command_line_parser. More...
 
class  basic_shell_command
 Abstract base class for all shell commands. More...
 
class  basic_shell_command_manager
 Manages registration, creation and invocation of shell commands for an application. More...
 
class  basic_shell_command_usage_options
 Provides options for how to format usage help for applications using shell commands. More...
 
class  basic_usage_options
 Provides options for how to format usage help. More...
 
class  command_line_argument
 Class that provides information about arguments that are not multi-value arguments. More...
 
class  command_line_argument_base
 Abstract base class for regular and multi-value arguments. More...
 
struct  console_stream
 Template to determine the correct console streams based on the character type. More...
 
struct  console_stream< char >
 Specialization of console_stream for char. More...
 
struct  console_stream< wchar_t >
 Specialization of console_stream for wchar_t. More...
 
struct  lexical_convert
 Template class used to convert strings to strongly typed argument values. More...
 
struct  lexical_convert< bool, CharType, Traits, Alloc >
 Specialization of the lexical_convert template for conversion from string to bool. More...
 
struct  lexical_convert< std::basic_string< CharType, Traits, Alloc >, CharType, Traits, Alloc >
 Specialization of lexical_convert for strings. More...
 
class  multi_value_command_line_argument
 Class that provides information about arguments that are not multi-value arguments. More...
 
class  owned_or_borrowed_ptr
 Smart pointer that may or may not own the contained pointer. More...
 
struct  parse_result
 Provides the result, success or error, of a command line argument parsing operation. More...
 
class  shell_command_info
 Provides information about a shell command. More...
 
struct  string_convert
 Performs a simple conversion of a narrow character string to a specified character type. More...
 
struct  string_convert< char, Traits, Alloc >
 Specialization of string_convert where the target type is also char. More...
 
struct  string_less
 A version of the std::less predicate for strings that supports case insensitive comparison. More...
 
class  tokenize
 A pseudo-range for string tokenization. More...
 
struct  value_description
 Template used to specify the default value description for a type. More...
 
struct  value_description< std::basic_string< CharType2, Traits2, Alloc2 >, CharType, Traits, Alloc >
 Specialization of value_description for strings. More...
 
struct  value_description< std::optional< T >, CharType, Traits, Alloc >
 Specialization of value_description for std::optional<T>. More...
 

Typedefs

using command_line_parser = basic_command_line_parser< char >
 Typedef for basic_command_line_parser using char as the character type.
 
using line_wrapping_ostream = ookii::basic_line_wrapping_ostream< char >
 A line wrapping stream for use with the char type.
 
using line_wrapping_streambuf = basic_line_wrapping_streambuf< char >
 A line wrapping stream buffer for use with the char type.
 
using parser_builder = basic_parser_builder< char >
 Typedef for basic_shell_command using char as the character type.
 
using shell_command = basic_shell_command< char >
 Typedef for basic_shell_command using char as the character type.
 
using shell_command_manager = basic_shell_command_manager< char >
 Typedef for basic_shell_command_manager using char as the character type.
 
using shell_command_usage_options = basic_shell_command_usage_options< char >
 Typedef for basic_shell_command_usage_options using char as the character type.
 
using usage_options = basic_usage_options< char >
 Typedef for basic_usage_options using char as the character type.
 
using wcommand_line_parser = basic_command_line_parser< wchar_t >
 Typedef for basic_command_line_parser using wchar_t as the character type.
 
using wline_wrapping_ostream = ookii::basic_line_wrapping_ostream< wchar_t >
 A line wrapping stream for use with the wchar_t type.
 
using wline_wrapping_streambuf = basic_line_wrapping_streambuf< wchar_t >
 A line wrapping stream buffer for use with the wchar_t type.
 
using wparser_builder = basic_parser_builder< wchar_t >
 Typedef for basic_shell_command using wchar_t as the character type.
 
using wshell_command = basic_shell_command< wchar_t >
 Typedef for basic_shell_command using wchar_t as the character type.
 
using wshell_command_manager = basic_shell_command_manager< wchar_t >
 Typedef for basic_shell_command_manager using wchar_t as the character type.
 
using wshell_command_usage_options = basic_shell_command_usage_options< wchar_t >
 Typedef for basic_shell_command_usage_options using wchar_t as the character type.
 
using wusage_options = basic_usage_options< wchar_t >
 Typedef for basic_usage_options using wchar_t as the character type.
 

Enumerations

enum class  on_parsed_action { none , cancel_parsing , always_continue }
 Value to be returned from the callback passed to the basic_command_line_parser::on_parsed() method. More...
 
enum class  parse_error {
  none , parsing_cancelled , invalid_value , unknown_argument ,
  missing_value , duplicate_argument , too_many_arguments , missing_required_argument
}
 The type of error that occurred while parsing the command line. More...
 

Functions

short get_console_width (short default_width=80) noexcept
 Determines the width of the console. More...
 
template<typename T , typename CharType = char, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
auto get_short_type_name ()
 Gets the name of a type excluding the namespace name. More...
 
template<typename CharType = char, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
auto get_short_type_name (const std::type_info &type)
 Gets the name of a type excluding the namespace name. More...
 
template<typename T , typename CharType = char, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
auto get_type_name ()
 Gets the name of a type. More...
 
template<typename CharType = char, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
auto get_type_name (const std::type_info &type)
 Gets the name of a type. More...
 
template<typename CharType , size_t Length>
constexpr const std::array< CharType, Length > literal_cast (const char(&value)[Length])
 Converts a simple ASCII string literal to the specified character type at compile time. More...
 
template<typename T , typename... Args>
auto make_owned_ptr (Args &&... args)
 Creates a new instance of the owned_or_borrowed_ptr that owns the contained pointer, by constructing a new object of type T with the specified arguments. More...
 
template<typename CharType , typename Traits >
std::basic_ostream< CharType, Traits > & reset_indent (std::basic_ostream< CharType, Traits > &stream)
 IO manipulator that lets the next line start at the beginning of the line, without indenting it. More...
 
details::set_indent_helper set_indent (size_t indent)
 IO manipulator that changes the number of spaces that each line is indented with for a line wrapping stream. More...
 
template<typename CharType , typename Traits >
bool string_equal_case_insensitive (std::basic_string_view< CharType, Traits > string1, std::basic_string_view< CharType, Traits > string2, const std::locale &locale={})
 Compares two strings, ignoring their case. More...
 
template<typename T >
void swap (owned_or_borrowed_ptr< T > &left, owned_or_borrowed_ptr< T > &right) noexcept
 Swaps two owned_or_borrowed_ptr instances. More...
 

Variables

constexpr size_t use_console_width = std::numeric_limits<size_t>::max()
 Indicates that the basic_line_wrapping_streambuf should use the console width as the line length.
 

Detailed Description

Namespace containing the core Ookii.CommandLine.Cpp types.

This namespace defines all the types needed to use Ookii.CommandLine.Cpp, including basic_command_line_parser and basic_parser_builder. It also defines utility types such as basic_line_wrapping_ostream.

Enumeration Type Documentation

◆ on_parsed_action

Value to be returned from the callback passed to the basic_command_line_parser::on_parsed() method.

Enumerator
none 

Don't take any special action.

cancel_parsing 

Cancel parsing immediately, disregarding the rest of the command line. Parsing will return with parse_error::parsing_cancelled.

always_continue 

Continue parsing even if command_line_argument::cancel_parsing() returns true.

◆ parse_error

enum ookii::parse_error
strong

The type of error that occurred while parsing the command line.

Enumerator
none 

No error occurred.

parsing_cancelled 

Parsing was cancelled by an argument using basic_parser_builder::argument_builder::cancel_parsing(), or the by the basic_command_line_parser::on_parsed() callback.

While this is treated as a parsing failure, this is not technically an error, and no error message is associated with it.

invalid_value 

A supplied value could not be converted to the argument's type.

unknown_argument 

An argument name was supplied that doesn't exist.

missing_value 

A named argument, other than a switch argument, was supplied without a value.

duplicate_argument 

An argument, other than a multi-value argument, was supplied more than once, and basic_parser_builder::allow_duplicate_arguments() was not enabled.

too_many_arguments 

More positional arguments were supplied than were defined.

missing_required_argument 

One of the required arguments was not supplied.

Function Documentation

◆ get_console_width()

short ookii::get_console_width ( short  default_width = 80)
inlinenoexcept

Determines the width of the console.

This function returns the width of the console attached to stdout. If stdout is redirected to a file, it's platform dependent whether the width is still returned.

Parameters
default_widthThe width to assume if the actual width can't be determined.

◆ get_short_type_name() [1/2]

template<typename T , typename CharType = char, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
auto ookii::get_short_type_name ( )
inline

Gets the name of a type excluding the namespace name.

On g++, this demangles the type name before returning it. On VC++, it also strips the "class" or "struct" prefix.

Template Parameters
TThe type whose name to return.
CharTypeThe character type to use for the returned string.
TraitsThe character traits to use.
AllocThe allocator to use.

◆ get_short_type_name() [2/2]

template<typename CharType = char, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
auto ookii::get_short_type_name ( const std::type_info &  type)
inline

Gets the name of a type excluding the namespace name.

On g++, this demangles the type name before returning it. On VC++, it also strips the "class" or "struct" prefix.

Template Parameters
CharTypeThe character type to use for the returned string.
TraitsThe character traits to use.
AllocThe allocator to use.
Parameters
typeThe type_info for the type.

◆ get_type_name() [1/2]

template<typename T , typename CharType = char, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
auto ookii::get_type_name ( )
inline

Gets the name of a type.

On g++, this demangles the type name before returning it.

Template Parameters
TThe type whose name to return.
CharTypeThe character type to use for the returned string.
TraitsThe character traits to use.
AllocThe allocator to use.

◆ get_type_name() [2/2]

template<typename CharType = char, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
auto ookii::get_type_name ( const std::type_info &  type)
inline

Gets the name of a type.

On g++, this demangles the type name before returning it.

Template Parameters
CharTypeThe character type to use for the returned string.
TraitsThe character traits to use.
AllocThe allocator to use.
Parameters
typeThe type_info for the type.

◆ literal_cast()

template<typename CharType , size_t Length>
constexpr const std::array<CharType, Length> ookii::literal_cast ( const char(&)  value[Length])
constexpr

Converts a simple ASCII string literal to the specified character type at compile time.

This function is intended to be used on simple literals, to allow template functions to use string literals where the character type depends on the template parameters.

Warning
This function simply copies the source array to the target array, and will not work correctly if the source array contains multi-byte characters.
Template Parameters
CharTypeThe target character type.
LengthThe length of the string.
Parameters
valueThe character sequence to convert.
Returns
A std::array holding the converted character sequence.

◆ make_owned_ptr()

template<typename T , typename... Args>
auto ookii::make_owned_ptr ( Args &&...  args)

Creates a new instance of the owned_or_borrowed_ptr that owns the contained pointer, by constructing a new object of type T with the specified arguments.

Template Parameters
TThe type of the object to construct.
ArgsThe types of the constructor arguments.
Parameters
argsThe constructor arguments.
Returns
A owned_or_borrowed_ptr that owns the constructed object.

◆ reset_indent()

template<typename CharType , typename Traits >
std::basic_ostream<CharType, Traits>& ookii::reset_indent ( std::basic_ostream< CharType, Traits > &  stream)

IO manipulator that lets the next line start at the beginning of the line, without indenting it.

Attention
If the last character written to the buffer was not a new line, one is inserted.
This has no effect if the stream does not use a basic_line_wrapping_streambuf.
Warning
This IO manipulator uses dynamic_cast and may require RTTI.

Sample:

stream << reset_indent;
std::basic_ostream< CharType, Traits > & reset_indent(std::basic_ostream< CharType, Traits > &stream)
IO manipulator that lets the next line start at the beginning of the line, without indenting it.
Definition: line_wrapping_stream.h:515
Template Parameters
CharTypeThe character type of the stream.
TraitsThe character traits type of the stream.
Parameters
streamThe stream to write to.

◆ set_indent()

details::set_indent_helper ookii::set_indent ( size_t  indent)
inline

IO manipulator that changes the number of spaces that each line is indented with for a line wrapping stream.

Attention
This has no effect if the stream does not use a basic_line_wrapping_streambuf.
Warning
This IO manipulator uses dynamic_cast and may require RTTI.

Sample:

stream << set_indent(4);
details::set_indent_helper set_indent(size_t indent)
IO manipulator that changes the number of spaces that each line is indented with for a line wrapping ...
Definition: line_wrapping_stream.h:493
Parameters
indentThe new indentation size.

◆ string_equal_case_insensitive()

template<typename CharType , typename Traits >
bool ookii::string_equal_case_insensitive ( std::basic_string_view< CharType, Traits >  string1,
std::basic_string_view< CharType, Traits >  string2,
const std::locale &  locale = {} 
)

Compares two strings, ignoring their case.

Template Parameters
CharTypeThe character type used.
TraitsThe character traits used.
Parameters
string1The first string.
string2The second string.
localeThe locale to use for case conversion.
Returns
true if the strings are equal, ignoring case; otherwise, false.

◆ swap()

template<typename T >
void ookii::swap ( owned_or_borrowed_ptr< T > &  left,
owned_or_borrowed_ptr< T > &  right 
)
noexcept

Swaps two owned_or_borrowed_ptr instances.

Parameters
leftThe first instance to swap.
rightThe second instance to swap.