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

The Argument class is a wrapper for command line argument information. More...

#include <argumentparser.h>

Inheritance diagram for CppUtilities::Argument:
[legend]

Public Types

enum class  Flags : std::uint64_t {
  None = 0x0 , Combinable = 0x1 , Implicit = 0x2 , Operation = 0x4 ,
  Deprecated = 0x8 , Greedy = 0x10
}
 The Flags enum specifies options for treating the argument in a special way. More...
 
typedef std::function< void(const ArgumentOccurrence &)> CallbackFunction
 

Public Member Functions

 Argument (const char *name, char abbreviation='\0', const char *description=nullptr, const char *example=nullptr)
 Constructs an Argument with the given name, abbreviation and description.
 
 ~Argument ()
 Destroys the Argument.
 
const char * name () const
 Returns the name of the argument.
 
void setName (const char *name)
 Sets the name of the argument.
 
char abbreviation () const
 Returns the abbreviation of the argument.
 
void setAbbreviation (char abbreviation)
 Sets the abbreviation of the argument.
 
const char * environmentVariable () const
 Returns the environment variable queried when firstValue() is called.
 
void setEnvironmentVariable (const char *environmentVariable)
 Sets the environment variable queried when firstValue() is called.
 
const char * description () const
 Returns the description of the argument.
 
void setDescription (const char *description)
 Sets the description of the argument.
 
const char * example () const
 Returns the usage example of the argument.
 
void setExample (const char *example)
 Sets the a usage example for the argument.
 
std::size_t requiredValueCount () const
 Returns the number of values which are required to be given for this argument.
 
void setRequiredValueCount (std::size_t requiredValueCount)
 Sets the number of values which are required to be given for this argument.
 
const std::vector< const char * > & valueNames () const
 Returns the names of the required values.
 
void setValueNames (std::initializer_list< const char * > valueNames)
 Sets the names of the required values.
 
void appendValueName (const char *valueName)
 Appends a value name.
 
void setConstraints (std::size_t minOccurrences, std::size_t maxOccurrences)
 Sets the allowed number of occurrences.
 
const std::vector< Argument * > & path (std::size_t occurrence=0) const
 Returns the path of the specified occurrence.
 
bool isRequired () const
 Returns an indication whether the argument is mandatory.
 
void setRequired (bool required)
 Sets whether this argument is mandatory or not.
 
Argument::Flags flags () const
 Returns Argument::Flags for the argument.
 
void setFlags (Argument::Flags flags)
 Replaces all Argument::Flags for the argument with the flags.
 
void setFlags (Argument::Flags flags, bool add)
 Adds or removes the specified flags.
 
bool isCombinable () const
 Returns an indication whether the argument is combinable.
 
void setCombinable (bool combinable)
 Sets whether this argument can be combined.
 
bool isImplicit () const
 Returns an indication whether the argument is an implicit argument.
 
void setImplicit (bool implicit)
 Sets whether the argument is an implicit argument.
 
bool denotesOperation () const
 Returns whether the argument denotes an operation.
 
void setDenotesOperation (bool denotesOperation)
 Sets whether the argument denotes the operation.
 
const CallbackFunctioncallback () const
 Returns the assigned callback function.
 
void setCallback (CallbackFunction callback)
 Sets a callback function which will be called by the parser if the argument could be found and no parsing errors occurred.
 
const ArgumentVectorsubArguments () const
 Returns the secondary arguments for this argument.
 
void setSubArguments (const ArgumentInitializerList &subArguments)
 Sets the secondary arguments for this argument.
 
void addSubArguments (const ArgumentInitializerList &subArguments)
 Sets the secondary arguments for this argument.
 
void addSubArgument (Argument *arg)
 Adds arg as a secondary argument for this argument.
 
bool hasSubArguments () const
 Returns an indication whether the argument has secondary arguments.
 
const ArgumentVectorparents () const
 Returns the parents of this argument.
 
void printInfo (std::ostream &os, unsigned char indentation=0) const
 Writes the name, the abbreviation and other information about the Argument to the give ostream.
 
ValueCompletionBehavior valueCompletionBehaviour () const
 Returns the items to be considered when generating completion for the values.
 
void setValueCompletionBehavior (ValueCompletionBehavior valueCompletionBehaviour)
 Sets the items to be considered when generating completion for the values.
 
const char * preDefinedCompletionValues () const
 Returns the assigned values used when generating completion for the values.
 
void setPreDefinedCompletionValues (const char *preDefinedCompletionValues)
 Assigns the values to be used when generating completion for the values.
 
const std::vector< const char * > & values (std::size_t occurrence=0) const
 Returns the parameter values for the specified occurrence of argument.
 
template<typename... TargetType>
std::tuple< TargetType... > valuesAs (std::size_t occurrence=0) const
 Converts the present values for the specified occurrence to the specified target types.
 
template<typename... TargetType>
std::vector< std::tuple< TargetType... > > allValuesAs () const
 Converts the present values for all occurrence to the specified target types.
 
const char * firstValue () const
 Returns the first parameter value of the first occurrence of the argument.
 
const char * firstValueOr (const char *fallback) const
 Returns the first value like Argument::firstValue() but returns fallback instead of nullptr if there's no value.
 
bool allRequiredValuesPresent (std::size_t occurrence=0) const
 Returns an indication whether all required values are present.
 
bool isPresent () const
 Returns an indication whether the argument could be detected when parsing.
 
std::size_t occurrences () const
 Returns how often the argument could be detected when parsing.
 
std::size_t index (std::size_t occurrence) const
 Returns the indices of the argument's occurrences which could be detected when parsing.
 
std::size_t minOccurrences () const
 Returns the minimum number of occurrences.
 
std::size_t maxOccurrences () const
 Returns the maximum number of occurrences.
 
bool isDeprecated () const
 
const ArgumentdeprecatedBy () const
 Returns the argument which obsoletes this argument.
 
void markAsDeprecated (const Argument *deprecatedBy=nullptr)
 Marks the argument as deprecated.
 
bool isMainArgument () const
 Returns an indication whether the argument is used as main argument.
 
bool isParentPresent () const
 Returns whether at least one parent argument is present.
 
ArgumentconflictsWithArgument () const
 Checks if this arguments conflicts with other arguments.
 
ArgumentwouldConflictWithArgument () const
 Checks if this argument would conflict with other arguments if it was present.
 
ArgumentspecifiedOperation () const
 Returns the first operation argument specified by the user or nullptr if no operation has been specified.
 
const std::vector< ArgumentOccurrence > & occurrenceInfo () const
 Returns information about all occurrences of the argument which have been detected when parsing.
 
std::vector< ArgumentOccurrence > & occurrenceInfo ()
 Returns information about all occurrences of the argument which have been detected when parsing.
 
void reset ()
 Resets occurrences (indices, values and paths).
 
void resetRecursively ()
 Resets this argument and all sub arguments recursively.
 

Static Public Attributes

static constexpr std::size_t varValueCount = std::numeric_limits<std::size_t>::max()
 Denotes a variable number of values.
 

Detailed Description

The Argument class is a wrapper for command line argument information.

Instances of the Argument class are used as definition when parsing command line arguments. Arguments can be assigned to an ArgumentParser using ArgumentParser::setMainArguments() and to another Argument instance using Argument::setSubArguments().

Definition at line 263 of file argumentparser.h.

Member Typedef Documentation

◆ CallbackFunction

Definition at line 269 of file argumentparser.h.

Member Enumeration Documentation

◆ Flags

enum class CppUtilities::Argument::Flags : std::uint64_t
strong

The Flags enum specifies options for treating the argument in a special way.

Enumerator
None 

No flags are present. The default for Argument().

Combinable 

It is no error if this argument occurs besides other arguments on the same level. The default for ConfigValueArgument.

Implicit 

