Ookii.CommandLine for C++  1.0.0
Public Types | Public Member Functions | Public Attributes | List of all members
ookii::parse_result< CharType, Traits, Alloc > Struct Template Reference

Provides the result, success or error, of a command line argument parsing operation. More...

#include <ookii/parse_result.h>

Collaboration diagram for ookii::parse_result< CharType, Traits, Alloc >:
Collaboration graph
[legend]

Public Types

using string_type = std::basic_string< CharType, Traits, Alloc >
 The concrete string type used by this structure.
 

Public Member Functions

 parse_result (parse_error error=parse_error::none, string_type error_arg_name={})
 Initializes a new instance of the parse_result structure. More...
 
string_type get_error_message (const std::locale &loc={}) const
 Gets a default, English language error message for the current error. More...
 
 operator bool () const noexcept
 Checks if the result was successful. More...
 

Public Attributes

parse_error error
 The type of error that occurred, or parse_error::none to indicate no error.
 
string_type error_arg_name
 The name of the argument that caused the error, or a blank string if there was no error or the error doesn't relate to a specific argument.
 

Detailed Description

template<typename CharType, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
struct ookii::parse_result< CharType, Traits, Alloc >

Provides the result, success or error, of a command line argument parsing operation.

This type is returned from the various basic_command_line_parser::parse() overloads to indicate success or failure. Inspect the value to see if parsing was successful.

Warning
Command line argument parsing is not atomic; if a value indicating failure is returned, some of the arguments could have already been successfully parsed and their variables set to the supplied values.
Template Parameters
CharTypeThe character type used for argument names and error 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

◆ parse_result()

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
ookii::parse_result< CharType, Traits, Alloc >::parse_result ( parse_error  error = parse_error::none,
string_type  error_arg_name = {} 
)
inline

Initializes a new instance of the parse_result structure.

Parameters
errorThe type of error that occurred, or parse_error::none to indicate no error.
error_arg_nameThe name of the argument that caused the error, or a blank string if there was no error or the error doesn't relate to a specific argument.

Member Function Documentation

◆ get_error_message()

template<typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
string_type ookii::parse_result< CharType, Traits, Alloc >::get_error_message ( const std::locale &  loc = {}) const
inline

Gets a default, English language error message for the current error.

If appropriate, the message will include the name of the argument that caused the error.

Parameters
locThe locale to use to format the error message.
Returns
The error message, or a blank string for parse_error::none and parse_error::parsing_cancelled.

◆ operator bool()

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

Checks if the result was successful.

Returns
true only if the error is parse_error::none; otherwise, false.

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