yat  0.20.3pre
Public Member Functions | Protected Member Functions | List of all members
theplu::yat::utility::OptionFile Class Reference

Class for file related options. More...

#include <yat/utility/OptionFile.h>

Inheritance diagram for theplu::yat::utility::OptionFile:
theplu::yat::utility::OptionArg< std::string > theplu::yat::utility::Option theplu::yat::utility::OptionInFile theplu::yat::utility::OptionOutFile

Public Member Functions

 OptionFile (CommandLine &cmd, std::string name, std::string desc, bool required=false, bool exist=false, std::string bits="")
 Constructor. More...
 
virtual ~OptionFile (void)
 Destructor.
 
void print_arg (std::string arg)
 
std::string value (void) const
 
void value (std::string v)
 set value More...
 
std::string description (void) const
 
void description (const std::string &description)
 set description More...
 
std::string long_name (void) const
 
void parse (std::vector< std::string >::iterator &, const std::vector< std::string >::iterator &)
 parsing the commandline
 
bool present (void) const
 Get if option was found in cmd. More...
 
std::string print (void)
 print help output More...
 
void reset (void)
 sets present to false
 
char short_name (void) const
 
void validate (void)
 Validate the Option. More...
 

Protected Member Functions

bool required (void) const
 
const CommandLinecmd (void) const
 

Detailed Description

Class for file related options.

This class could be used for an option with argument when the argument is a file. The class adds some convenience on top of OptionArg<std::string> by utilizing the FileUtil class. Besides setting the name and description of the option and whether the option must appear in the command line, you can declare whether the file must exist and whether it must fulfill certain file permissions. If any of these requirements are not met, an exception will be thrown during the validation phase in CommandLine::parse.

See also
FileUtil

Constructor & Destructor Documentation

◆ OptionFile()

theplu::yat::utility::OptionFile::OptionFile ( CommandLine cmd,
std::string  name,
std::string  desc,
bool  required = false,
bool  exist = false,
std::string  bits = "" 
)

Constructor.

Parameters
cmdCommandline Option is associated with
namestring such as "file" for –file, "f" for -f or "f,file" for having both short and long option name
descstring used in help display
requiredIf true option must be found in commandline or exception is thrown in validation
existif true File must exist, see FileUtil::exists()
bitsused to check permission on file, see FileUtil::permissions()

Member Function Documentation

◆ cmd()

const CommandLine& theplu::yat::utility::Option::cmd ( void  ) const
protectedinherited
Returns
const reference to CommandLine Option belongs to.

◆ description() [1/2]

std::string theplu::yat::utility::Option::description ( void  ) const
inherited
Returns
description

◆ description() [2/2]

void theplu::yat::utility::Option::description ( const std::string &  description)
inherited

set description

Since
New in yat 0.7

◆ long_name()

std::string theplu::yat::utility::Option::long_name ( void  ) const
inherited
Returns
long name e.g. 'help' for –help option.

◆ present()

bool theplu::yat::utility::Option::present ( void  ) const
inherited

Get if option was found in cmd.

Returns
true if option has been detected in parsing

◆ print()

std::string theplu::yat::utility::Option::print ( void  )
inherited

print help output

This function calls the four virtual private functions print1, print2, print3, and print4. This allows an inherited class to implement one (or several) of these functions and keep the default output of the others. The default behavior is that:

◆ print_arg()

void theplu::yat::utility::OptionArg< std::string >::print_arg ( std::string  arg)
inlineinherited
Parameters
argstring to be used in help output such as '=TARGET' in '–target=TARGET'. See print3().
Since
New in yat 0.5.

◆ required()

bool theplu::yat::utility::OptionArg< std::string >::required ( void  ) const
inlineprotectedinherited
Returns
true if Option is required, i.e., if Option is not found during parsing an exception will be thrown.

◆ short_name()

char theplu::yat::utility::Option::short_name ( void  ) const
inherited
Returns
short name e.g. 'h' for -h option.

◆ validate()

void theplu::yat::utility::Option::validate ( void  )
inherited

Validate the Option.

This function is called by CommandLine::parse() after all options have been detected and parsed (see Option::parse()).

◆ value() [1/2]

std::string theplu::yat::utility::OptionArg< std::string >::value ( void  ) const
inlineinherited
Returns
value

◆ value() [2/2]

void theplu::yat::utility::OptionArg< std::string >::value ( std::string  v)
inlineinherited

set value

Since
new in yat 0.5

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

Generated on Sat Feb 18 2023 03:31:45 for yat by  doxygen 1.8.14