Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Burger::CommandParameter Class Referenceabstract

Base class for command line parameters. More...

Inheritance diagram for Burger::CommandParameter:
Inheritance graph
[legend]
Collaboration diagram for Burger::CommandParameter:
Collaboration graph
[legend]

Public Member Functions

const Burger::StaticRTTIget_StaticRTTI (void) const noexcept override
 Get the description to the class.
 
uint_t IsHelpAvailable (void) const noexcept
 Determine if help is available.
 
const char * GetHelp (void) const noexcept
 Return the help string.
 
virtual int Action (int argc, const char **argv)=0
 Process the parameters for a command.
 
- Public Member Functions inherited from Burger::Base
const char * get_class_name (void) const noexcept
 Get the name of the class.
 
virtual ~Base () noexcept=default
 Destructor.
 

Static Public Member Functions

static int RemoveParms (int argc, const char **argv, int iIndexToArgv, int iRemoveCount) noexcept
 Remove entries from a "C" command list.
 
static int Process (int argc, const char **argv, const CommandParameter **ppParms, uintptr_t uParmCount, const char *pUsage=nullptr, int iMin=0, int iMax=0) noexcept
 Process an array of command parameters.
 

Static Public Attributes

static const Burger::StaticRTTI g_StaticRTTI
 The global description of the class.
 
- Static Public Attributes inherited from Burger::Base
static const Burger::StaticRTTI g_StaticRTTI
 The global description of the class.
 

Protected Member Functions

 CommandParameter (const char *pHelp, const char *const *ppParameterNames, uintptr_t uParameterCount) noexcept
 Base class constructor.
 

Protected Attributes

const char * m_pHelp
 Pointer to the optional help string.
 
const char *const * m_ppParameterNames
 Array of "C" strings of the -parameter (Minus the -)
 
uintptr_t m_uParameterCount
 Number of possible strings to check.
 

Detailed Description

Base class for command line parameters.


For ease of parsing command lines for tools, derived classes for each data type are created and then pooled to handle most parsing needs. It is modeled after the argparse class found in python.

Burger::CommandParameterBooleanTrue ShowAsm("Save as asm hex source","h");
Burger::CommandParameterBooleanTrue ShowC("Save as \"C\" source","c");
"Playback frequency","f",44100,400,100000);
"Length to dump","l",UINTPTR_MAX);
const CommandParameter *MyParms[] = {
&ShowAsm,
&ShowC,
&Frequency,
&Length
};
argc = CommandParameter::Process(argc,argv,MyParms,
BURGER_ARRAYSIZE(MyParms),
"Dump's the contents of a file to stdout.\n"
"Copyright by Rebecca Ann Heineman\n",2);
if (argc<0) {
} else {
if (ShowAsm.GetValue()) {
ShowAsmCode();
}
if (ShowC.GetValue()) {
ShowCCode();
}
PlaySound(Frequency.GetValue(),Length.GetValue());
}
#define BURGER_ARRAYSIZE(x)
Define to return the number of elements in an array.
Definition burger.h:1423
Class for a boolean command line parameters.
Definition burger.h:23609
Base class for command line parameters.
Definition burger.h:23570
static int Process(int argc, const char **argv, const CommandParameter **ppParms, uintptr_t uParmCount, const char *pUsage=nullptr, int iMin=0, int iMax=0) noexcept
Process an array of command parameters.
Definition brcommandparameter.cpp:211
Class for a numeric string command line parameter.
Definition burger.h:23634
static void SetErrorCode(eError iNewError) noexcept
Set the current error code.
Definition burger.h:15593

Constructor & Destructor Documentation

◆ CommandParameter()

Burger::CommandParameter::CommandParameter ( const char * pHelp,
const char *const * ppParameterNames,
uintptr_t uParameterCount )
inlineprotectednoexcept

Base class constructor.


Construct the base data needed for a CommandParameter

Parameters
pHelpMessage Pointer to a "C" string containing the help message for this parameter or nullptr if help is not available.
ppParameterNamesEither a pointer to an array of "C" strings or a pointer to a single "C" string.
uParameterCountNumber of entries in the array (0 if the array is a single direct pointer)
See also
Burger::CommandParameterBooleanTrue, Burger::CommandParameterWordPtr

