C++ Utilities  4.9.2
Common C++ classes and routines used by my applications such as argument parser, IO and conversion utilities
Classes | Typedefs | Enumerations | Functions | Variables
ApplicationUtilities Namespace Reference

Contains currently only ArgumentParser and related classes. More...

Classes

class  Argument
 The Argument class is a wrapper for command line argument information. More...
 
struct  ArgumentOccurrence
 The ArgumentOccurrence struct holds argument values for an occurrence of an argument. More...
 
class  ArgumentParser
 The ArgumentParser class provides a means for handling command line arguments. More...
 
class  ArgumentReader
 
class  ConfigValueArgument
 The ConfigValueArgument class is an Argument where setCombinable() is true by default. More...
 
class  Failure
 The Failure class is thrown by an ArgumentParser when a parsing error occurs. More...
 
class  FakeQtConfigArguments
 The FakeQtConfigArguments class provides arguments for the Qt GUI used when the application hasn't been built with Qt GUI support. More...
 
class  HelpArgument
 The HelpArgument class prints help information for an argument parser when present (–help, -h). More...
 
class  Indentation
 The Indentation class allows printing indentation conveniently, eg. More...
 
class  OperationArgument
 The OperationArgument class is an Argument where denotesOperation() is true by default. More...
 

Typedefs

typedef std::initializer_list< Argument * > ArgumentInitializerList
 
typedef std::vector< Argument * > ArgumentVector
 
typedef std::function< bool(Argument *)> ArgumentPredicate
 

Enumerations

enum  UnknownArgumentBehavior { UnknownArgumentBehavior::Ignore, UnknownArgumentBehavior::Warn, UnknownArgumentBehavior::Fail }
 The UnknownArgumentBehavior enum specifies the behavior of the argument parser when an unknown argument is detected. More...
 
enum  ValueCompletionBehavior : unsigned char {
  ValueCompletionBehavior::None = 0, ValueCompletionBehavior::PreDefinedValues = 2, ValueCompletionBehavior::Files = 4, ValueCompletionBehavior::Directories = 8,
  ValueCompletionBehavior::FileSystemIfNoPreDefinedValues = 16, ValueCompletionBehavior::AppendEquationSign = 32
}
 The ValueCompletionBehavior enum specifies the items to be considered when generating completion for an argument value. More...
 
enum  Response { Response::None, Response::Yes, Response::No }
 The Response enum is used to specify the default response for the confirmPrompt() method. More...
 
enum  ArgumentDenotationType : unsigned char { Value = 0, Abbreviation = 1, FullName = 2 }
 The ArgumentDenotationType enum specifies the type of a given argument denotation. More...
 

Functions

Argument CPP_UTILITIES_EXPORTfirstPresentUncombinableArg (const ArgumentVector &args, const Argument *except)
 This function return the first present and uncombinable argument of the given list of arguments. More...
 
bool CPP_UTILITIES_EXPORT confirmPrompt (const char *message, Response defaultResponse)
 Prompts for confirmation displaying the specified message. More...
 
CPP_UTILITIES_EXPORT std::ostream & operator<< (std::ostream &out, Indentation indentation)
 
bool compareArgs (const Argument *arg1, const Argument *arg2)
 Returns whether arg1 should be listed before arg2 when printing completion. More...
 
void insertSiblings (const ArgumentVector &siblings, list< const Argument *> &target)
 Inserts the specified siblings in the target list. More...
 

Variables

CPP_UTILITIES_EXPORT const char * applicationName = nullptr
 Specifies the name of the application (used by ArgumentParser::printHelp()). More...
 
CPP_UTILITIES_EXPORT const char * applicationAuthor = nullptr
 Specifies the author of the application (used by ArgumentParser::printHelp()). More...
 
CPP_UTILITIES_EXPORT const char * applicationVersion = nullptr
 Specifies the version of the application (used by ArgumentParser::printHelp()). More...
 
CPP_UTILITIES_EXPORT const char * applicationUrl = nullptr
 Specifies the URL to the application website (used by ArgumentParser::printHelp()). More...
 
CPP_UTILITIES_EXPORT std::initializer_list< const char * > dependencyVersions
 Specifies the dependency versions the application was linked against (used by ArgumentParser::printHelp()). More...
 
CPP_UTILITIES_EXPORT void(* exitFunction )(int) = &exit
 Specifies a function quit the application. More...
 

Detailed Description

Contains currently only ArgumentParser and related classes.

Typedef Documentation

◆ ArgumentInitializerList

typedef std::initializer_list<Argument *> ApplicationUtilities::ArgumentInitializerList

