C12Adapter Opensource C++ Interface
MCommandLineParser Class Reference

Command line parser to help dealing with argv and argc arguments within function main. More...

Public Types

enum  {
  HelpOutputLineLength = 80,
  HelpOutputBorder = 20
}
 

Public Member Functions

 MCommandLineParser ()
 Create a new command line parser. More...
 
 ~MCommandLineParser ()
 Destroy the object and reclaim its resources back to the operating system.
 
void DeclareFlag (char shortName, const char *longName, const char *description, bool &destination)
 Declare boolean flag that the command line will take. More...
 
void DeclareNamedBool (char shortName, const char *longName, const char *description, bool &destination)
 Declare a named argument of boolean type, one given as a flag with value. More...
 
void DeclareNamedInt (char shortName, const char *longName, const char *label, const char *description, int &destination)
 Declare a named argument of integer type, one given as a flag with value. More...
 
void DeclareNamedUnsignedInt (char shortName, const char *longName, const char *label, const char *description, unsigned &destination)
 Declare a named argument of unsigned integer type, one given as a flag with value. More...
 
void DeclareNamedDouble (char shortName, const char *longName, const char *label, const char *description, double &destination)
 Declare a named argument of double precision floating point type, one given as a flag with value. More...
 
void DeclareNamedString (char shortName, const char *longName, const char *label, const char *description, MStdString &destination)
 Declare a named argument of string type, one given as a flag with value. More...
 
void DeclareBool (const char *label, const char *description, bool &destination)
 Declare mandatory positional argument of Boolean type. More...
 
void DeclareInt (const char *label, const char *description, int &destination)
 Declare mandatory positional argument of integer type. More...
 
void DeclareUnsignedInt (const char *label, const char *description, unsigned &destination)
 Declare mandatory positional argument of unsigned integer type. More...
 
void DeclareDouble (const char *label, const char *description, double &destination)
 Declare mandatory positional argument of double precision floating point type. More...
 
void DeclareString (const char *label, const char *description, MStdString &destination)
 Declare mandatory positional argument of string type. More...
 
void DeclareOptionalInt (const char *label, const char *description, int &destination)
 Declare optional positional argument of integer type. More...
 
void DeclareOptionalUnsignedInt (const char *label, const char *description, unsigned &destination)
 Declare optional positional argument of unsigned integer type. More...
 
void DeclareOptionalDouble (const char *label, const char *description, double &destination)
 Declare optional positional argument of double precision floating point type. More...
 
void DeclareOptionalString (const char *label, const char *description, MStdString &destination)
 Declare optional positional argument of string type. More...
 
void DeclareStringVector (const char *label, const char *description, MStdStringVector &destination)
 Declare a list of positional arguments, strings. More...
 
MStreamGetErrorStream ()
 
void SetErrorStream (MStream *stream)
 
MStreamGetOutputStream ()
 
void SetOutputStream (MStream *stream)
 
const MStdStringGetCopyright () const
 
void SetCopyright (const char *copyrightMessage)
 
void SetCopyright (const MStdString &copyrightMessage)
 
const MStdStringGetDescription () const
 
void SetDescription (const char *description)
 
void SetDescription (const MStdString &description)
 
const MStdStringGetVersion () const
 
void SetVersion (const char *versionString)
 
void SetVersion (const MStdString &versionString)
 
const MStdStringGetExecutableName () const
 
void SetExecutableName (const char *name)
 
void SetExecutableName (const MStdString &name)
 
const MStdStringGetBuildDate () const
 
void SetBuildDate (const char *date)
 
void SetBuildDate (const MStdString &date)
 
const MStdStringGetFooter () const
 
void SetFooter (const char *footer)
 
void SetFooter (const MStdString &footer)
 
int Process (int argc, const char **argv)
 
int Process (int argc, char **argv)
 
int Process (const char *commandLine)
 
int Process (const MStdString &commandLine)
 
void WriteHelp ()
 @) More...
 
void WriteHeader ()
 Write software header to the stream. More...
 
void WriteUsage ()
 Write usage to the output stream supplied based on the already given Declare methods. More...
 
void WriteFooter ()
 Write software header to the stream. More...
 
void WriteException (MException &ex)
 Write the given exception to the error stream. More...
 
void WriteError (const char *fmt,...)
 Write the given error text with variable number of arguments to the error stream. More...
 
void WriteError (const MStdString &text)
 Write the given error text to the error stream. More...
 

Detailed Description

Command line parser to help dealing with argv and argc arguments within function main.

