Option++  2.0
C++ library for reading command-line options
Public Types | Public Member Functions | List of all members
optionpp::parser_result Class Reference

Holds data that was parsed from the program command line. More...

#include <parser_result.hpp>

Public Types

using value_type = parsed_entry
 Type used for storing argument data.
 
using container_type = std::vector< value_type >
 Type of container used to store the data entries.
 
using size_type = container_type::size_type
 Unsigned integer type (usually std::size_t) that can hold container size.
 
using iterator = container_type::iterator
 Plain iterator type.
 
using const_iterator = container_type::const_iterator
 Constant iterator type.
 
using reverse_iterator = container_type::reverse_iterator
 Reverse iterator type.
 
using const_reverse_iterator = container_type::const_reverse_iterator
 Constant reverse iterator type.
 

Public Member Functions

 parser_result () noexcept
 Default constructor. More...
 
 parser_result (const std::initializer_list< value_type > &il)
 Construct from an initializer list. More...
 
template<typename InputIt >
 parser_result (InputIt first, InputIt last)
 Construct from a sequence. More...
 
void push_back (const value_type &entry)
 Add a parsed_entry to the back of the container. More...
 
void push_back (value_type &&entry)
 Add a parsed_entry to the back of the container. More...
 
void clear () noexcept
 Erase all data entries currently stored.
 
size_type size () const noexcept
 Return the number of data entries. More...
 
bool empty () const noexcept
 Return whether the container is empty. More...
 
iterator begin () noexcept
 Return an iterator to the beginning of the container. More...
 
const_iterator begin () const noexcept
 Return a const_iterator to the beginning of the container. More...
 
iterator end () noexcept
 Return an iterator to the end of the container. More...
 
const_iterator end () const noexcept
 Return a const_iterator to the end of the container. More...
 
const_iterator cbegin () const noexcept
 Return a const_iterator to the beginning of the container. More...
 
const_iterator cend () const noexcept
 Return a const_iterator to the end of the container. More...
 
reverse_iterator rbegin () noexcept
 Return a reverse_iterator to the beginning. More...
 
const_reverse_iterator rbegin () const noexcept
 Return a const_reverse_iterator to the beginning. More...
 
reverse_iterator rend () noexcept
 Return a reverse_iterator to the end. More...
 
const_reverse_iterator rend () const noexcept
 Return a const_reverse_iterator to the end. More...
 
const_reverse_iterator crbegin () const noexcept
 Return a const_reverse_iterator to the beginning. More...
 
const_reverse_iterator crend () const noexcept
 Return a const_reverse_iterator to the end. More...
 
value_typeat (size_type index)
 Range-checked subscript. More...
 
const value_typeat (size_type index) const
 Range-checked subscript. More...
 
value_typeoperator[] (size_type index)
 Subscript operator. More...
 
const value_typeoperator[] (size_type index) const
 Subscript operator. More...
 
value_typeback ()
 Access last entry in the container. More...
 
const value_typeback () const
 Access last entry in the container. More...
 
bool is_option_set (const std::string &long_name) const noexcept
 Returns whether the specified option is set. More...
 
bool is_option_set (char short_name) const noexcept
 Returns whether the specified option is set. More...
 
std::string get_argument (std::string long_name) const noexcept
 Get the argument for the specified option. More...
 
std::string get_argument (char short_name) const noexcept
 Get the argument for the specified option. More...
 

Detailed Description

Holds data that was parsed from the program command line.

This is a container of parsed_entry instances that describe all the program options that were set on the command line as well as all non-option arguments, all in the order in which they were originally specified.

For example, if the user ran the program with the command

myprogram -afn file1.txt file2.txt --verbose file3.txt

then the corresponding parser_result would hold seven data entries: -a, -f, -n, file1.txt, file2.txt, --verbose, file3.txt, in that order.

Constructor & Destructor Documentation

◆ parser_result() [1/3]

optionpp::parser_result::parser_result ( )
inlinenoexcept

Default constructor.

Constructs an empty parser_result.

◆ parser_result() [2/3]

optionpp::parser_result::parser_result ( const std::initializer_list< value_type > &  il)
inline

Construct from an initializer list.

Parameters
ilThe initializer_list holding the parsed data.

◆ parser_result() [3/3]

template<typename InputIt >
optionpp::parser_result::parser_result ( InputIt  first,
InputIt  last 
)
inline

Construct from a sequence.

Template Parameters
InputItThe type of iterator (usually deduced).
Parameters
firstIterator pointing to the beginning of the sequence.
lastIterator pointing to one past the end of the sequence.

Member Function Documentation

◆ at() [1/2]

value_type& optionpp::parser_result::at ( size_type  index)
inline

Range-checked subscript.

Parameters
indexThe index of the parsed_entry to return.
Returns
The parsed data entry corresponding to the index.
Exceptions
out_of_rangeThrown if index >= size().

◆ at() [2/2]

const value_type& optionpp::parser_result::at ( size_type  index) const
inline

Range-checked subscript.

Parameters
indexThe index of the parsed_entry to return.
Returns
The parsed data entry corresponding to the index.
Exceptions
out_of_rangeThrown if index >= size().

◆ back() [1/2]

value_type& optionpp::parser_result::back ( )
inline

Access last entry in the container.

