wavelength 1.0.0
Loading...
Searching...
No Matches
OptionProcessor Class Reference

Parser of the command line that main() receives. More...

#include <optionprocessor.h>

Public Member Functions

 OptionProcessor ()=default
 Construct a processor without options.
 ~OptionProcessor ()
 Delete every option.
void AddBool (const char *pszName, int *pnTarget, int nValue)
 Add an option that stores a value when it is present.
void AddString (const char *pszName, String *pTarget)
 Add an option that reads the argument after it into a string.
void Process (int argc, char **argv)
 Apply the options of a command line.
const std::list< std::unique_ptr< Option > > & GetOptions () const
int GetIndex () const
 ~OptionProcessor ()
 Delete every option.
void AddBoolOption (const char *name, bool *value, bool setValue)
 Add an option that stores a fixed value in a flag.
void AddStringOption (const char *name, String *value)
 Add an option that stores the argument after it.
void Process (int argc, char **argv)
 Apply the options to the arguments that start with a dash, stopping at the first that does not.

Static Public Member Functions

static char ** ParseCommandLine (const char *commandLine, int *argc)
 Split a command line into arguments at spaces outside double quotes.

Detailed Description

Parser of the command line that main() receives.

Set of command-line options applied to an argument vector.

The class is not polymorphic. The name comes from its messages.

The object is 0x10 bytes. The name comes from the message Process() prints for an unknown option.

Constructor & Destructor Documentation

◆ OptionProcessor()

OptionProcessor::OptionProcessor ( )
default

Construct a processor without options.

◆ ~OptionProcessor() [1/2]

OptionProcessor::~OptionProcessor ( )

Delete every option.

Ghidra address:
NTSC-U/C: 0x0029d870
Ghidra address:
PAL: 0x002a7538

◆ ~OptionProcessor() [2/2]

OptionProcessor::~OptionProcessor ( )

Delete every option.

Ghidra address:
0x100131d0

Member Function Documentation

◆ AddBool()

void OptionProcessor::AddBool ( const char * pszName,
int * pnTarget,
int nValue )

Add an option that stores a value when it is present.

Parameters
pszNameThe option's name, without the leading -.
pnTargetReceives nValue when the option is present.
nValueThe value.
Ghidra address:
NTSC-U/C: 0x0029d520
Ghidra address:
PAL: 0x002a71e8

◆ AddString()

void OptionProcessor::AddString ( const char * pszName,
String * pTarget )

Add an option that reads the argument after it into a string.

Parameters
pszNameThe option's name, without the leading -.
pTargetReceives the argument.
Ghidra address:
NTSC-U/C: 0x0029d5f0
Ghidra address:
PAL: 0x002a72b8

◆ Process() [1/2]

void OptionProcessor::Process ( int argc,
char ** argv )

Apply the options of a command line.

Adds an -options option. When it is present, every option prints its usage line and the program exits.

Parameters
argcThe argument count.
argvThe arguments.
Ghidra address:
NTSC-U/C: 0x0029d6b0
Ghidra address:
PAL: 0x002a7378

◆ GetOptions()

const std::list< std::unique_ptr< Option > > & OptionProcessor::GetOptions ( ) const
inline
Returns
The options, in the order they were added.

◆ GetIndex()

int OptionProcessor::GetIndex ( ) const
inline
Returns
The index of the next argument Process() reads.

◆ AddBoolOption()

void OptionProcessor::AddBoolOption ( const char * name,
bool * value,
bool setValue )

Add an option that stores a fixed value in a flag.

Parameters
nameThe option's name.
valueThe flag.
setValueThe value stored when the option appears.
Ghidra address:
0x10012eb0

◆ AddStringOption()

void OptionProcessor::AddStringOption ( const char * name,
String * value )

Add an option that stores the argument after it.

Parameters
nameThe option's name.
valueThe string.
Ghidra address:
0x10012f50

◆ Process() [2/2]

void OptionProcessor::Process ( int argc,
char ** argv )

Apply the options to the arguments that start with a dash, stopping at the first that does not.

An unknown option prints a message and is skipped. The --options argument prints every option's usage and exits.

Parameters
argcThe number of arguments, the program name included.
argvThe arguments.
Ghidra address:
0x10012fe0

◆ ParseCommandLine()

char ** OptionProcessor::ParseCommandLine ( const char * commandLine,
int * argc )
static

Split a command line into arguments at spaces outside double quotes.

The vector and the copy of the command line share one allocation. Twenty arguments at most are kept.

Parameters
commandLineThe command line.
argcReceives the number of arguments.
Returns
The arguments.
Ghidra address:
0x100130d0

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