This is a C++ only class. Use it to parse UNIX like flags and parameters passed to a command line tool. Here is a typical usage:

parser.SetDescription("Universal communicator command line application");
parser.SetBuildDate(__DATE__); // this repeats what is done inside the constructor already
parser.DeclareNamedString('f', "config", "Configuration file path", ""), configFile); // -f with value
parser.DeclareNamedInt('c', "count", "Device count", // -c with value
"Overwrite count parameter in the configuration file", count);
parser.DeclareFlag('s', "save", "Save temporary data", save); // -s
parser.DeclareFlag('m', "monitor", "Use Monitor.", useMonitor); // -m
parser.DeclareFlag('r', "relay", "Communicate through relay.", useRelay);
parser.DeclareNamedString('h', "relay-host", "Relay host.", "", relayHost);
int result = parser.Process(argc, argv); // here all the above variables will be initialized
if ( result > 0 ) // successful completion with an already handled option such as --version
return EXIT_SUCCESS; // everything is done already inside of Process()
else if ( result < 0 ) // failure in parameters given, error is reported already
return EXIT_FAILURE; // everything is done already inside of Process()
// case when the result is zero is when all parameters are parsed
// and further processing shall be done by a program

Constructor & Destructor Documentation

MCommandLineParser::MCommandLineParser ( )

Create a new command line parser.

This will typically be a local class within function main. After creation, the next set of actions will be defining parameters and flags with Declare, and calling Process.

Member Function Documentation

void MCommandLineParser::DeclareBool ( const char *  label,
const char *  description,
bool &  destination 
)

Declare mandatory positional argument of Boolean type.

The order of positional Declare calls determines the order of arguments. For example:

parser.DeclareBool("print", "Print or not", print);
parser.DeclareInt("times", "How many times to perform an action", times);

Determines two parameters, first is a Boolean and a second is an integer.

The accepted argument for boolean types are:

  • "false", "no", 'f', 'n' or '0' for false, all letters are case insensitive
  • "true", "yes", 't', 'y' or '1' for true, all letters are case insensitive
Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to an integer value into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareDouble ( const char *  label,
const char *  description,
double &  destination 
)

Declare mandatory positional argument of double precision floating point type.

The order of positional Declare calls determines the order of arguments. For example:

parser.DeclareString("action", "Action to perform", action);
parser.DeclareDouble("multiplier", "Multiplier parameter", multiplier);

Determines two parameters, first is a string and a second is a floating point number.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a floating point number value into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareFlag ( char  shortName,
const char *  longName,
const char *  description,
bool &  destination 
)

Declare boolean flag that the command line will take.

Flag is a named entity with a short name such as -r, or long name such as –recursive. Presence of the flag in the command line is determined by a boolean parameter destination, which shall be initialized into false prior to this call.

Parameters
shortNameOne character, the short flag name, such as 'r' for '-r' flag. If this is '\0' the flag has no short name (it has to have a long name in this case)
longNameParameter long name, such as 'recursive' for '–recursive' flag. If this is an empty string the flag has no long name (it has to have a short name in this case)
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to boolean value that will be controlled by presence of such flag in the command line. The particular variable to which this parameter refers will typically be initialized with false. When the flag is present in the command line, after calling any of Process functions, the value will become true.
void MCommandLineParser::DeclareInt ( const char *  label,
const char *  description,
int &  destination 
)

Declare mandatory positional argument of integer type.

The order of positional Declare calls determines the order of arguments. For example:

parser.DeclareString("action", "Action to perform", action);
parser.DeclareInt("times", "How many times to perform an action", times);

Determines two parameters, first is a string and a second is an integer.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to an integer value into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareNamedBool ( char  shortName,
const char *  longName,
const char *  description,
bool &  destination 
)

Declare a named argument of boolean type, one given as a flag with value.

Such named argument is always optional, and its presence can be determined by whether or not the default value of destination is unchanged. It can appear at any position in the list. Example:

parser.DeclareNamedBool('g', "go", "Go or no go", goBool);
// possible uses in the command line:
// -g1
// -g Y
// --go=f
// --go n

If the argument is not supplied, the above mentioned goBool will be unchanged at Process call.

The accepted argument for boolean types are:

  • "false", "no", 'f', 'n' or '0' for false, all letters are case insensitive
  • "true", "yes", 't', 'y' or '1' for true, all letters are case insensitive

Different from the other named parameters, the boolean variant does not have label, as it will always be "0/1"

