Public Member Functions

OptionManager Class Reference
[Global code used by all commands]

Manages command and config-file options. More...

#include <optionmanager.hpp>

List of all members.

Public Member Functions

 OptionManager (QString commandFormat=QString())
 Defaults options : h -> help (flag), v -> version (string), f -> configfile (string).
void addOption (const QChar &name, const QString &description, Option::ArgValueType valueType=Option::Flag, QString longName=QString())
 Overloads addOption for convenience.
void addOption (const QChar &name, const Option &option)
 Add the option to known options.
void clear ()
 Clears all values and set flags.
void displayHelp () const
 Display the command line format and the available options.
bool isSet (const QChar &optionName) const
QVariant optionValue (const QChar &optionName) const
void parse (const QString &fileName)
 Parses the ini file from the given fileName and stores values in the map.
void parse (const QStringList &args, QStringList *nonOptionArgs=0, int neededArgCount=0)
 Parses the command line args and stores them in the map.
void setCommandFormat (const QString &commandFormat)
 Sets the command format message.
bool setValue (const QChar &optionName, const QString &value)
 Sets the value for the specified option.

Detailed Description

Manages command and config-file options.

Todo:
Sort options with groups and sort the help displayed

Constructor & Destructor Documentation

OptionManager::OptionManager ( QString  commandFormat = QString()  ) 

Defaults options : h -> help (flag), v -> version (string), f -> configfile (string).


Member Function Documentation

void OptionManager::addOption ( const QChar &  name,
const Option option 
)

Add the option to known options.

Exceptions:
Exception If name or longName are not valid or if the option name is already known
void OptionManager::addOption ( const QChar &  name,
const QString &  description,
Option::ArgValueType  valueType = Option::Flag,
QString  longName = QString() 
)

Overloads addOption for convenience.

Exceptions:
Exception If name or longName are not valid or if the option name is already known
void OptionManager::clear (  ) 

Clears all values and set flags.

void OptionManager::displayHelp (  )  const

Display the command line format and the available options.

bool OptionManager::isSet ( const QChar &  optionName  )  const
Returns:
True if the option is a flag and is set, false otherwise.
QVariant OptionManager::optionValue ( const QChar &  optionName  )  const
Returns:
An empty QVariant if option is unknown or does not have value (like flag options), the QVariant value otherwise.
void OptionManager::parse ( const QString &  fileName  ) 

Parses the ini file from the given fileName and stores values in the map.

Exceptions:
Exception If parsing fails
void OptionManager::parse ( const QStringList &  args,
QStringList *  nonOptionArgs = 0,
int  neededArgCount = 0 
)

Parses the command line args and stores them in the map.

If the config-file option (-f) is given, it will automatically parse the config-file after the args.

Parameters:
nonOptionArgs A list to store the command line argument which are not options
neededArgCount The expected count of command line non-option arguments
Exceptions:
Exception If parsing fails
void OptionManager::setCommandFormat ( const QString &  commandFormat  ) 

Sets the command format message.

bool OptionManager::setValue ( const QChar &  optionName,
const QString &  value 
)

Sets the value for the specified option.

Returns:
False if option name is unknown or if value is not valid, true otherwise.
All Classes Functions Variables Typedefs Enumerations Enumerator