The argument is assumed to be present if its values are present. Only one argument can be implicit at the same level.

Operation 

The argument is an operation, so no -- prefix is required when specifying it. The default for OperationArgument().

Deprecated 

The argument is considered deprecated and therefore excluded from the help.

Greedy 

The argument is "greedy" so when Argument::varValueCount is used all subsequent arguments will be considered values of that argument. This is useful to pass remaining arguments down to another argument parser as-is.

Definition at line 272 of file argumentparser.h.

Constructor & Destructor Documentation

◆ Argument()

CppUtilities::Argument::Argument ( const char * name,
char abbreviation = '\0',
const char * description = nullptr,
const char * example = nullptr )

Constructs an Argument with the given name, abbreviation and description.

The name and the abbreviation mustn't contain any whitespaces. The name mustn't be empty. The abbreviation and the description might be empty.

Definition at line 463 of file argumentparser.cpp.

◆ ~Argument()

CppUtilities::Argument::~Argument ( )

Destroys the Argument.

Definition at line 484 of file argumentparser.cpp.

Member Function Documentation

◆ abbreviation()

char CppUtilities::Argument::abbreviation ( ) const
inline

Returns the abbreviation of the argument.

The parser compares the abbreviation with the characters following a "-" prefix to identify arguments.

Definition at line 550 of file argumentparser.h.

◆ addSubArgument()

void CppUtilities::Argument::addSubArgument ( Argument * arg)

Adds arg as a secondary argument for this argument.

See also
secondaryArguments()
setSubArguments()
hasSubArguments()

Definition at line 666 of file argumentparser.cpp.

◆ addSubArguments()

void CppUtilities::Argument::addSubArguments ( const ArgumentInitializerList & subArguments)

Sets the secondary arguments for this argument.

The given arguments will be considered as secondary arguments of this argument by the argument parser. This means that the parser will complain if these arguments are given, but not this argument. If secondary arguments are labeled as mandatory their parent is also mandatory.

The Argument does not take ownership. Do not destroy the given arguments as long as they are used as secondary arguments.

See also
setSubArguments()
secondaryArguments()
addSecondaryArgument()
hasSubArguments()

Definition at line 643 of file argumentparser.cpp.

◆ allRequiredValuesPresent()

bool CppUtilities::Argument::allRequiredValuesPresent ( std::size_t occurrence = 0) const
inline

Returns an indication whether all required values are present.

Definition at line 718 of file argumentparser.h.

◆ allValuesAs()

template<typename... TargetType>
std::vector< std::tuple< TargetType... > > CppUtilities::Argument::allValuesAs ( ) const

Converts the present values for all occurrence to the specified target types.

For each occurrence, there must be as many values present as types are specified.

Exceptions
ThrowsArgumentUtilities::Failure when the number of present values is not sufficient or a conversion error occurs.
Remarks
Still experimental. Might be removed/adjusted in next minor release.

Definition at line 421 of file argumentparser.h.

◆ appendValueName()

void CppUtilities::Argument::appendValueName ( const char * valueName)
inline

Appends a value name.

The value names names will be shown when printing information about the argument.

See also
setValueNames()
valueNames()

Definition at line 710 of file argumentparser.h.

◆ callback()

const Argument::CallbackFunction & CppUtilities::Argument::callback ( ) const
inline

Returns the assigned callback function.

See also
setCallback()

Definition at line 941 of file argumentparser.h.

◆ conflictsWithArgument()

Argument * CppUtilities::Argument::conflictsWithArgument ( ) const

Checks if this arguments conflicts with other arguments.

If the argument is in conflict with an other argument this argument will be returned. Otherwise nullptr will be returned.

Remarks
Conflicts with main arguments aren't considered by this method!

Definition at line 702 of file argumentparser.cpp.

◆ denotesOperation()

bool CppUtilities::Argument::denotesOperation ( ) const
inline

Returns whether the argument denotes an operation.

An argument which denotes an operation might be specified without "--" or "-" prefix.