Parameters
shortNameOne character, the short flag name, such as 'g' for '-g1' flag with value. If this is '\0' the flag has no short name (it has to have a long name in this case)
longNameParameter long name, such as 'go' for '–go=0' flag with value. If this is an empty string the flag has no long name (it has to have a short name in this case)
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a boolean value into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareNamedDouble ( char  shortName,
const char *  longName,
const char *  label,
const char *  description,
double &  destination 
)

Declare a named argument of double precision floating point type, one given as a flag with value.

Such argument is always optional, and its presence can be determined by whether or not the default value of destination is unchanged. It can appear at any position in the list. Example:

parser.DeclareNamedString('m', "multiplier", "mul", "Multiplier of the value", mul);
// possible uses in the command line:
// -m3.14
// -m 5.7
// --multiplier=5.0
// --multiplier 123

If the argument is not supplied, the above mentioned mul will be unchanged at Process call.

Parameters
shortNameOne character, the short flag name, such as 'x' for '-x3.13' flag with value. If this is '\0' the flag has no short name (it has to have a long name in this case)
longNameParameter long name, such as 'number' for '–number=4' flag with value. If this is an empty string the flag has no long name (it has to have a short name in this case)
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a double precision floating point value into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareNamedInt ( char  shortName,
const char *  longName,
const char *  label,
const char *  description,
int &  destination 
)

Declare a named argument of integer type, one given as a flag with value.

Such argument is always optional, and its presence can be determined by whether or not the default value of destination is unchanged. It can appear at any position in the list. Example:

parser.DeclareNamedString('n', "number", "cnt", "Number of actions", num);
// possible uses in the command line:
// -n3
// -n 5
// --number=5
// --number 5

If the argument is not supplied, the above mentioned num will be unchanged at Process call.

Parameters
shortNameOne character, the short flag name, such as 'n' for '-n4' flag with value. If this is '\0' the flag has no short name (it has to have a long name in this case)
longNameParameter long name, such as 'number' for '–number=4' flag with value. If this is an empty string the flag has no long name (it has to have a short name in this case)
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a integer value into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareNamedString ( char  shortName,
const char *  longName,
const char *  label,
const char *  description,
MStdString destination 
)

Declare a named argument of string type, one given as a flag with value.

Such argument is always optional, and its presence can be determined by whether or not the default value of destination is unchanged. It can appear at any position in the list. Example:

parser.DeclareNamedString('o', "output-file", "file.name", "Output file name", outputFile);
// possible uses in the command line:
// -ofilename.txt
// -o filename.txt
// --output-file=filename.txt
// --output-file filename.txt

If the argument is not supplied, the above mentioned outputFile will be unchanged at Process call.

Parameters
shortNameOne character, the short flag name, such as 'f' for '-f file.txt' flag with value. If this is '\0' the flag has no short name (it has to have a long name in this case)
longNameParameter long name, such as 'number' for '–number=4' flag with value. If this is an empty string the flag has no long name (it has to have a short name in this case)
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a string value into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareNamedUnsignedInt ( char  shortName,
const char *  longName,
const char *  label,
const char *  description,
unsigned &  destination 
)

Declare a named argument of unsigned integer type, one given as a flag with value.

Such argument is always optional, and its presence can be determined by whether or not the default value of destination is unchanged. It can appear at any position in the list. Example:

parser.DeclareNamedUnsignedString('n', "number", "cnt", "Number of actions", num);
// possible uses in the command line:
// -n3
// -n 5
// --number=5
// --number 5

If the argument is not supplied, the above mentioned num will be unchanged at Process call.

Parameters
shortNameOne character, the short flag name, such as 'n' for '-n4' flag with value. If this is '\0' the flag has no short name (it has to have a long name in this case)
longNameParameter long name, such as 'number' for '–number=4' flag with value. If this is an empty string the flag has no long name (it has to have a short name in this case)
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to an unsigned integer value into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareOptionalDouble ( const char *  label,
const char *  description,
double &  destination 
)

Declare optional positional argument of double precision floating point type.

The order of positional Declare calls determines the order of arguments. Optional arguments can only be at the tail of the argument list, if any of them are present, DeclareStringVector shall not be used. Whether or not an optional argument was specified in the command line can determined by whether or not the destination variable was changed from its initial value.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a double precision floating point value into which the argument will be written at the time the Process method is called.
See also
DeclareDouble - mandatory double precision floating point argument
void MCommandLineParser::DeclareOptionalInt ( const char *  label,
const char *  description,
int &  destination 
)

