C++ Utilities 5.27.0
Useful C++ classes and routines such as argument parser, IO and conversion utilities
Loading...
Searching...
No Matches
CppUtilities::ArgumentReader Class Reference

The ArgumentReader class internally encapsulates the process of reading command line arguments. More...

#include <argumentparserprivate.h>

Collaboration diagram for CppUtilities::ArgumentReader:
[legend]

Public Member Functions

 ArgumentReader (ArgumentParser &parser, const char *const *argv, const char *const *end, bool completionMode=false)
 Initializes the internal reader for the specified parser and arguments.
 
ArgumentReaderreset (const char *const *argv, const char *const *end)
 Resets the ArgumentReader to continue reading new argv.
 
bool read ()
 Reads the commands line arguments specified when constructing the object.
 
bool read (ArgumentVector &args)
 Reads the commands line arguments specified when constructing the object.
 

Public Attributes

ArgumentParserparser
 The associated ArgumentParser instance.
 
ArgumentVectorargs
 The Argument instances to store the results. Sub arguments of args are considered as well.
 
std::size_t index
 An index which is incremented when an argument is encountered (the current index is stored in the occurrence) or a value is encountered.
 
const char *const * argv
 Points to the first argument denotation and will be incremented when a denotation has been processed.
 
const char *const * end
 Points to the end of the argv array.
 
ArgumentlastArg
 The last Argument instance which could be detected. Set to nullptr in the initial call. Used for Bash completion.
 
const char *const * lastArgDenotation
 Points to the element in argv where lastArg was encountered. Unspecified if lastArg is not set.
 
const char * argDenotation
 The currently processed abbreviation denotation (should be substring of one of the args in argv). Set to nullptr for processing argv from the beginning (default).
 
unsigned char argDenotationType
 The type of the currently processed abbreviation denotation. Unspecified if argDenotation is not set.
 
bool completionMode
 Whether completion mode is enabled. In this case reading args will be continued even if an denotation is unknown (regardless of unknownArgumentBehavior()).
 

Detailed Description

The ArgumentReader class internally encapsulates the process of reading command line arguments.

Remarks
  • For meaning of parameters see documentation of corresponding member variables.
  • Results are stored in specified args and assigned sub arguments.
  • This class is explicitly not part of the public API.

Definition at line 9 of file argumentparserprivate.h.

Constructor & Destructor Documentation

◆ ArgumentReader()

CppUtilities::ArgumentReader::ArgumentReader ( ArgumentParser & parser,
const char *const * argv,
const char *const * end,
bool completionMode = false )

Initializes the internal reader for the specified parser and arguments.

Definition at line 126 of file argumentparser.cpp.

Member Function Documentation

◆ read() [1/2]

bool CppUtilities::ArgumentReader::read ( )

Reads the commands line arguments specified when constructing the object.

Remarks
Reads on main-argument-level.

Definition at line 155 of file argumentparser.cpp.

◆ read() [2/2]

bool CppUtilities::ArgumentReader::read ( ArgumentVector & args)

Reads the commands line arguments specified when constructing the object.

Remarks
The argument definitions to look for are specified via args. The method calls itself recursively to check for nested arguments as well.
Returns
Returns true if all arguments have been processed. Returns false on early exit because some argument is unknown and behavior for this case is set to UnknownArgumentBehavior::Fail.

Definition at line 175 of file argumentparser.cpp.

◆ reset()

ArgumentReader & CppUtilities::ArgumentReader::reset ( const char *const * argv,
const char *const * end )

Resets the ArgumentReader to continue reading new argv.

Definition at line 141 of file argumentparser.cpp.

Member Data Documentation

◆ argDenotation

const char* CppUtilities::ArgumentReader::argDenotation

The currently processed abbreviation denotation (should be substring of one of the args in argv). Set to nullptr for processing argv from the beginning (default).

Definition at line 31 of file argumentparserprivate.h.

◆ argDenotationType

unsigned char CppUtilities::ArgumentReader::argDenotationType

The type of the currently processed abbreviation denotation. Unspecified if argDenotation is not set.

Definition at line 33 of file argumentparserprivate.h.

◆ args

ArgumentVector& CppUtilities::ArgumentReader::args

The Argument instances to store the results. Sub arguments of args are considered as well.

Definition at line 19 of file argumentparserprivate.h.

◆ argv

const char* const* CppUtilities::ArgumentReader::argv

Points to the first argument denotation and will be incremented when a denotation has been processed.

Definition at line 23 of file argumentparserprivate.h.

◆ completionMode

bool CppUtilities::ArgumentReader::completionMode

Whether completion mode is enabled. In this case reading args will be continued even if an denotation is unknown (regardless of unknownArgumentBehavior()).

Definition at line 35 of file argumentparserprivate.h.

◆ end

const char* const* CppUtilities::ArgumentReader::end

Points to the end of the argv array.

Definition at line 25 of file argumentparserprivate.h.

◆ index

std::size_t CppUtilities::ArgumentReader::index

An index which is incremented when an argument is encountered (the current index is stored in the occurrence) or a value is encountered.

Definition at line 21 of file argumentparserprivate.h.

◆ lastArg

Argument* CppUtilities::ArgumentReader::lastArg

The last Argument instance which could be detected. Set to nullptr in the initial call. Used for Bash completion.

Definition at line 27 of file argumentparserprivate.h.

◆ lastArgDenotation

const char* const* CppUtilities::ArgumentReader::lastArgDenotation

Points to the element in argv where lastArg was encountered. Unspecified if lastArg is not set.

Definition at line 29 of file argumentparserprivate.h.

◆ parser

ArgumentParser& CppUtilities::ArgumentReader::parser

The associated ArgumentParser instance.

Definition at line 17 of file argumentparserprivate.h.


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