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

The NoColorArgument class allows to specify whether use of escape codes or similar technique to provide formatted output on the terminal should be enabled/disabled. More...

#include <argumentparser.h>

Inheritance diagram for CppUtilities::NoColorArgument:
[legend]
Collaboration diagram for CppUtilities::NoColorArgument:
[legend]

Public Member Functions

 NoColorArgument ()
 Constructs a new NoColorArgument argument.
 
void apply () const
 Sets EscapeCodes::enabled according to the presence of the first instantiation of NoColorArgument.
 
- Public Member Functions inherited from 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.
 
 ~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.
 

Additional Inherited Members

- Public Types inherited from CppUtilities::Argument
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
 
- Static Public Attributes inherited from CppUtilities::Argument
static constexpr std::size_t varValueCount = std::numeric_limits<std::size_t>::max()
 Denotes a variable number of values.
 

Detailed Description

The NoColorArgument class allows to specify whether use of escape codes or similar technique to provide formatted output on the terminal should be enabled/disabled.

This argument will either prevent or explicitly allow the use of escape codes or similar technique to provide formatted output on the terminal. More explicitly, the argument will always allow to negate the default value of EscapeCodes::enabled which can be configured at build time by setting the CMake variable ENABLE_ESCAPE_CODES_BY_DEFAULT.

Remarks
  • Only the first instance is considered for actually altering the value of EscapeCodes::enabled so it makes no sense to instantiate this class multiple times.
  • It is ensure that EscapeCodes::enabled will be set before any callback functions are invoked and even in the error case (if the error doesn't prevent the argument from being detected). Hence this feature is implemented via NoColorArgument::apply() rather than the usual callback mechanism.
See also
NoColorArgument::NoColorArgument(), EscapeCodes::enabled

Definition at line 447 of file argumentparser.h.

Constructor & Destructor Documentation

◆ NoColorArgument()

CppUtilities::NoColorArgument::NoColorArgument ( )

Constructs a new NoColorArgument argument.

Remarks
This will also set EscapeCodes::enabled to the value of the environment variable ENABLE_ESCAPE_CODES.

Definition at line 1761 of file argumentparser.cpp.

Member Function Documentation

◆ apply()

void CppUtilities::NoColorArgument::apply ( ) const

Sets EscapeCodes::enabled according to the presence of the first instantiation of NoColorArgument.

Definition at line 1783 of file argumentparser.cpp.


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