POption Class Reference

Detailed Description

The POption class represents a command line parser.

Features are the following:

  • Long or short option names: "--input=123" OR "-i 123"
  • Support basic data types and some papillon objects
  • Mandatory or optional arguments
  • Default values

Typical use is:

POption commandLine(argc, argv);
// Add --help Or -h option to the command line parser
bool displayHelp = commandLine.Option("help,h", "Display help message");
// Add --myString=... OR -s=... option: this command line argument is mandatory (true flag)
PString strParam = commandLine.String("myString,s", PString::Empty(), "Any string parameter", true); // mandatory
// Add --myInt=... OR -i=... option: this command line argument is NOT mandatory (false flag), default value is -1
int intParam = commandLine.Int ("myInt,i", -1, "Any int parameter", false); // not mandatory
if (displayHelp)
std::cout << commandLine.ToStringHelp().c_str() << std::endl;
commandLine.Check().OrDie();

Definition at line 56 of file POption.h.

#include <POption.h>

Constructor & Destructor Documentation

◆ POption() [1/4]

POption::POption ( )

Constructs an empty command line parser.

◆ POption() [2/4]

POption::POption ( const PString commandLine)

Constructs a command line parser from a command line string.

◆ POption() [3/4]

POption::POption ( int  argc,
char **  argv 
)

Constructs a command line parser from argc/argc.

◆ POption() [4/4]

POption::POption ( const POption other)

Constructs a shared copy of other.

◆ ~POption()

virtual POption::~POption ( )
virtual

Destroys this object.

Member Function Documentation

◆ AddStandardOptions()

void POption::AddStandardOptions ( )

Adds the following classical options to this command line parser: –help (or -h) : for help –logFile (or -l) : log to the specified file –logLevel (or -ll): set log level –verbose (or -v) : set log verbosity.

◆ Bool()

bool POption::Bool ( const PString optionName,
bool  defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified bool value from the command line.

Returns false if any error occurs.

◆ Check()

PResult POption::Check ( ) const

Checks is the command line is valid.

Returns PResult::C_OK if success, another result otherwise.

◆ Double()

double POption::Double ( const PString optionName,
double  defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified double value from the command line.

Returns PMath::NaNd if any error occurs.

◆ ExportCommandLine()

PString POption::ExportCommandLine ( ) const

Export the command line from the current list of options.

◆ Float()

float POption::Float ( const PString optionName,
float  defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified float value from the command line.

Returns PMath::NaNf if any error occurs.

◆ GetCmdLine()

PString POption::GetCmdLine ( ) const

Returns the command line as a single string.

◆ Guid()

PGuid POption::Guid ( const PString optionName,
const PGuid defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified PGuid value from the command line.

Returns PGuid::Null() if any error occurs.

◆ Has()

bool POption::Has ( const PString optionName) const

Returns true if the specified option was passed in the command line, false otherwise.

◆ Image()

PImage POption::Image ( const PString optionName,
const PImage defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified PImage value from the command line.

Returns an empty image if any error occurs.

◆ InputVideoStream()

PInputVideoStream POption::InputVideoStream ( const PString optionName,
const PInputVideoStream defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified PInputVideoStream value from the command line.

Returns an empty input video stream if any error occurs.

◆ Int()

papillon::int32 POption::Int ( const PString optionName,
papillon::int32  defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified int value from the command line.

Returns PMath::C_INT_MIN if any error occurs.

◆ IsEmpty()

bool POption::IsEmpty ( ) const

Returns true if the command line has not set, false otherwise.

◆ operator=()

POption& POption::operator= ( const POption other)

Performs a shared copy of other to this object.

◆ Option()

bool POption::Option ( const PString optionName,
const PString description 
)

Adds an option with no argument on the command line (e.g.

–display). Returns true if the option is on the command line, false otherwise.

See also
Has()

◆ OutputVideoStream()

POutputVideoStream POption::OutputVideoStream ( const PString optionName,
const POutputVideoStream defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified POutputVideoStream value from the command line.

Returns an empty output video stream if any error occurs.

◆ Parse()

static PStringList POption::Parse ( const PString commandLine)
static

Parses the specified command line and retrieve a list of arguments.

Removes leading and trailing whitespace characters. Quoted arguments and backslashes are taken into account. Example: " app.exe \"a b c ""file 2.tmp" --arg1=2 -arg2 "my file.bin" -arg3=\\ "1\2" -arg4=myArg " gives 9 elements: ["app.exe", "a b c ", "file 2.tmp", "--arg1=2", "-arg2", "my file.bin", "-arg3=\", "1\2", "-arg4=myArg"]

◆ Rectanglei()

PRectanglei POption::Rectanglei ( const PString optionName,
const PRectanglei defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified PRectanglei value from the command line.

Returns (0,0,0,0) if any error occurs.

◆ Set()

PResult POption::Set ( const PString optionName,
const PString value 
)

Replaces the value of an argument on the command line.

Returns PResult::C_OK if success, another result otherwise.

◆ Sizef()

PSizef POption::Sizef ( const PString optionName,
const PSizef defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified PSizef value from the command line.

Returns (0,0) if any error occurs.

◆ Sizei()

PSizei POption::Sizei ( const PString optionName,
const PSizei defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified PSizei value from the command line.

Returns (0,0) if any error occurs.

◆ String()

PString POption::String ( const PString optionName,
const PString defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified PString value from the command line.

Returns PString::Empty()if any error occurs.

◆ StringList()

PStringList POption::StringList ( const PString optionName,
const PStringList defaultValue,
const PString description,
bool  isRequired = false 
)

Gets the specified PStringList value from the command line.

Elements of the list must be separated by commas (e.g. –myList=a,bc,def). Returns an empty PStringList if any error occurs.

◆ ToStringHelp()

PString POption::ToStringHelp ( papillon::int32  lengthDescription = 50) const

Returns an aligned text description of this command line.

You can specify the maximum length of the description (if longer, the description is split on several lines).