Classes | Namespaces | Defines | Functions

arg.h File Reference

This file contains the definition of a class which can be used to parse the command line of a program and to set variables according to the command-line arguments. More...

#include "chomp/system/config.h"
#include <iostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cctype>

Go to the source code of this file.

Classes

class  chomp::homology::argflags
 This is a helper class which defines specific flags indicating various types of command-line arguments and the state of interpreting them. More...
class  chomp::homology::argelement
 This is a helper class which defines common properties of a command-line argument bound with any type of a variable. More...
class  chomp::homology::argunit< type >
 This is a helper class which defines one command-line argument which is bound with some specific variable. More...
class  chomp::homology::arguments
 The objects of this class gather the expected command-line arguments and decode them. More...

Namespaces

namespace  chomp
 

This namespace contains the entire CHomP library interface.


namespace  chomp::homology
 

This namespace contains the core of the homology computation procedures and related classes and templates contained in the CHomP C++ library.


Defines

#define argstreamprepare(a)
 This macrodefinition sets up command line arguments for the analysis of typical arguments related to the output streams defined in the module "textfile.h".
#define argstreamset()
 This macrodefinition sets up the streams defined in the module "textfile.h", based on the analyzed command line arguments defined by the macrodefinition "algstreamprepare(a)".

Functions

std::ostream & chomp::homology::operator<< (std::ostream &out, const argelement &p)
template<class type >
int chomp::homology::readfromstring (char *str, type &t)
 A template for reading a variable from a string.
int chomp::homology::readfromstring (char *str, char *&t)
 A specialization of the above template for interpreting a string as a string (no processing is necessary).
int chomp::homology::readfromstring (char *str, const char *&t)
 A specialization of the above template for interpreting a string as a const string (no processing is necessary).
int chomp::homology::readfromstring (char *str, bool &t)
 A specialization of the above template for reading a bool type.
template<class type >
void chomp::homology::arg (arguments &a, const char *name, type &value)
 Adds a command line argument.
template<class type >
void chomp::homology::arg (arguments &a, const char *name, type &value, type defaultvalue)
 Adds a command line argument with a default value.
void chomp::homology::arg (arguments &a, const char *name, char *&value, const char *defaultvalue)
 A specialization of the above for C-style strings.
template<class type >
void chomp::homology::arg (arguments &a, const char *name, type *value, int &count, int size)
 Adds a command line argument whose repeated occurrences fill in consecutive elements of the given array.
template<class type >
void chomp::homology::arg (arguments &a, const char *name, type *value, int &count, int size, type defaultvalue)
 A version of the above with a default value of the arguments.
template<class type >
void chomp::homology::argoblig (arguments &arg, const char *name, type &value)
 Defines an obligatory command line argument.
template<class type >
void chomp::homology::argoblig (arguments &arg, const char *name, type &value, type defaultvalue)
 A version of the above with the default value provided.
void chomp::homology::argoblig (arguments &arg, const char *name, char *&value, const char *defaultvalue)
 A version of the above for reading an array of argument values.
template<class type >
void chomp::homology::argbreak (arguments &arg, const char *name, type &value)
 Adds an argument whose appearence interrupts the analysis of the command line and makes the analyzing function return the value of 1.
template<class type >
void chomp::homology::argbreak (arguments &arg, const char *name, type &value, type defaultvalue)
 A version of the above with the default value provided.
void chomp::homology::argbreak (arguments &arg, const char *name, char *&value, const char *defaultvalue)
 A version of the above for the C-style string.
void chomp::homology::argbreak (arguments &arg, const char *name)
 A version of the above which ignores the value of the argument.
template<class type >
void chomp::homology::argswitch (arguments &arg, const char *name, type &value, const type &defaultvalue)
 Defines a command line argument which is a switch, that is, there is no value given for it in the command line.
void chomp::homology::argswitch (arguments &arg, const char *name, char *&value, const char *defaultvalue)
 A version of the above for the C-style string.
void chomp::homology::argswitch (arguments &arg, const char *name)
 Defines an ignored switch (no value is set when this argument appears).
void chomp::homology::arghelp (arguments &a)
 Adds the typical arguments which should make the program display help information.
void chomp::homology::argstreams (arguments &a, char *&logfilename, char *&seqfilename, bool &quiet, bool &debug)
 Adds typical command line arguments for manipulating output streams.
void chomp::homology::setstreams (const char *logfilename, char *seqfilename, bool quiet, bool debug)
 Sets the parameters of the output streams depending on the file names acquired from the command line.

Detailed Description

This file contains the definition of a class which can be used to parse the command line of a program and to set variables according to the command-line arguments.

The way of using the features defined in this header file is very simple and intuitive.

First, one must define in one's program an object of the type "arguments" which will collect and process the command line.

Then one should use some of the several functions "arg", "argswitch", and "arghelp" to bind various arguments with specific variables. For example, 'arg (argObject, "i", increase, 1);' makes the program react to the switch "-i" appearing in the command line and sets the value of the variable "increase" to what follows "-i", either without space, or after a space, but if no value is provided then the default value "1" is used.

At the end of arguments' definitions, it is recommended to use the function "arghelp (argObject);" to add the arguments typical for the user asking the program to display help information (like "--help"), but this step is not obligatory.

After all the arguments have been defined, one might also call the function "argstreamprepare (argObject);" (which is actually a macro) to set up some additional arguments related to the streams of the class "outputstream" defined in "chomp/system/textfile.h". In particular, this call adds the useful feature that if the user adds the argument "--log filename" to the command-line then all the output displayed to the screen (directed to "sout") is additionally logged to the given file.

Eventually, one should call the method "analyze" of the arguments object, e.g. "int argresult = argObject. analyze (argc, argv);", followed by another macro "argstreamset ();" which sets the streams defined with the macro "argstreamprepare".

The returned value "argresult" indicates what happened during the processing of the command line arguments: 0 means "all good", 1 means "help requested", and a negative value means "some error(s) occurred".

Author:
Pawel Pilarczyk

Definition in file arg.h.


Define Documentation

#define argstreamprepare (   a  ) 
Value:
char *arg_logfilename = NULL; \
char *arg_seqfilename = NULL; \
char *arg_computername = NULL; \
bool arg_quiet = false; \
bool arg_debug = false; \
arg (a, "-comp", arg_computername); \
argstreams (a, arg_logfilename, arg_seqfilename, arg_quiet, arg_debug);

This macrodefinition sets up command line arguments for the analysis of typical arguments related to the output streams defined in the module "textfile.h".

Definition at line 839 of file arg.h.

Referenced by chomp::multiwork::mwSubdivMain().

#define argstreamset (  ) 
Value:
setstreams (arg_logfilename, arg_seqfilename, arg_quiet, arg_debug); \
slog << commandline (argc, argv) << "\n\n"; \
if (arg_computername) slog << "Running on " << arg_computername << ". "; \
slog << "Start time: " << currenttime () << '\n';

This macrodefinition sets up the streams defined in the module "textfile.h", based on the analyzed command line arguments defined by the macrodefinition "algstreamprepare(a)".

Definition at line 853 of file arg.h.

Referenced by chomp::multiwork::mwSubdivMain().