The default value is false, except for OperationArgument instances.

See also
setDenotesOperation()

Definition at line 923 of file argumentparser.h.

◆ deprecatedBy()

const Argument * CppUtilities::Argument::deprecatedBy ( ) const
inline

Returns the argument which obsoletes this argument.

Definition at line 794 of file argumentparser.h.

◆ description()

const char * CppUtilities::Argument::description ( ) const
inline

Returns the description of the argument.

The parser uses the description when printing help information.

Definition at line 592 of file argumentparser.h.

◆ environmentVariable()

const char * CppUtilities::Argument::environmentVariable ( ) const
inline

Returns the environment variable queried when firstValue() is called.

See also
firstValue(), setEnvironmentVariable()

Definition at line 573 of file argumentparser.h.

◆ example()

const char * CppUtilities::Argument::example ( ) const
inline

Returns the usage example of the argument.

The parser uses the description when printing help information.

Definition at line 612 of file argumentparser.h.

◆ firstValue()

const char * CppUtilities::Argument::firstValue ( ) const

Returns the first parameter value of the first occurrence of the argument.

Remarks
  • If the argument is not present and the an environment variable has been set using setEnvironmentVariable() the value of the specified variable will be returned.
  • Returns nullptr if no value is available though.

Definition at line 495 of file argumentparser.cpp.

◆ firstValueOr()

const char * CppUtilities::Argument::firstValueOr ( const char * fallback) const

Returns the first value like Argument::firstValue() but returns fallback instead of nullptr if there's no value.

Definition at line 509 of file argumentparser.cpp.

◆ flags()

Argument::Flags CppUtilities::Argument::flags ( ) const
inline

Returns Argument::Flags for the argument.

Definition at line 864 of file argumentparser.h.

◆ hasSubArguments()

bool CppUtilities::Argument::hasSubArguments ( ) const
inline

Returns an indication whether the argument has secondary arguments.

See also
secondaryArguments()
setSubArguments()

Definition at line 974 of file argumentparser.h.

◆ index()

std::size_t CppUtilities::Argument::index ( std::size_t occurrence) const
inline

Returns the indices of the argument's occurrences which could be detected when parsing.

Definition at line 761 of file argumentparser.h.

◆ isCombinable()

bool CppUtilities::Argument::isCombinable ( ) const
inline

Returns an indication whether the argument is combinable.

The parser will complain if two arguments labeled as uncombinable are present at the same time.

See also
setCombinable()

Definition at line 895 of file argumentparser.h.

◆ isDeprecated()

bool CppUtilities::Argument::isDeprecated ( ) const
inline

Definition at line 786 of file argumentparser.h.

◆ isImplicit()

bool CppUtilities::Argument::isImplicit ( ) const
inline

Returns an indication whether the argument is an implicit argument.

See also
setImplicit()

Definition at line 728 of file argumentparser.h.

◆ isMainArgument()

bool CppUtilities::Argument::isMainArgument ( ) const
inline

Returns an indication whether the argument is used as main argument.

An argument used as main argument shouldn't be used as secondary arguments at the same time.

Definition at line 1000 of file argumentparser.h.

◆ isParentPresent()

bool CppUtilities::Argument::isParentPresent ( ) const

Returns whether at least one parent argument is present.

Remarks
Returns always true for main arguments.

Definition at line 681 of file argumentparser.cpp.

◆ isPresent()

bool CppUtilities::Argument::isPresent ( ) const
inline

Returns an indication whether the argument could be detected when parsing.

Definition at line 745 of file argumentparser.h.

◆ isRequired()

bool CppUtilities::Argument::isRequired ( ) const
inline

Returns an indication whether the argument is mandatory.

The parser will complain if a mandatory argument is not present.

The default value is false.

See also
setRequired()

Definition at line 838 of file argumentparser.h.

◆ markAsDeprecated()

void CppUtilities::Argument::markAsDeprecated ( const Argument * deprecatedBy = nullptr)
inline