Definition at line 52 of file argumentparser.h.

◆ ArgumentPredicate

typedef std::function<bool(Argument *)> ApplicationUtilities::ArgumentPredicate

Definition at line 56 of file argumentparser.h.

◆ ArgumentVector

Definition at line 55 of file argumentparser.h.

Enumeration Type Documentation

◆ ArgumentDenotationType

The ArgumentDenotationType enum specifies the type of a given argument denotation.

Enumerator
Value 

parameter value

Abbreviation 

argument abbreviation

FullName 

full argument name

Definition at line 32 of file argumentparser.cpp.

◆ Response

The Response enum is used to specify the default response for the confirmPrompt() method.

Enumerator
None 
Yes 
No 

Definition at line 18 of file commandlineutils.h.

◆ UnknownArgumentBehavior

The UnknownArgumentBehavior enum specifies the behavior of the argument parser when an unknown argument is detected.

Enumerator
Ignore 

Unknown arguments are ignored without warnings.

Warn 

A warning is printed to std::cerr if an unknown argument is detected.

Fail 

Further parsing is aborted and an ApplicationUtilities::Failure instance with an error message is thrown.

Definition at line 62 of file argumentparser.h.

◆ ValueCompletionBehavior

enum ApplicationUtilities::ValueCompletionBehavior : unsigned char
strong

The ValueCompletionBehavior enum specifies the items to be considered when generating completion for an argument value.

Enumerator
None 

no auto-completion

PreDefinedValues 

values assigned with Argument::setPreDefinedCompletionValues()

Files 

files

Directories 

directories

FileSystemIfNoPreDefinedValues 

files and directories but only if no values have been assigned (default behavior)

AppendEquationSign 

an equation sign is appended to values which not contain an equation sign already

Definition at line 71 of file argumentparser.h.

Function Documentation

◆ compareArgs()

bool ApplicationUtilities::compareArgs ( const Argument arg1,
const Argument arg2 
)

Returns whether arg1 should be listed before arg2 when printing completion.

Arguments are sorted by name (ascending order). However, all arguments denoting an operation are listed before all other arguments.

Definition at line 796 of file argumentparser.cpp.

◆ confirmPrompt()

bool ApplicationUtilities::confirmPrompt ( const char *  message,
Response  defaultResponse = Response::None 
)

Prompts for confirmation displaying the specified message.

Definition at line 18 of file commandlineutils.cpp.

◆ firstPresentUncombinableArg()

Argument * ApplicationUtilities::firstPresentUncombinableArg ( const ArgumentVector args,
const Argument except 
)

This function return the first present and uncombinable argument of the given list of arguments.

The Argument except will be ignored.

Definition at line 407 of file argumentparser.cpp.

◆ insertSiblings()

void ApplicationUtilities::insertSiblings ( const ArgumentVector siblings,
list< const Argument *> &  target 
)

Inserts the specified siblings in the target list.

Remarks
Only inserts siblings which could still occur at least once more.

Definition at line 811 of file argumentparser.cpp.

◆ operator<<()

CPP_UTILITIES_EXPORT std::ostream& ApplicationUtilities::operator<< ( std::ostream &  out,
Indentation  indentation 
)
inline

Definition at line 55 of file commandlineutils.h.

Variable Documentation

◆ applicationAuthor

const char * ApplicationUtilities::applicationAuthor = nullptr

Specifies the author of the application (used by ArgumentParser::printHelp()).

Definition at line 266 of file argumentparser.cpp.

◆ applicationName

const char * ApplicationUtilities::applicationName = nullptr

Specifies the name of the application (used by ArgumentParser::printHelp()).

Definition at line 264 of file argumentparser.cpp.

◆ applicationUrl

const char * ApplicationUtilities::applicationUrl = nullptr

Specifies the URL to the application website (used by ArgumentParser::printHelp()).

Definition at line 270 of file argumentparser.cpp.

◆ applicationVersion

const char * ApplicationUtilities::applicationVersion = nullptr

Specifies the version of the application (used by ArgumentParser::printHelp()).

Definition at line 268 of file argumentparser.cpp.

◆ dependencyVersions

std::initializer_list< const char * > ApplicationUtilities::dependencyVersions

Specifies the dependency versions the application was linked against (used by ArgumentParser::printHelp()).

Definition at line 272 of file argumentparser.cpp.

◆ exitFunction

void(* ApplicationUtilities::exitFunction)(int) = &exit

Specifies a function quit the application.

Remarks
Currently only used after printing Bash completion. Default is std::exit().

Definition at line 278 of file argumentparser.cpp.