TF++, Miscellaneous classes and modules in C++:

Evaluates commandline by calling long_getopt. ,You may instantiate a Commandline object by passing the C-variables iargc and argv (which are passed to main) and a Declare-list to the constructor. The constructor itself will call the function long_getopt to evaluate the command line and stores the results. More...

#include <commandline.h>

Collaboration diagram for tfxx::cmdline::Commandline:

Classes

struct  Result
 Structure to store result of command line scanning. More...
 

Public Member Functions

 Commandline (int &iargc, char **argv, Declare *declarations)
 Constructor evaluates commandline by calling long_getopt. More...
 
 ~Commandline ()
 Destructor has to remove result array. More...
 
Option argument query functions.

Functions to query commandline option information.

bool optset (const int &iopt) const
 true if option # iopt was set on commandline More...
 
std::string string_arg (const int &iopt) const
 return argument of option # iopt as string value More...
 
int int_arg (const int &iopt) const
 return argument of option # iopt as int value More...
 
float float_arg (const int &iopt) const
 return argument of option # iopt as float value More...
 
double double_arg (const int &iopt) const
 return argument of option # iopt as double value More...
 
long long_arg (const int &iopt) const
 return argument of option # iopt as long value More...
 
bool bool_arg (const int &iopt) const
 return argument of option # iopt as bool value More...
 
Commandline argument query functions.

Functions to query extra commandline arguments.

bool extra () const
 true if there are more commandline arguments More...
 
char * next ()
 returns char-array of next commandline argument More...
 

Private Member Functions

void check_index (const int &iopt) const
 Check requested index before query. More...
 

Private Attributes

ResultMresult
 Array of command line contents. More...
 
int Mnopt
 Total number of options evaluated ot Mresult. More...
 
int Miargc
 Number of command line strings (as passed to main) More...
 
char ** Margv
 Pointer to array of command line strings (as passed to main) More...
 
int Moptind
 Next option string to read after last defined option. More...
 

Detailed Description

Evaluates commandline by calling long_getopt. ,

You may instantiate a Commandline object by passing the C-variables iargc and argv (which are passed to main) and a Declare-list to the constructor. The constructor itself will call the function long_getopt to evaluate the command line and stores the results.

Option settings and options arguments (in various types) may be received through query functions. Two other query functions allow reading of the rest of the commandline arguments (filenames etc.).

Usage example:

// collect options from commandline
tfxx::cmdline::Commandline cmdline(iargc, argv, options);
// help requested? print full help text...
if (cmdline.optset(0))
{
cerr << usage_text << endl;
cerr << help_text << endl;
exit(0);
}
// dummy operation: print option settings
for (int iopt=0; iopt<3; iopt++)
{
cout << "option: '" << options[iopt].opt_string << "'" << endl;
if (cmdline.optset(iopt)) { cout << " option was set"; }
else { cout << "option was not set"; }
cout << endl;
cout << " argument (string): '" << cmdline.string_arg(iopt) << "'" << endl;
cout << " argument (int): '" << cmdline.int_arg(iopt) << "'" << endl;
cout << " argument (long): '" << cmdline.long_arg(iopt) << "'" << endl;
cout << " argument (float): '" << cmdline.float_arg(iopt) << "'" << endl;
cout << " argument (double): '" << cmdline.double_arg(iopt) << "'" << endl;
cout << " argument (bool): '";
if (cmdline.bool_arg(iopt))
{ cout << "true"; } else { cout << "false"; }
cout << "'" << endl;
}
// dummy operation: print rest of command line
while (cmdline.extra()) { cout << cmdline.next() << endl; }

Consult the documentation of tfxx::cmdline::Declare on the construction of the options array.

See also
tfxx::cmdline::Declare
TEST: Commandline evaluation.
Commandline options and arguments.
tfxx::cmdline
Examples:
tests/commandlinetest.cc, and tests/fortraniotest.cc.

Definition at line 201 of file commandline.h.


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