Marks the argument as deprecated.

If another argument should be used instead, specify it via deprecatedBy.

Definition at line 804 of file argumentparser.h.

◆ maxOccurrences()

std::size_t CppUtilities::Argument::maxOccurrences ( ) const
inline

Returns the maximum number of occurrences.

If the argument occurs more often, the parser will complain.

Definition at line 781 of file argumentparser.h.

◆ minOccurrences()

std::size_t CppUtilities::Argument::minOccurrences ( ) const
inline

Returns the minimum number of occurrences.

If the argument occurs not that many times, the parser will complain.

Definition at line 771 of file argumentparser.h.

◆ name()

const char * CppUtilities::Argument::name ( ) const
inline

Returns the name of the argument.

The parser compares the name with the characters following a "--" prefix to identify arguments.

Definition at line 520 of file argumentparser.h.

◆ occurrenceInfo() [1/2]

std::vector< ArgumentOccurrence > & CppUtilities::Argument::occurrenceInfo ( )
inline

Returns information about all occurrences of the argument which have been detected when parsing.

Remarks
This information is meant to be set by the ArgumentParser. Modifying it directly is likely not a good idea. This method has been added primarily for testing purposes. In this case it might make sense to skip the actual parsing and just provide some dummy values.

Definition at line 1086 of file argumentparser.h.

◆ occurrenceInfo() [2/2]

const std::vector< ArgumentOccurrence > & CppUtilities::Argument::occurrenceInfo ( ) const
inline

Returns information about all occurrences of the argument which have been detected when parsing.

Remarks
The convenience methods isPresent(), values() and path() provide direct access to these information for a particular occurrence.

Definition at line 1075 of file argumentparser.h.

◆ occurrences()

std::size_t CppUtilities::Argument::occurrences ( ) const
inline

Returns how often the argument could be detected when parsing.

Definition at line 753 of file argumentparser.h.

◆ parents()

const ArgumentVector & CppUtilities::Argument::parents ( ) const
inline

Returns the parents of this argument.

If this argument is used as secondary argument, the arguments which contain this argument as secondary arguments are returned as "parents" of this argument.

If this argument is used as a main argument shouldn't be used as secondary argument at the same time and thus have no parents.

Definition at line 989 of file argumentparser.h.

◆ path()

const std::vector< Argument * > & CppUtilities::Argument::path ( std::size_t occurrence = 0) const
inline

Returns the path of the specified occurrence.

Definition at line 824 of file argumentparser.h.

◆ preDefinedCompletionValues()

const char * CppUtilities::Argument::preDefinedCompletionValues ( ) const
inline

Returns the assigned values used when generating completion for the values.

Definition at line 1030 of file argumentparser.h.

◆ printInfo()

void CppUtilities::Argument::printInfo ( std::ostream & os,
unsigned char indentation = 0 ) const

Writes the name, the abbreviation and other information about the Argument to the give ostream.

Definition at line 521 of file argumentparser.cpp.

◆ requiredValueCount()

std::size_t CppUtilities::Argument::requiredValueCount ( ) const
inline

Returns the number of values which are required to be given for this argument.

The parser will expect that many values when parsing command line arguments. A negative value indicates a variable number of arguments to be expected.

The default value is 0, except for ConfigValueArgument instances.

See also
setRequiredValueCount()
valueNames()
setValueNames()

Definition at line 651 of file argumentparser.h.

◆ reset()

void CppUtilities::Argument::reset ( )
inline

Resets occurrences (indices, values and paths).

So parsing results are wiped while the argument definition is preserved.

Definition at line 1048 of file argumentparser.h.

◆ resetRecursively()

void CppUtilities::Argument::resetRecursively ( )

Resets this argument and all sub arguments recursively.

See also
Argument::reset()

Definition at line 748 of file argumentparser.cpp.

◆ setAbbreviation()

void CppUtilities::Argument::setAbbreviation ( char abbreviation)
inline

Sets the abbreviation of the argument.

