#include <Args.h>
Public Member Functions | |
Args () | |
The constructor. | |
void | setGroup (const string &groupName) |
Defines the current groups of arguments. | |
void | declareArgument (const string &name) |
Declare a simple argument. | |
void | declareArgument (const string &name, const string &description, const int numOptions=0, const string &options="") |
Declare an argument. | |
void | printGroup (const string &groupName, ostream &out=cout, const int indSpaces=3) |
Display the arguments (with description and options) associated with the groupName passed. | |
ArgsOutType | readArguments (const int argc, char *argv[]) |
Read the arguments passed with the commandline. | |
bool | hasArgument (const string &argument) const |
Ask if an argument has been provided via command line. | |
vector< string > & | getValuesVector (const string &argument) |
Returns the vector of the values that belongs to the given argument. | |
template<typename T> | |
void | getValue (const string &argument, int index, T &valueToFill) |
Get the nth value of the given argument, where n = index. | |
Private Member Functions | |
string | getWrappedString (const string &str, const int leftSpace=0, const bool spacesInFirstLine=true) const |
Return a string which has been wrapped to fit into _maxColumns columns. | |
Private Attributes | |
string | _currentGroup |
The current group. | |
int | _maxColumns |
The maximum number of column (in a loosely sense) allowed to be printed. | |
map< string, vector< Argument > > | _groupedList |
The list of arguments per group. | |
map< string, int > | _argsList |
Arguments declared. | |
map< string, vector< string > > | _resArgs |
Arguments found. | |
Classes | |
struct | Argument |
Holds the informations of a single argument. More... |
Provide an easy (but simple) way to handle parameters in a command line program. It works by first declaring the arguments via declareArgument, for instance:
// declare a simple argument args.declareArgument("-help"); // Declare an argument -test which takes two following arguments. args.declareArgument("-test", "Test the model.", 2, "<dataFile> <shypFile>");
Once the arguments are declared, readArguments() takes the standard C arguments and fill a map with the ones selected by the user. If they do not follow the declaration's constraints, readArguments returns an error. When the user needs the values of an argument, it just calls the getValue() or getValuesVector().
It is also possible to defines groups of options, using setGroup before the call of any declareArgument. The name passed, will be used to print a nicely formatted list of the group's arguments using printGroup().
Definition at line 81 of file Args.h.
|
The constructor. Set the current group to "general".
|
|
Declare an argument. This type of argument has a description, and might have options. For instance an argument such as -file filename.txt is declared as declareArgument( "-file", "Open a file", 1, "<filename>" );
Definition at line 33 of file Args.cpp. References Args::_argsList, Args::_currentGroup, and Args::_groupedList. |
|
Declare a simple argument. Just declare an argument without following options, nor descriptions.
Definition at line 26 of file Args.cpp. References Args::_argsList. Referenced by StumpLearner::declareArguments(). |
|
Get the nth value of the given argument, where n = index. The value is stored in the variable valueToFill which can be any type, thanks to the use of templates and string stream. For instance with the command line: myProgram -arg val1 val2 10 11 int val; getValue("-arg", 2, val); // -> val = 10
Definition at line 209 of file Args.h. References Args::_resArgs. Referenced by AdaBoostLearner::AdaBoostLearner(), Classifier::Classifier(), and StumpLearner::initOptions(). |
|
Returns the vector of the values that belongs to the given argument. For instance with the command line: myProgram -arg val1 val2 10 11 getValuesVector("-arg"); // -> ["val1", "val2", "10", "11"]
Definition at line 112 of file Args.cpp. References Args::_resArgs. |
|
Return a string which has been wrapped to fit into _maxColumns columns. For instance, if _maxColumns is set to 20: string s = "A simple test of wrapping a line into some more. Here is how it goes"; string w1 = getWrappedString(s, 5); string w2 = getWrappedString(s, 5, false); cout << "w1: " << endl << w1 << endl; cout << "w2: " << endl << w1 << endl; w1: A simple test of wrapping a line into some more. Here is how it goes. w2: A simple test of wrapping a line into some more. Here is how it goes.
Definition at line 125 of file Args.cpp. References Args::_maxColumns. Referenced by Args::printGroup(). |
|
Ask if an argument has been provided via command line.
Definition at line 174 of file Args.h. References Args::_resArgs. Referenced by AdaBoostLearner::AdaBoostLearner(), Classifier::Classifier(), StumpLearner::initOptions(), and InputData::initOptions(). |
|
Display the arguments (with description and options) associated with the groupName passed. Example: Args a; a.setGroup("group1"); a.declareArgument("-arg1", "The first argument"); a.declareArgument("-arg2", "The second argument"); a.setGroup("group2"); a.declareArgument("-arg3", "Another argument"); group1: -arg1: The first argument -arg2: The second argument
Definition at line 45 of file Args.cpp. References Args::_groupedList, and Args::getWrappedString(). |
|
Read the arguments passed with the commandline.
Definition at line 71 of file Args.cpp. References Args::_argsList, Args::_resArgs, nor_utils::AOT_NO_ARGUMENTS, nor_utils::AOT_TOO_FEW_VALUES, and nor_utils::AOT_UNKOWN_ARGUMENT. |
|
Defines the current groups of arguments. The group defines which argument has to be printed together. To be used before the subsequent call of declareArgument.
Definition at line 101 of file Args.h. References Args::_currentGroup. |
|
The current group.
Definition at line 293 of file Args.h. Referenced by Args::declareArgument(), and Args::setGroup(). |
|
The maximum number of column (in a loosely sense) allowed to be printed.
Definition at line 300 of file Args.h. Referenced by Args::getWrappedString(). |