PIP  0.4.0_beta2
Platform-Independent Primitives
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PICLI Class Reference

Command-line arguments parser. More...

+ Inheritance diagram for PICLI:

Public Member Functions

 PICLI (int argc, char *argv[])
 Constructor.
 
void addArgument (const PIString &name, bool value=false)
 Add argument with name "name", short key = name first letter, full key = name.
 
void addArgument (const PIString &name, const PIChar &shortKey, bool value=false)
 Add argument with name "name", short key = "shortKey", full key = name.
 
void addArgument (const PIString &name, const char *shortKey, bool value=false)
 Add argument with name "name", short key = "shortKey", full key = name.
 
void addArgument (const PIString &name, const PIChar &shortKey, const PIString &fullKey, bool value=false)
 Add argument with name "name", short key = "shortKey", full key = "fullKey".
 
void addArgument (const PIString &name, const char *shortKey, const PIString &fullKey, bool value=false)
 Add argument with name "name", short key = "shortKey", full key = "fullKey".
 
PIString rawArgument (int index)
 Returns unparsed command-line argument by index "index". Index 0 is program execute command.
 
const PIStringListrawArguments ()
 Returns unparsed command-line arguments.
 
PIString programCommand ()
 Returns program execute command without arguments.
 
- Public Member Functions inherited from PIObject
 PIObject (const PIString &name=PIString())
 Contructs PIObject with name "name".
 
PIString name () const
 Returns object name.
 
virtual const char * className () const
 Returns object class name.
 
bool debug () const
 Return if debug of this object is active.
 
void setName (const PIString &name)
 Set object name.
 
void setDebug (bool debug)
 Set object debug active.
 
const PIMap< PIString,
PIVariant > & 
properties () const
 Returns properties of the object.
 
int propertiesCount () const
 Returns properties count of the object.
 
PIVariant property (const PIString &name) const
 Returns property with name "name".
 
void setProperty (const PIString &name, const PIVariant &value)
 Set property with name "name" to "value". If there is no such property in object it will be added.
 
bool isPropertyExists (const PIString &name) const
 Returns if property with name "name" exists.
 

Additional Inherited Members

- Static Public Member Functions inherited from PIObject
static void piDisconnect (PIObject *src, const PIString &sig)
 Disconnect object "src" from all connections with event name "sig".
 
static void piDisconnect (PIObject *src)
 Disconnect object "src" from all connections, i.e. all connections where object "src" is emitter.
 
static PIObjectfindByName (const PIString &name)
 Returns PIObject* with name "name" or 0, if there is no object found.
 
- Protected Member Functions inherited from PIObject
PIObjectemitter () const
 Returns PIObject* which has raised an event. This value is correct only in definition of some event handler.
 
virtual void propertyChanged (const PIString &name)
 Virtual function executes after property with name "name" has been changed.
 

Detailed Description

Command-line arguments parser.

Synopsis

This class provide handy parsing of command-line arguments. First you should add arguments to PICLI with function addArgument(). Then you can check if there is some argument in application command-line with function hasArgument();

Example

int main(int argc, char ** argv) {
PICLI cli(argc, argv);
cli.addArgument("console");
cli.addArgument("debug");
cli.addArgument("Value", "v", "value", true);
if (cli.hasArgument("console"))
piCout << "console active";
if (cli.hasArgument("debug"))
piCout << "debug active";
piCout << "Value =" << cli.argumentValue("Value");
return 0;
}
These executions are similar:
a.out -cd -v 10
a.out --value 10 -dc
a.out -c -v 10 -d
a.out --console -d -v 10
a.out --debug -c --value 10