Declare optional positional argument of integer type.

The order of positional Declare calls determines the order of arguments. Optional arguments can only be at the tail of the argument list, if any of them are present, DeclareStringVector shall not be used. Whether or not an optional argument was specified in the command line can determined by whether or not the destination variable was changed from its initial value.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to an integer value into which the argument will be written at the time the Process method is called.
See also
DeclareInt - mandatory integer argument
void MCommandLineParser::DeclareOptionalString ( const char *  label,
const char *  description,
MStdString destination 
)

Declare optional positional argument of string type.

The order of positional Declare calls determines the order of arguments. Optional arguments can only be at the tail of the argument list, if any of them are present, DeclareStringVector shall not be used. Whether or not an optional argument was specified in the command line can determined by whether or not the destination variable was changed from its initial value.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a string value into which the argument will be written at the time the Process method is called.
See also
DeclareString - mandatory argument
DeclareStringVector - variable size list of arguments
void MCommandLineParser::DeclareOptionalUnsignedInt ( const char *  label,
const char *  description,
unsigned &  destination 
)

Declare optional positional argument of unsigned integer type.

The order of positional Declare calls determines the order of arguments. Optional arguments can only be at the tail of the argument list, if any of them are present, DeclareStringVector shall not be used. Whether or not an optional argument was specified in the command line can determined by whether or not the destination variable was changed from its initial value.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to an unsigned integer value into which the argument will be written at the time the Process method is called.
See also
DeclareUnsignedInt - mandatory unsigned integer argument
void MCommandLineParser::DeclareString ( const char *  label,
const char *  description,
MStdString destination 
)

Declare mandatory positional argument of string type.

The order of positional Declare calls determines the order of arguments. For example:

parser.DeclareString("source", "Source from which to copy", src);
parser.DeclareString("destination", "Where to copy", destination);

Determines the parameters for a command line utility that copies one given entity into another.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a string value into which the argument will be written at the time the Process method is called.
See also
DeclareOptionalString - optional argument
void MCommandLineParser::DeclareStringVector ( const char *  label,
const char *  description,
MStdStringVector destination 
)

Declare a list of positional arguments, strings.

This call will declare a list of arguments, and it is the only way to have optional parameters without names. The list will be located after all positional arguments.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to a string vector into which the argument will be written at the time the Process method is called.
void MCommandLineParser::DeclareUnsignedInt ( const char *  label,
const char *  description,
unsigned &  destination 
)

Declare mandatory positional argument of unsigned integer type.

The order of positional Declare calls determines the order of arguments. For example:

parser.DeclareString("action", "Action to perform", action);
parser.DeclareUnsignedInt("number", "How many times to execute action", number);

Determines two parameters, first is a string, and a second is an unsigned number.

Parameters
labelName of the value for the argument, typically one word, appears in help as value placeholder.
descriptionDescription of the flag, an English text. This text is shown to the user at –help option. Text wrapping is done automatically, therefore, the description shall not have line breaks.
destinationReference to an unsigned number value into which the argument will be written at the time the Process method is called.
const MStdString& MCommandLineParser::GetBuildDate ( ) const
inline

Build date, if it has to be passed explicitly.

Typically, there is no need to specify the build date, as it is assigned from DATE macro at the time of library compilation. This call is useful if the library is compiled separately from the application that uses it, in which case the usage will be like:

parser.SetBuildDate(__DATE__);
const MStdString& MCommandLineParser::GetCopyright ( ) const
inline

Copyright message to use in case the command line parser needs to show it to the user.

The copyright message is shown as part of usage message. By default, copyright message is initialized from customization macro M_PRODUCT_LEGAL_COPYRIGHT and in most cases there is no need to call SetCopyright explicitly. Otherwise it should be a single string that includes copyright years and message. Usage example:

parser.SetCopyright("Copyright (c) 2000-2010 The CompanyName Here");
const MStdString& MCommandLineParser::GetDescription ( ) const
inline

Set description message to use in case the command line parser needs to show it to the user.

The description is shown as part of usage message. By default, the description is empty, and it is always a good idea to call this method and specify a text. Usage example:

parser.SetDescription("Character encoding tool");
MStream* MCommandLineParser::GetErrorStream ( )
inline

Stream for error reporting

const MStdString& MCommandLineParser::GetExecutableName ( ) const
inline

Executable name, passed explicitly or fetched from argv

Typically, there is no need to specify the name of the executable, as it will be taken from the argv parameter at the time Process is called. This method is useful if there is a necessity to overwrite the default name.

const MStdString& MCommandLineParser::GetFooter ( ) const
inline

Set footer message to use in case the command line parser needs to show it to the user.

The footer is typically a list of examples and further references. By default, the footer is empty.

MStream* MCommandLineParser::GetOutputStream ( )
inline

Stream for regular output

const MStdString& MCommandLineParser::GetVersion ( ) const
inline

String representation of version for the command line tool

The version is shown as part of usage message, and also, when the user requests it with –version flag. Typically, there is no need to specify the version with this call, as by default, M_PRODUCT_VERSION customization macro is used.

Usage example:

parser.SetVersion("1.2");
int MCommandLineParser::Process ( int  argc,
const char **  argv 
)

Process the arguments given as argc and argv using previously defined command line flags and parameters

Prior to this call, the parameters and flags shall be declared with a set of Declare methods.

Parameters
argcArgument count as given to function main
argvList of arguments as given to function main. ANSI C standard requires the item after last to be NULL.
Returns
int - success indicator with the following possible values:
  • Positive value means the parameters are processed successfully, but the given flags are as such that nothing shall be done by a program. For example, this is how –help or –version are handled.
  • Negative value means there is an error in parameters detected, this error is reported, and the program shall immediately exit with failure status.
  • Zero means the parameters are processed successfully and variables given to Declare methods are initialized. The program is expected to continue with its own actions based on parameters supplied.
int MCommandLineParser::Process ( int  argc,
char **  argv 
)
inline

Process the arguments given as argc and argv using previously defined command line flags and parameters

Prior to this call, the parameters and flags shall be declared with a set of Declare methods.

Parameters
argcArgument count as given to function main
argvList of arguments as given to function main. ANSI C standard requires the item after last to be NULL.
Returns
int - success indicator with the following possible values:
  • Positive value means the parameters are processed successfully, but the given flags are as such that nothing shall be done by a program. For example, this is how –help or –version are handled.
  • Negative value means there is an error in parameters detected, this error is reported, and the program shall immediately exit with failure status.
  • Zero means the parameters are processed successfully and variables given to Declare methods are initialized. The program is expected to continue with its own actions based on parameters supplied.
int MCommandLineParser::Process ( const char *  commandLine)

Process command line from string using previously defined command line flags and parameters

Prior to this call, the parameters and flags shall be declared with a set of Declare methods.

Parameters
commandLineWhole command line including the application name
Returns
int - success indicator with the following possible values:
  • Positive value means the parameters are processed successfully, but the given flags are as such that nothing shall be done by a program. For example, this is how –help or –version are handled.
  • Negative value means there is an error in parameters detected, this error is reported, and the program shall immediately exit with failure status.
  • Zero means the parameters are processed successfully and variables given to Declare methods are initialized. The program is expected to continue with its own actions based on parameters supplied.
int MCommandLineParser::Process ( const MStdString commandLine)
inline

Process command line from string using previously defined command line flags and parameters

Prior to this call, the parameters and flags shall be declared with a set of Declare methods.

Parameters
commandLineWhole command line including the application name
Returns
int - success indicator with the following possible values:
  • Positive value means the parameters are processed successfully, but the given flags are as such that nothing shall be done by a program. For example, this is how –help or –version are handled.
  • Negative value means there is an error in parameters detected, this error is reported, and the program shall immediately exit with failure status.
  • Zero means the parameters are processed successfully and variables given to Declare methods are initialized. The program is expected to continue with its own actions based on parameters supplied.
void MCommandLineParser::SetBuildDate ( const char *  date)
inline

Build date, if it has to be passed explicitly.

Typically, there is no need to specify the build date, as it is assigned from DATE macro at the time of library compilation. This call is useful if the library is compiled separately from the application that uses it, in which case the usage will be like:

parser.SetBuildDate(__DATE__);
void MCommandLineParser::SetBuildDate ( const MStdString date)
inline

Build date, if it has to be passed explicitly.

Typically, there is no need to specify the build date, as it is assigned from DATE macro at the time of library compilation. This call is useful if the library is compiled separately from the application that uses it, in which case the usage will be like:

parser.SetBuildDate(__DATE__);
void MCommandLineParser::SetCopyright ( const char *  copyrightMessage)
inline

Copyright message to use in case the command line parser needs to show it to the user.

The copyright message is shown as part of usage message. By default, copyright message is initialized from customization macro M_PRODUCT_LEGAL_COPYRIGHT and in most cases there is no need to call SetCopyright explicitly. Otherwise it should be a single string that includes copyright years and message. Usage example:

