PixelLightAPI  .
Public Member Functions | Static Public Member Functions
PLCore::CommandLine Class Reference

Command line parser. More...

#include <CommandLine.h>

List of all members.

Public Member Functions

 CommandLine ()
 Constructor.
 ~CommandLine ()
 Destructor.
uint32 GetNumOfOptions () const
 Get number of registered options.
CommandLineOptionGetOption (uint32 nIndex) const
 Get option by index.
CommandLineOptionGetOption (const String &sName) const
 Get option by name.
PLCORE_API void Clear ()
 Delete all options.
PLCORE_API bool AddParameter (const String &sName, const String &sShort, const String &sLong, const String &sDescription, const String &sDefault, bool bRequired=false)
 Add parameter.
PLCORE_API bool AddFlag (const String &sName, const String &sShort, const String &sLong, const String &sDescription, bool bRequired=false)
 Add flag (on/off)
PLCORE_API bool AddArgument (const String &sName, const String &sDescription, const String &sDefault, bool bRequired=false)
 Add argument.
PLCORE_API bool ParseCommandLine (const Array< String > &lstArgs)
 Parse command line arguments.
bool HasErrors () const
 Check if there were any errors parsing the command line arguments.
PLCORE_API bool IsValueSet (const String &sName) const
 Check if an option value is set ('true' for boolean options or any other than "" for string values)
PLCORE_API String GetValue (const String &sName) const
 Get option value.
uint32 GetNumOfAdditionalArguments () const
 Get number of additional arguments that have been defined.
String GetAdditionalArgument (uint32 nIndex) const
 Get additional argument.
PLCORE_API void PrintHelp (const String &sProgramName) const
 Display a help text with all available options on the console.

Static Public Member Functions

static PLCORE_API String ArgumentsToString (const Array< String > &lstArguments)
 Convert a command array to a string.
static PLCORE_API Array< StringStringToArguments (const String &sCmdLine)
 Convert a command string to an array.

Detailed Description

Command line parser.

Remarks:
This class is used to define the command line arguments your application understands and parse a given command line string passed to the application. Typical problems like quotes and filenames, or errors like missing arguments or unknown options are automatically taken care of. This makes it quite easy to provide nice command line arguments for your application without having to go through parsing hell yourself :-)

Constructor & Destructor Documentation

Destructor.


Member Function Documentation

static PLCORE_API String PLCore::CommandLine::ArgumentsToString ( const Array< String > &  lstArguments) [static]

Convert a command array to a string.

Parameters:
[in]lstArgumentsList of arguments
Returns:
Command string
static PLCORE_API Array<String> PLCore::CommandLine::StringToArguments ( const String sCmdLine) [static]

Convert a command string to an array.

Parameters:
[in]sCmdLineCommand string
Returns:
Command array of arguments
uint32 PLCore::CommandLine::GetNumOfOptions ( ) const [inline]

Get number of registered options.

Returns:
Number of options that have been registered
CommandLineOption * PLCore::CommandLine::GetOption ( uint32  nIndex) const [inline]

Get option by index.

Parameters:
[in]nIndexIndex of the option to retrieve
Returns:
Pointer to option, or a null pointer
CommandLineOption * PLCore::CommandLine::GetOption ( const String sName) const [inline]

Get option by name.

Parameters:
[in]sNameName of the option to retrieve (short or long name)
Returns:
Pointer to option, or a null pointer
PLCORE_API void PLCore::CommandLine::Clear ( )

Delete all options.

PLCORE_API bool PLCore::CommandLine::AddParameter ( const String sName,
const String sShort,
const String sLong,
const String sDescription,
const String sDefault,
bool  bRequired = false 
)

Add parameter.

Parameters:
[in]sNameParameter name (logical name, must *not* start with "-" or "--")
[in]sShortShort name (must start with "-", e.g. "-a") or ""
[in]sLongLong name (must start with "--", e.g. "-optiona") or ""
[in]sDescriptionDescription text for this option
[in]sDefaultDefault value
[in]bRequiredIs the option required?
Returns:
'true' if option could be added, 'false' on error
Remarks:
A parameter is an option that can receive a value. Example: command --name <name>
PLCORE_API bool PLCore::CommandLine::AddFlag ( const String sName,
const String sShort,
const String sLong,
const String sDescription,
bool  bRequired = false 
)

Add flag (on/off)

Parameters:
[in]sNameParameter name (logical name, must *not* start with "-" or "--")
[in]sShortShort name (must start with "-", e.g. "-a") or ""
[in]sLongLong name (must start with "--", e.g. "-optiona") or ""
[in]sDescriptionDescription text for this option
[in]bRequiredIs the option required?
Returns:
'true' if option could be added, 'false' on error
Remarks:
A flag is an option that is either on or off (off as default). Example: command --option
PLCORE_API bool PLCore::CommandLine::AddArgument ( const String sName,
const String sDescription,
const String sDefault,
bool  bRequired = false 
)

Add argument.

Parameters:
[in]sNameParameter name (logical name, must *not* start with "-" or "--")
[in]sDescriptionDescription text for this option
[in]sDefaultDefault value
[in]bRequiredIs the option required?
Returns:
'true' if option could be added, 'false' on error
Remarks:
An argument is an option that can receive a value, but is not preceded by the option name (like a parameter). Example: command <name>
PLCORE_API bool PLCore::CommandLine::ParseCommandLine ( const Array< String > &  lstArgs)

Parse command line arguments.

Parameters:
[in]lstArgsList of arguments
Returns:
'true' if the command line could be parsed without error, else 'false'
bool PLCore::CommandLine::HasErrors ( ) const [inline]

Check if there were any errors parsing the command line arguments.

Returns:
'true' if there were errors, else 'false'
PLCORE_API bool PLCore::CommandLine::IsValueSet ( const String sName) const

Check if an option value is set ('true' for boolean options or any other than "" for string values)

Parameters:
[in]sNameName of option (short or long name)
Returns:
'true' if the value is set, else 'false'
PLCORE_API String PLCore::CommandLine::GetValue ( const String sName) const

Get option value.

Parameters:
[in]sNameName of option (short or long name)
Returns:
Value of option ("true"/"false" for boolean values)

Get number of additional arguments that have been defined.

Returns:
Number of additional arguments
Remarks:
Additional arguments are values that have been provided on the command line but do not belong to a specific option (for arbitrary number of arguments)
String PLCore::CommandLine::GetAdditionalArgument ( uint32  nIndex) const [inline]

Get additional argument.

Parameters:
[in]nIndexIndex of argument to get
Returns:
Additional argument, or ""
PLCORE_API void PLCore::CommandLine::PrintHelp ( const String sProgramName) const

Display a help text with all available options on the console.

Parameters:
[in]sProgramNameName of the program

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


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:16
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported