PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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:
Collaboration diagram for PConfigArgs:

Public Member Functions

Construction
 PConfigArgs (const PArgList &args)
 
 ~PConfigArgs ()
 
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 (const char *theArgStr)
 
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...
 
void SetCommandName (const PString &name)
 Set the comand name. More...
 
const PStringGetCommandName () const
 Get the command name. More...
 
virtual bool Parse (const char *theArgumentSpec=NULL, PBoolean optionsBeforeParams=true)
 Parse the arguments. More...
 
virtual bool Parse (const PString &theArgumentStr, PBoolean optionsBeforeParams=true)
 Parse the arguments. More...
 
bool IsParsed () const
 Determine if already parsed at least once. More...
 
const PStringGetParseError () const
 Return error message after a call to Parse(). More...
 
ostream & Usage (ostream &strm, const char *usage=NULL, const char *prefix="Usage: ") const
 Output usage text for parsed arguments. More...
 
PString Usage (const char *usage=NULL, const char *prefix="Usage: ") const
 
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...
 
template<typename ValueType , typename OptionType >
ValueType GetOptionAs (OptionType option, ValueType value=0) const
 Get option as specicied type. 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...
 
- Public Member Functions inherited from PObject
__inline unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
__inline void SetTraceContextIdentifier (unsigned id)
 
__inline void SetTraceContextIdentifier (const PObject &obj)
 
__inline void SetTraceContextIdentifier (const PObject *obj)
 
__inline void CopyTraceContextIdentifier (PObject &obj) const
 
__inline void CopyTraceContextIdentifier (PObject *obj) const
 
virtual ~PObject ()
 
__inline const char * GetClass () const
 
__inline bool IsClass (const char *name) const
 
__inline const PObjectPTraceObjectInstance () const
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. 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 void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Protected Member Functions

PString CharToString (char ch) const
 
- Protected Member Functions inherited from PArgList
bool InternalSpecificationError (bool isError, const PString &msg)
 
size_t InternalFindOption (const PString &name) const
 
int InternalParseOption (const PString &opt, PINDEX offset, PINDEX &arg)
 
PINDEX InternalGetOptionCountByIndex (size_t idx) const
 
PString InternalGetOptionStringByIndex (size_t idx, const char *dflt) const
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

PConfigm_config
 
PString m_sectionName
 
PString m_negationPrefix
 
- Protected Attributes inherited from PArgList
PString m_commandName
 
bool m_parsed
 
PString m_parseError
 
PStringArray m_argumentArray
 
vector< OptionSpecm_options
 
PIntArray m_parameterIndex
 The index of each parameter. More...
 
int m_shift
 Shift count for the parameters in the argument list. More...
 
int m_argsParsed
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

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 __inline void CopyTraceContextIdentifier (PObject &to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject *from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject *from)
 
static __inline const char * Class ()
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
template<typename T >
static Comparison Compare2 (T v1, T v2)
 Compare two types, returning Comparison type. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
- Protected Types inherited from PArgList
enum  OptionType { NoString, HasString, OptionalString }
 

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.
PConfigArgs::~PConfigArgs ( )

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 m_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 m_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 m_negationPrefix.

void PConfigArgs::SetSectionName ( const PString section)
inline

Set the PConfig section name for options.

Parameters
sectionNew section name

References m_sectionName.

Member Data Documentation

PConfig* PConfigArgs::m_config
protected
PString PConfigArgs::m_negationPrefix
protected
PString PConfigArgs::m_sectionName
protected

Referenced by GetSectionName(), and SetSectionName().


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