Member Function Documentation

◆ Action()

int Burger::CommandParameter::Action ( int argc,
const char ** argv )
pure virtual

Process the parameters for a command.


Process the parameters and return the number of parameters used including the parameter that invoked this command.

Example: If "-a", then return 1, if "-length 2000", return 2

If there was a parsing error, return -1

Note
Do not attempt to manually remove parameters from the input. It will be performed by the caller with the returned value (Number of parameters processed)
Parameters
argcNumber of entries remaining in the parameter array (Can be zero)
argvPointer to an array of "C" string pointers.
Returns
Number of parameters processed or -1 on error or 1 for no parameters needed.
See also
RemoveParms() or Process()

Implemented in Burger::CommandParameterBooleanTrue, Burger::CommandParameterWordPtr, and Burger::CommandParameterString.

◆ get_StaticRTTI()

const Burger::StaticRTTI * Burger::CommandParameter::get_StaticRTTI ( void ) const
overridevirtualnoexcept

Get the description to the class.


This virtual function will pull the pointer to the StaticRTTI instance that has the name of the class. Due to it being virtual, it will be the name of the most derived class.

Returns
Pointer to a global, read only instance of StaticRTTI for the true class

Reimplemented from Burger::Base.

◆ GetHelp()

Burger::CommandParameter::GetHelp ( void ) const
inlinenoexcept

Return the help string.


Returns
A pointer to a "C" string for the help or nullptr if there isn't any.
See also
IsHelpAvailable(void) const

◆ IsHelpAvailable()

Burger::CommandParameter::IsHelpAvailable ( void ) const
inlinenoexcept

Determine if help is available.


Returns
TRUE if there is a help string available, FALSE if not.
See also
GetHelp(void) const

◆ Process()

int BURGER_API Burger::CommandParameter::Process ( int argc,
const char ** argv,
const CommandParameter ** ppParms,
uintptr_t uParmCount,
const char * pUsage = nullptr,
int iMin = 0,
int iMax = 0 )
staticnoexcept

Process an array of command parameters.


Given a list of command table parsers, scan the parameter list for matches and invoke their functions to calculate the values.

Each parameter is checked for a prefix of '-' and then it's matched to the command strings found in each CommandParameter and if processed, the entry will be removed from the list. When this function is complete, only the unprocessed entries will remain

Note
On Windows and MSDOS platforms, the prefix '/' is accepted as well as '-'
Parameters
argcNumber of parameters in the argv list.
argvPointer to an array of "C" strings to parse a command line from.
ppParmsArray of pointers to CommandParameter objects
uParmCountNumber of entries in the ppParms array
pUsagePointer to a "C" string with copyright and usage, or nullptr if no usage is present
iMinMinimum number of allowable parameters or zero if no min/max test is to be performed
iMaxMaximum number of allowable parameters or if it must match iMin
Returns
-1 on error (Or help printed) or the number of unprocessed command line entries.
See also
Burger::CommandParameter

◆ RemoveParms()

int BURGER_API Burger::CommandParameter::RemoveParms ( int argc,
const char ** argv,
int iIndexToArgv,
int iRemoveCount )
staticnoexcept

Remove entries from a "C" command list.


Index into an array of "C" string pointers, index into the array and remove the requested number of entries. Returns the number of entries remaining in the array.

Parameters
argcNumber of parameters in the argv list.
argvPointer to an array of "C" strings to parse a command line from.
iIndexToArgvEntry into the array to start entry removal from.
iRemoveCountNumber of entries to remove.
Returns
The number of entries remaining in the array.

Member Data Documentation

◆ g_StaticRTTI

const Burger::StaticRTTI Burger::CommandParameter::g_StaticRTTI
static

The global description of the class.


This record contains the name of this class and a reference to the parent

◆ m_pHelp

const char* Burger::CommandParameter::m_pHelp
protected

Pointer to the optional help string.

◆ m_ppParameterNames

const char* const* Burger::CommandParameter::m_ppParameterNames
protected

Array of "C" strings of the -parameter (Minus the -)

◆ m_uParameterCount

uintptr_t Burger::CommandParameter::m_uParameterCount
protected

Number of possible strings to check.