All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
args.h
Go to the documentation of this file.
/*
* args.h
*
* Program Argument Parsing class
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_ARGLIST_H
#define PTLIB_ARGLIST_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
class PArgList : public PObject
{
PCLASSINFO(PArgList, PObject);
public:
PArgList(
const char * theArgPtr = NULL,
const char * argumentSpecPtr = NULL,
PBoolean optionsBeforeParams = true
);
PArgList(
const PString & theArgStr,
const char * argumentSpecPtr = NULL,
PBoolean optionsBeforeParams = true
);
PArgList(
const PString & theArgStr,
const PString & argumentSpecStr,
PBoolean optionsBeforeParams = true
);
PArgList(
int theArgc,
char ** theArgv,
const char * argumentSpecPtr = NULL,
PBoolean optionsBeforeParams = true
);
PArgList(
int theArgc,
char ** theArgv,
const PString & argumentSpecStr,
PBoolean optionsBeforeParams = true
);
virtual void PrintOn(
ostream & strm
) const;
virtual void ReadFrom(
istream & strm
);
void SetArgs(
const PString & theArgStr
);
void SetArgs(
int theArgc,
char ** theArgv
);
void SetArgs(
const PStringArray & theArgs
);
virtual PBoolean Parse(
const char * theArgumentSpec,
PBoolean optionsBeforeParams = true
);
virtual PBoolean Parse(
const PString & theArgumentStr,
PBoolean optionsBeforeParams = true
);
virtual PINDEX GetOptionCount(
char optionChar
) const;
virtual PINDEX GetOptionCount(
const char * optionStr
) const;
virtual PINDEX GetOptionCount(
const PString & optionName
) const;
PBoolean HasOption(
char optionChar
) const;
PBoolean HasOption(
const char * optionStr
) const;
PBoolean HasOption(
const PString & optionName
) const;
virtual PString GetOptionString(
char optionChar,
const char * dflt = NULL
) const;
virtual PString GetOptionString(
const char * optionStr,
const char * dflt = NULL
) const;
virtual PString GetOptionString(
const PString & optionName,
const char * dflt = NULL
) const;
PINDEX GetCount() const;
PStringArray GetParameters(
PINDEX first = 0,
PINDEX last = P_MAX_INDEX
) const;
PString GetParameter(
PINDEX num
) const;
PString operator[](
PINDEX num
) const;
void Shift(
int sh
);
PArgList & operator<<(
int sh
);
PArgList & operator>>(
int sh
);
virtual void IllegalArgumentIndex(
PINDEX idx
) const;
virtual void UnknownOption(
const PString & option
) const;
virtual void MissingArgument(
const PString & option
) const;
protected:
PStringArray argumentArray;
PString optionLetters;
PStringArray optionNames;
PIntArray optionCount;
PStringArray optionString;
PIntArray parameterIndex;
int shift;
private:
PBoolean ParseOption(PINDEX idx, PINDEX offset, PINDEX & arg, const PIntArray & canHaveOptionString);
PINDEX GetOptionCountByIndex(PINDEX idx) const;
PString GetOptionStringByIndex(PINDEX idx, const char * dflt) const;
int m_argsParsed;
};
#ifdef P_CONFIG_FILE
class PConfigArgs : public PArgList
{
PCLASSINFO(PConfigArgs, PArgList);
public:
PConfigArgs(
const PArgList & args
);
virtual PINDEX GetOptionCount(
char optionChar
) const;
virtual PINDEX GetOptionCount(
const char * optionStr
) const;
virtual PINDEX GetOptionCount(
const PString & optionName
) const;
virtual PString GetOptionString(
char optionChar,
const char * dflt = NULL
) const;
virtual PString GetOptionString(
const char * optionStr,
const char * dflt = NULL
) const;
virtual PString GetOptionString(
const PString & optionName,
const char * dflt = NULL
) const;
void Save(
const PString & optionName
);
void SetSectionName(
const PString & section
) { sectionName = section; }
const PString & GetSectionName() const { return sectionName; }
void SetNegationPrefix(
const PString & prefix
) { negationPrefix = prefix; }
const PString & GetNegationPrefix() const { return negationPrefix; }
protected:
PString CharToString(char ch) const;
PConfig config;
PString sectionName;
PString negationPrefix;
};
#endif // P_CONFIG_FILE
#endif // PTLIB_ARGLIST_H
// End Of File ///////////////////////////////////////////////////////////////
PArgList::parameterIndex
PIntArray parameterIndex
The index of each .
Definition: args.h:317
PArgList::SetArgs
void SetArgs(const PString &theArgStr)
Set the internal copy of the program arguments.
PArgList::UnknownOption
virtual void UnknownOption(const PString &option) const
This function is called when an unknown option was specified on the command line. ...
PArgList::operator[]
PString operator[](PINDEX num) const
Get the parameter that was parsed in the argument list.
PArgList::optionString
PStringArray optionString
The array of associated strings to options.
Definition: args.h:315
PArgList::shift
int shift
Shift count for the parameters in the argument list.
Definition: args.h:319
PConfigArgs::GetOptionCount
virtual PINDEX GetOptionCount(char optionChar) const
Get the count of the number of times the option was specified on the command line.
PArgList::GetParameters
PStringArray GetParameters(PINDEX first=0, PINDEX last=P_MAX_INDEX) const
Get the parameters that were parsed in the argument list.
PArgList::PArgList
PArgList(const char *theArgPtr=NULL, const char *argumentSpecPtr=NULL, PBoolean optionsBeforeParams=true)
Create an argument list.
PArgList::operator>>
PArgList & operator>>(int sh)
Shift the parameters by the specified amount.
PConfigArgs::PConfigArgs
PConfigArgs(const PArgList &args)
PConfig
A class representing a configuration for the application.
Definition: config.h:67
PArgList::GetParameter
PString GetParameter(PINDEX num) const
Get the parameter that was parsed in the argument list.
PConfigArgs::negationPrefix
PString negationPrefix
Definition: args.h:430
PArgList::operator<<
PArgList & operator<<(int sh)
Shift the parameters by the specified amount.
PConfigArgs::Save
void Save(const PString &optionName)
Save the current options to the PConfig.
PStringArray
This is an array collection class of PString objects.
Definition: pstring.h:2024
PConfigArgs::GetNegationPrefix
const PString & GetNegationPrefix() const
Get the prefix for option negation.
Definition: args.h:422
PConfigArgs::SetSectionName
void SetSectionName(const PString &section)
Set the PConfig section name for options.
Definition: args.h:404
PBoolean
BOOL PBoolean
Definition: object.h:102
PArgList::HasOption
PBoolean HasOption(char optionChar) const
Get if option present.
PConfigArgs::CharToString
PString CharToString(char ch) const
PConfigArgs::SetNegationPrefix
void SetNegationPrefix(const PString &prefix)
Set the prefix for option negation.
Definition: args.h:415
PArgList::optionLetters
PString optionLetters
The specification letters for options.
Definition: args.h:309
PArgList::optionNames
PStringArray optionNames
The specification strings for options.
Definition: args.h:311
PArgList::Parse
virtual PBoolean Parse(const char *theArgumentSpec, PBoolean optionsBeforeParams=true)
Parse the arguments.
PConfigArgs::GetOptionString
virtual PString GetOptionString(char optionChar, const char *dflt=NULL) const
Get option string.
PConfigArgs
This class parse command line arguments with the ability to override them from a PConfig file/registr...
Definition: args.h:334
PArgList::ReadFrom
virtual void ReadFrom(istream &strm)
Input the string from the specified stream.
PString
The character string class.
Definition: pstring.h:108
PArgList::GetOptionCount
virtual PINDEX GetOptionCount(char optionChar) const
Get the count of the number of times the option was specified on the command line.
PArgList
This class allows the parsing of a set of program arguments.
Definition: args.h:45
PArgList::optionCount
PIntArray optionCount
The count of the number of times an option appeared in the command line.
Definition: args.h:313
PArgList::argumentArray
PStringArray argumentArray
The original program arguments.
Definition: args.h:307
PArgList::PrintOn
virtual void PrintOn(ostream &strm) const
Output the string to the specified stream.
PConfigArgs::GetSectionName
const PString & GetSectionName() const
Get the PConfig section name for options.
Definition: args.h:410
PConfigArgs::config
PConfig config
Definition: args.h:428
PArgList::IllegalArgumentIndex
virtual void IllegalArgumentIndex(PINDEX idx) const
This function is called when access to illegal parameter index is made in the GetParameter function...
PConfigArgs::sectionName
PString sectionName
Definition: args.h:429
PArgList::GetCount
PINDEX GetCount() const
Get the argument count.
PIntArray
Array of integers.
Definition: array.h:616
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PArgList::MissingArgument
virtual void MissingArgument(const PString &option) const
This function is called when an option that requires an associated string was specified on the comman...
PArgList::GetOptionString
virtual PString GetOptionString(char optionChar, const char *dflt=NULL) const
Get option string.
PArgList::Shift
void Shift(int sh)
Shift the parameters by the specified amount.