PTLib  Version 2.10.10
PConfigArgs Class Reference

This class parse command line arguments with the ability to override them from a PConfig file/registry. More...

#include <args.h>

Inheritance diagram for PConfigArgs:
PArgList PObject

Public Member Functions

Construction
 PConfigArgs (const PArgList &args)
 
Overrides from class PArgList
virtual PINDEX GetOptionCount (char optionChar) const
 Get the count of the number of times the option was specified on the command line. More...
 
virtual PINDEX GetOptionCount (const char *optionStr) const
 Get the count of option. More...
 
virtual PINDEX GetOptionCount (const PString &optionName) const
 Get the count of option. More...
 
virtual PString GetOptionString (char optionChar, const char *dflt=NULL) const
 Get option string. More...
 
virtual PString GetOptionString (const char *optionStr, const char *dflt=NULL) const
 Get option string. More...
 
virtual PString GetOptionString (const PString &optionName, const char *dflt=NULL) const
 Get option string. More...
 
void Save (const PString &optionName)
 Save the current options to the PConfig. More...
 
void SetSectionName (const PString &section)
 Set the PConfig section name for options. More...
 
const PStringGetSectionName () const
 Get the PConfig section name for options. More...
 
void SetNegationPrefix (const PString &prefix)
 Set the prefix for option negation. More...
 
const PStringGetNegationPrefix () const
 Get the prefix for option negation. More...
 
- Public Member Functions inherited from PArgList
 PArgList (const char *theArgPtr=NULL, const char *argumentSpecPtr=NULL, PBoolean optionsBeforeParams=true)
 Create an argument list. More...
 
 PArgList (const PString &theArgStr, const char *argumentSpecPtr=NULL, PBoolean optionsBeforeParams=true)
 Create an argument list. More...
 
 PArgList (const PString &theArgStr, const PString &argumentSpecStr, PBoolean optionsBeforeParams=true)
 Create an argument list. More...
 
 PArgList (int theArgc, char **theArgv, const char *argumentSpecPtr=NULL, PBoolean optionsBeforeParams=true)
 Create an argument list. More...
 
 PArgList (int theArgc, char **theArgv, const PString &argumentSpecStr, PBoolean optionsBeforeParams=true)
 Create an argument list. More...
 
virtual void PrintOn (ostream &strm) const
 Output the string to the specified stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the string from the specified stream. More...
 
void SetArgs (const PString &theArgStr)
 Set the internal copy of the program arguments. More...
 
void SetArgs (int theArgc, char **theArgv)
 Set the internal copy of the program arguments. More...
 
void SetArgs (const PStringArray &theArgs)
 Set the internal copy of the program arguments. More...
 
virtual PBoolean Parse (const char *theArgumentSpec, PBoolean optionsBeforeParams=true)
 Parse the arguments. More...
 
virtual PBoolean Parse (const PString &theArgumentStr, PBoolean optionsBeforeParams=true)
 Parse the arguments. More...
 
PBoolean HasOption (char optionChar) const
 Get if option present. More...
 
PBoolean HasOption (const char *optionStr) const
 Get if option present. More...
 
PBoolean HasOption (const PString &optionName) const
 Get if option present. More...
 
PINDEX GetCount () const
 Get the argument count. More...
 
PStringArray GetParameters (PINDEX first=0, PINDEX last=P_MAX_INDEX) const
 Get the parameters that were parsed in the argument list. More...
 
PString GetParameter (PINDEX num) const
 Get the parameter that was parsed in the argument list. More...
 
PString operator[] (PINDEX num) const
 Get the parameter that was parsed in the argument list. More...
 
void Shift (int sh)
 Shift the parameters by the specified amount. More...
 
PArgListoperator<< (int sh)
 Shift the parameters by the specified amount. More...
 
PArgListoperator>> (int sh)
 Shift the parameters by the specified amount. More...
 
virtual void IllegalArgumentIndex (PINDEX idx) const
 This function is called when access to illegal parameter index is made in the GetParameter function. More...
 
virtual void UnknownOption (const PString &option) const
 This function is called when an unknown option was specified on the command line. More...
 
virtual void MissingArgument (const PString &option) const
 This function is called when an option that requires an associated string was specified on the command line but no associated string was provided. More...
 
- Public Member Functions inherited from PObject
virtual ~PObject ()
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual Comparison Compare (const PObject &obj) const
 Compare the two objects and return their relative rank. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. More...
 

Protected Member Functions

PString CharToString (char ch) const
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

PConfig config
 
PString sectionName
 
PString negationPrefix
 
- Protected Attributes inherited from PArgList
PStringArray argumentArray
 The original program arguments. More...
 
PString optionLetters
 The specification letters for options. More...
 
PStringArray optionNames
 The specification strings for options. More...
 
PIntArray optionCount
 The count of the number of times an option appeared in the command line. More...
 
PStringArray optionString
 The array of associated strings to options. More...
 
PIntArray parameterIndex
 The index of each . More...
 
int shift
 Shift count for the parameters in the argument list. More...
 

Additional Inherited Members

- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 
- Static Public Member Functions inherited from PObject
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
static const char * Class ()
 Get the name of the class as a C string. More...
 

Detailed Description

This class parse command line arguments with the ability to override them from a PConfig file/registry.

Constructor & Destructor Documentation

PConfigArgs::PConfigArgs ( const PArgList args)
Parameters
argsRaw argument list.

Member Function Documentation

PString PConfigArgs::CharToString ( char  ch) const
protected
const PString& PConfigArgs::GetNegationPrefix ( ) const
inline

Get the prefix for option negation.

The default is "no-".

References negationPrefix.

virtual PINDEX PConfigArgs::GetOptionCount ( char  optionChar) const
virtual

Get the count of the number of times the option was specified on the command line.

Returns
option repeat count.
Parameters
optionCharCharacter letter code for the option

Reimplemented from PArgList.

virtual PINDEX PConfigArgs::GetOptionCount ( const char *  optionStr) const
virtual

Get the count of option.

Parameters
optionStrString code for the option

Reimplemented from PArgList.

virtual PINDEX PConfigArgs::GetOptionCount ( const PString optionName) const
virtual

Get the count of option.

Parameters
optionNameString code for the option

Reimplemented from PArgList.

virtual PString PConfigArgs::GetOptionString ( char  optionChar,
const char *  dflt = NULL 
) const
virtual

Get option string.

Gets the string associated with an option e.g. -ofile or -o file would return the string "file". An option may have an associated string if it had a ':' character folowing it in the specification string passed to the Parse() function.

Returns
the options associated string.
Parameters
optionCharCharacter letter code for the option
dfltDefault value of the option string

Reimplemented from PArgList.

virtual PString PConfigArgs::GetOptionString ( const char *  optionStr,
const char *  dflt = NULL 
) const
virtual

Get option string.

Parameters
optionStrString letter code for the option
dfltDefault value of the option string

Reimplemented from PArgList.

virtual PString PConfigArgs::GetOptionString ( const PString optionName,
const char *  dflt = NULL 
) const
virtual

Get option string.

Parameters
optionNameString code for the option
dfltDefault value of the option string

Reimplemented from PArgList.

const PString& PConfigArgs::GetSectionName ( ) const
inline

Get the PConfig section name for options.

References sectionName.

void PConfigArgs::Save ( const PString optionName)

Save the current options to the PConfig.

This function will check to see if the option name is present and if so, save to the PConfig all of the arguments present in the currently parsed list. Note that the optionName for saving is not saved to the PConfig itself as this would cause the data to be saved always!

Parameters
optionNameOption name for saving.
void PConfigArgs::SetNegationPrefix ( const PString prefix)
inline

Set the prefix for option negation.

The default is "no-".

Parameters
prefixNew prefix string

References negationPrefix.

void PConfigArgs::SetSectionName ( const PString section)
inline

Set the PConfig section name for options.

Parameters
sectionNew section name

References sectionName.

Member Data Documentation

PConfig PConfigArgs::config
protected
PString PConfigArgs::negationPrefix
protected
PString PConfigArgs::sectionName
protected

Referenced by GetSectionName(), and SetSectionName().


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