The abbreviation might be empty but mustn't be white spaces, equation char, single quote, double quote or newline.

The parser compares the abbreviation with the characters following a "-" prefix to identify arguments.

Definition at line 562 of file argumentparser.h.

◆ setCallback()

void CppUtilities::Argument::setCallback ( Argument::CallbackFunction callback)
inline

Sets a callback function which will be called by the parser if the argument could be found and no parsing errors occurred.

Remarks
The callback will be called for each occurrence of the argument.
See also
callback()

Definition at line 952 of file argumentparser.h.

◆ setCombinable()

void CppUtilities::Argument::setCombinable ( bool combinable)
inline

Sets whether this argument can be combined.

The parser will complain if two arguments labeled as uncombinable are present at the same time.

See also
isCombinable()

Definition at line 908 of file argumentparser.h.

◆ setConstraints()

void CppUtilities::Argument::setConstraints ( std::size_t minOccurrences,
std::size_t maxOccurrences )
inline

Sets the allowed number of occurrences.

See also
minOccurrences()
maxOccurrences()

Definition at line 815 of file argumentparser.h.

◆ setDenotesOperation()

void CppUtilities::Argument::setDenotesOperation ( bool denotesOperation)
inline

Sets whether the argument denotes the operation.

See also
denotesOperation()

Definition at line 932 of file argumentparser.h.

◆ setDescription()

void CppUtilities::Argument::setDescription ( const char * description)
inline

Sets the description of the argument.

The parser uses the description when printing help information.

Definition at line 602 of file argumentparser.h.

◆ setEnvironmentVariable()

void CppUtilities::Argument::setEnvironmentVariable ( const char * environmentVariable)
inline

Sets the environment variable queried when firstValue() is called.

See also
firstValue(), environmentVariable()

Definition at line 582 of file argumentparser.h.

◆ setExample()

void CppUtilities::Argument::setExample ( const char * example)
inline

Sets the a usage example for the argument.

The parser uses the description when printing help information.

Definition at line 622 of file argumentparser.h.

◆ setFlags() [1/2]

void CppUtilities::Argument::setFlags ( Argument::Flags flags)
inline

Replaces all Argument::Flags for the argument with the flags.

Definition at line 872 of file argumentparser.h.

◆ setFlags() [2/2]

void CppUtilities::Argument::setFlags ( Argument::Flags flags,
bool add )
inline

Adds or removes the specified flags.

Definition at line 880 of file argumentparser.h.

◆ setImplicit()

void CppUtilities::Argument::setImplicit ( bool implicit)
inline

Sets whether the argument is an implicit argument.

See also
isImplicit()

Definition at line 737 of file argumentparser.h.

◆ setName()

void CppUtilities::Argument::setName ( const char * name)
inline

Sets the name of the argument.

The name mustn't be empty, start with a minus or contain white spaces, equation chars, quotes and newlines.

The parser compares the name with the characters following a "--" prefix to identify arguments.

Definition at line 532 of file argumentparser.h.

◆ setPreDefinedCompletionValues()

void CppUtilities::Argument::setPreDefinedCompletionValues ( const char * preDefinedCompletionValues)
inline

Assigns the values to be used when generating completion for the values.

Definition at line 1038 of file argumentparser.h.

◆ setRequired()

void CppUtilities::Argument::setRequired ( bool required)
inline

Sets whether this argument is mandatory or not.

The parser will complain if a mandatory argument is not present.

Definition at line 850 of file argumentparser.h.

◆ setRequiredValueCount()

void CppUtilities::Argument::setRequiredValueCount ( std::size_t requiredValueCount)
inline

Sets the number of values which are required to be given for this argument.

The parser will expect that many values when parsing command line arguments. Pass Argument::varValueCount for a variable number of arguments to be expected.

See also
requiredValueCount()
valueNames()
setValueNames()

Definition at line 668 of file argumentparser.h.

◆ setSubArguments()

void CppUtilities::Argument::setSubArguments ( const ArgumentInitializerList & subArguments)