parser.SetCopyright("Copyright (c) 2000-2010 The CompanyName Here");
void MCommandLineParser::SetCopyright ( const MStdString copyrightMessage)
inline

Copyright message to use in case the command line parser needs to show it to the user.

The copyright message is shown as part of usage message. By default, copyright message is initialized from customization macro M_PRODUCT_LEGAL_COPYRIGHT and in most cases there is no need to call SetCopyright explicitly. Otherwise it should be a single string that includes copyright years and message. Usage example:

parser.SetCopyright("Copyright (c) 2000-2010 The CompanyName Here");
void MCommandLineParser::SetDescription ( const char *  description)
inline

Set description message to use in case the command line parser needs to show it to the user.

The description is shown as part of usage message. By default, the description is empty, and it is always a good idea to call this method and specify a text. Usage example:

parser.SetDescription("Character encoding tool");
void MCommandLineParser::SetDescription ( const MStdString description)
inline

Set description message to use in case the command line parser needs to show it to the user.

The description is shown as part of usage message. By default, the description is empty, and it is always a good idea to call this method and specify a text. Usage example:

parser.SetDescription("Character encoding tool");
void MCommandLineParser::SetErrorStream ( MStream stream)
inline

Stream for error reporting

void MCommandLineParser::SetExecutableName ( const char *  name)
inline

Executable name, passed explicitly or fetched from argv

Typically, there is no need to specify the name of the executable, as it will be taken from the argv parameter at the time Process is called. This method is useful if there is a necessity to overwrite the default name.

void MCommandLineParser::SetExecutableName ( const MStdString name)
inline

Executable name, passed explicitly or fetched from argv

Typically, there is no need to specify the name of the executable, as it will be taken from the argv parameter at the time Process is called. This method is useful if there is a necessity to overwrite the default name.

void MCommandLineParser::SetFooter ( const char *  footer)
inline

Set footer message to use in case the command line parser needs to show it to the user.

The footer is typically a list of examples and further references. By default, the footer is empty.

void MCommandLineParser::SetFooter ( const MStdString footer)
inline

Set footer message to use in case the command line parser needs to show it to the user.

The footer is typically a list of examples and further references. By default, the footer is empty.

void MCommandLineParser::SetOutputStream ( MStream stream)
inline

Stream for regular output

void MCommandLineParser::SetVersion ( const char *  versionString)
inline

String representation of version for the command line tool

The version is shown as part of usage message, and also, when the user requests it with –version flag. Typically, there is no need to specify the version with this call, as by default, M_PRODUCT_VERSION customization macro is used.

Usage example:

parser.SetVersion("1.2");
void MCommandLineParser::SetVersion ( const MStdString versionString)
inline

String representation of version for the command line tool

The version is shown as part of usage message, and also, when the user requests it with –version flag. Typically, there is no need to specify the version with this call, as by default, M_PRODUCT_VERSION customization macro is used.

Usage example:

parser.SetVersion("1.2");
void MCommandLineParser::WriteError ( const char *  fmt,
  ... 
)

Write the given error text with variable number of arguments to the error stream.

This is a convenience method for helping programs report errors

Parameters
fmtStandard C format string followed by arguments
void MCommandLineParser::WriteError ( const MStdString text)

Write the given error text to the error stream.

This is a convenience method for helping programs report errors

Parameters
textString to write as error
void MCommandLineParser::WriteException ( MException ex)

Write the given exception to the error stream.

This is a convenience method for helping programs report errors

Parameters
exException to report
void MCommandLineParser::WriteFooter ( )

Write software header to the stream.

See also
WriteHeader
WriteUsage
WriteHelp - combines WriteHeader, WriteUsage, and WriteFooter
void MCommandLineParser::WriteHeader ( )

Write software header to the stream.

Write program name and copyright message to the output stream.

See also
WriteUsage
WriteFooter
WriteHelp - combines WriteHeader, WriteUsage, and WriteFooter
void MCommandLineParser::WriteHelp ( )

@)

Write program help to the output stream

Write Header, Usage and Footer to the output stream. This method is of rare use, as the command line parser handles –help and -h all by itself internally.

See also
WriteHeader
WriteUsage
WriteFooter
void MCommandLineParser::WriteUsage ( )

Write usage to the output stream supplied based on the already given Declare methods.

See also
WriteHeader
WriteFooter
WriteHelp - combines WriteHeader, WriteUsage, and WriteFooter