Exceptions
out_of_rangeIf container is empty.
Returns
Reference to last parsed_entry.

◆ back() [2/2]

const value_type& optionpp::parser_result::back ( ) const
inline

Access last entry in the container.

Exceptions
out_of_rangeIf container is empty.
Returns
Reference to last parsed_entry.

◆ begin() [1/2]

const_iterator optionpp::parser_result::begin ( ) const
inlinenoexcept

Return a const_iterator to the beginning of the container.

Returns
A const_iterator pointing to the first entry.

◆ begin() [2/2]

iterator optionpp::parser_result::begin ( )
inlinenoexcept

Return an iterator to the beginning of the container.

Returns
An iterator pointing to the first entry.

◆ cbegin()

const_iterator optionpp::parser_result::cbegin ( ) const
inlinenoexcept

Return a const_iterator to the beginning of the container.

Returns
A const_iterator pointing to the first entry.

◆ cend()

const_iterator optionpp::parser_result::cend ( ) const
inlinenoexcept

Return a const_iterator to the end of the container.

Returns
A const_iterator pointing to one past the last entry.

◆ crbegin()

const_reverse_iterator optionpp::parser_result::crbegin ( ) const
inlinenoexcept

Return a const_reverse_iterator to the beginning.

Returns
A const_reverse_iterator pointing to the first entry in the reversed sequence.

◆ crend()

const_reverse_iterator optionpp::parser_result::crend ( ) const
inlinenoexcept

Return a const_reverse_iterator to the end.

Returns
A const_reverse_iterator pointing to one past the last entry in the reversed sequence.

◆ empty()

bool optionpp::parser_result::empty ( ) const
inlinenoexcept

Return whether the container is empty.

Returns
True if the entry container is empty, false otherwise.

◆ end() [1/2]

const_iterator optionpp::parser_result::end ( ) const
inlinenoexcept

Return a const_iterator to the end of the container.

Returns
A const_iterator pointing to one past the last entry.

◆ end() [2/2]

iterator optionpp::parser_result::end ( )
inlinenoexcept

Return an iterator to the end of the container.

Returns
An iterator pointing to one past the last entry.

◆ get_argument() [1/2]

std::string optionpp::parser_result::get_argument ( char  short_name) const
noexcept

Get the argument for the specified option.

If no argument was given, an empty string is returned. If multiple arguments were given, the last is returned.

Parameters
short_nameThe short name for the option.
Returns
The argument given to the option.

◆ get_argument() [2/2]

std::string optionpp::parser_result::get_argument ( std::string  long_name) const
noexcept

Get the argument for the specified option.

If no argument was given, an empty string is returned. If multiple arguments were given, the last is returned.

Parameters
long_nameThe long name for the option.
Returns
The argument given to the option.

◆ is_option_set() [1/2]

bool optionpp::parser_result::is_option_set ( char  short_name) const
noexcept

Returns whether the specified option is set.

Parameters
short_nameThe short name for the option.
Returns
True if the option was present on the command-line, and false otherwise.

◆ is_option_set() [2/2]

bool optionpp::parser_result::is_option_set ( const std::string &  long_name) const
noexcept

Returns whether the specified option is set.

Parameters
long_nameThe long name for the option.
Returns
True if the option was present on the command-line, and false otherwise.

◆ operator[]() [1/2]

value_type& optionpp::parser_result::operator[] ( size_type  index)
inline

Subscript operator.

Parameters
indexThe index of the data entry to return.
Returns
The parsed_entry corresponding to the index.

◆ operator[]() [2/2]

const value_type& optionpp::parser_result::operator[] ( size_type  index) const
inline

Subscript operator.

Parameters
indexThe index of the data entry to return.
Returns
The parsed_entry corresponding to the index.

◆ push_back() [1/2]

void optionpp::parser_result::push_back ( const value_type entry)
inline

Add a parsed_entry to the back of the container.

Parameters
entryThe parsed data entry to add.

◆ push_back() [2/2]

void optionpp::parser_result::push_back ( value_type &&  entry)
inline

Add a parsed_entry to the back of the container.

Parameters
entryThe parsed data entry to add.

◆ rbegin() [1/2]

const_reverse_iterator optionpp::parser_result::rbegin ( ) const
inlinenoexcept

Return a const_reverse_iterator to the beginning.

Returns
A const_reverse_iterator pointing to the first entry in the reversed sequence.

◆ rbegin() [2/2]

reverse_iterator optionpp::parser_result::rbegin ( )
inlinenoexcept

Return a reverse_iterator to the beginning.

Returns
A reverse_iterator pointing to the first entry in the reversed sequence.

◆ rend() [1/2]

const_reverse_iterator optionpp::parser_result::rend ( ) const
inlinenoexcept

Return a const_reverse_iterator to the end.

Returns
A const_reverse_iterator pointing to one past the last entry in the reversed sequence.

◆ rend() [2/2]

reverse_iterator optionpp::parser_result::rend ( )
inlinenoexcept

Return a reverse_iterator to the end.

Returns
A reverse_iterator pointing to one past the last entry in the reversed sequence.

◆ size()

size_type optionpp::parser_result::size ( ) const
inlinenoexcept

Return the number of data entries.

This will be the total number of options and non-option arguments that were specified.

Returns
The number of option and non-option argument data entries.

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