Sets the secondary arguments for this argument.

The given arguments will be considered as secondary arguments of this argument by the argument parser. This means that the parser will complain if these arguments are given, but not this argument. If secondary arguments are labeled as mandatory their parent is also mandatory.

The Argument does not take ownership. Do not destroy the given arguments as long as they are used as secondary arguments.

See also
addSubArguments()
secondaryArguments()
addSecondaryArgument()
hasSubArguments()

Definition at line 617 of file argumentparser.cpp.

◆ setValueCompletionBehavior()

void CppUtilities::Argument::setValueCompletionBehavior ( ValueCompletionBehavior completionValues)
inline

Sets the items to be considered when generating completion for the values.

By default, files and directories are considered, unless pre-defined values have been specified using setPreDefinedCompletionValues().

Definition at line 1022 of file argumentparser.h.

◆ setValueNames()

void CppUtilities::Argument::setValueNames ( std::initializer_list< const char * > valueNames)
inline

Sets the names of the required values.

These names will be used when printing information about the argument.

If the number of value names is higher than the number of required values the additional value names will be ignored. If the number of value names is lesser than the number of required values generic values will be used for the missing names.

See also
appendValueName()
valueNames()
requiredValueCount()

Definition at line 699 of file argumentparser.h.

◆ specifiedOperation()

Argument * CppUtilities::Argument::specifiedOperation ( ) const

Returns the first operation argument specified by the user or nullptr if no operation has been specified.

Remarks
Only direct sub arguments of this argument are considered.

Definition at line 734 of file argumentparser.cpp.

◆ subArguments()

const ArgumentVector & CppUtilities::Argument::subArguments ( ) const
inline

Returns the secondary arguments for this argument.

See also
setSubArguments()
hasSubArguments()

Definition at line 963 of file argumentparser.h.

◆ valueCompletionBehaviour()

ValueCompletionBehavior CppUtilities::Argument::valueCompletionBehaviour ( ) const
inline

Returns the items to be considered when generating completion for the values.

By default, files and directories are considered, unless pre-defined values have been specified using setPreDefinedCompletionValues().

Definition at line 1011 of file argumentparser.h.

◆ valueNames()

const std::vector< const char * > & CppUtilities::Argument::valueNames ( ) const
inline

Returns the names of the required values.

These names will be shown when printing information about the argument.

See also
setValueNames()
appendValueName()

Definition at line 681 of file argumentparser.h.

◆ values()

const std::vector< const char * > & CppUtilities::Argument::values ( std::size_t occurrence = 0) const
inline

Returns the parameter values for the specified occurrence of argument.

Remarks
  • The values are set by the parser when parsing the command line arguments.
  • The specified occurrence must be less than occurrences().

Definition at line 633 of file argumentparser.h.

◆ valuesAs()

template<typename... TargetType>
std::tuple< TargetType... > CppUtilities::Argument::valuesAs ( std::size_t occurrence = 0) const

Converts the present values for the specified occurrence to the specified target types.

There must be as many values present as types are specified.

Exceptions
ThrowsArgumentUtilities::Failure when the number of present values is not sufficient or a conversion error occurs.
Remarks
Still experimental. Might be removed/adjusted in next minor release.

Definition at line 411 of file argumentparser.h.

◆ wouldConflictWithArgument()

Argument * CppUtilities::Argument::wouldConflictWithArgument ( ) const

Checks if this argument would conflict with other arguments if it was present.

If the argument is in conflict with an other argument this argument will be returned. Otherwise nullptr will be returned.

Remarks
Conflicts with main arguments aren't considered by this method!

Definition at line 715 of file argumentparser.cpp.

Member Data Documentation

◆ varValueCount

std::size_t CppUtilities::Argument::varValueCount = std::numeric_limits<std::size_t>::max()
staticconstexpr

Denotes a variable number of values.

See also
setRequiredValueCount()

Definition at line 368 of file argumentparser.h.


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