74#ifndef _CHOMP_SYSTEM_ARG_H_
75#define _CHOMP_SYSTEM_ARG_H_
115 void set (
int flag) {
n |= flag;}
121 bool get (
int flag)
const {
return !!(
n & flag);}
161 virtual void show (std::ostream &out)
const = 0;
170 void unset (
int flag);
173 bool get (
int flag)
const;
187 if (!_name || !*_name)
191 name =
new char [strlen (_name) + 1];
192 strcpy (
name, _name);
257 argunit (
const char *_name, type &_value);
266 argunit (
const char *_name, type *_value,
int &_count,
271 argunit (
const char *_name, type *_value,
int &_count,
275 int setvalue (
char *str,
char *next);
281 void show (std::ostream &out)
const;
312 argelement (_name), value (_value), previousvalue (_value),
321 argelement (_name), value (_value), defaultvalue (_defaultvalue),
322 previousvalue (_value), table (NULL)
330 int &_count,
int _size):
331 argelement (_name), value (*_value), previousvalue (*_value),
332 table (_value), count (&_count), previouscount (_count),
340 int &_count,
int _size, type _defaultvalue):
341 argelement (_name), value (*_value), defaultvalue (_defaultvalue),
342 previousvalue (*_value), table (_value),
343 count (&_count), previouscount (_count), size (_size)
355 std::istringstream s (str);
421 if (next && *next && ((*next !=
'-') ||
422 std::isdigit (next [1])))
442 element = defaultvalue;
459 table [(*count) ++] = element;
479 value = previousvalue;
481 *count = previouscount;
491 if (getname () && *getname ())
497 out <<
" '-" << getname () <<
"'";
502 out <<
" set to '" << value <<
"'";
503 else if (table && *count)
505 for (
int i = 0; i < *count; ++ i)
506 out << (i ?
", " :
" set to '") << table [i];
509 out <<
" [too many!]";
514 out <<
" (default: '" << defaultvalue <<
"')";
516 out <<
" (no default value)";
517 out <<
"." << std::endl;
556 std::ostream &out = std::cerr);
625 const char *defaultvalue)
629 const_cast<char *
> (defaultvalue));
640 int &count,
int size)
650 int &count,
int size, type defaultvalue)
683 const char *defaultvalue)
720 const char *defaultvalue)
733 char *dummystring = NULL;
746 const type &defaultvalue)
756 const char *defaultvalue)
768 char *dummystring = NULL;
794 bool &quiet,
bool &debug)
796 arg (a,
"-log", logfilename);
797 arg (a,
"-seq", seqfilename);
806inline void setstreams (
const char *logfilename,
char *seqfilename,
807 bool quiet,
bool debug)
819 slog. logfile (logfilename);
820 slog. keepforever ();
827 sseq. logfile (seqfilename);
834#ifndef algstreamprepare
838#define argstreamprepare(a) \
839char *arg_logfilename = NULL; \
840char *arg_seqfilename = NULL; \
841char *arg_computername = NULL; \
842bool arg_quiet = false; \
843bool arg_debug = false; \
844arg (a, "-comp", arg_computername); \
845argstreams (a, arg_logfilename, arg_seqfilename, arg_quiet, arg_debug);
852#define argstreamset() \
853setstreams (arg_logfilename, arg_seqfilename, arg_quiet, arg_debug); \
854slog << commandline (argc, argv) << "\n\n"; \
855if (arg_computername) slog << "Running on " << arg_computername << ". "; \
856slog << "Start time: " << currenttime () << '\n';
This is a helper class which defines common properties of a command-line argument bound with any type...
bool get(int flag) const
Returns the value of the given flag.
virtual int setvalue(char *str, char *next)=0
Sets the value of this argument according to the string.
const char * getname() const
Returns the name of the command-line argument.
void unset(int flag)
Unsets (clears) the given flag.
void set(int flag)
Sets the given flag.
virtual void show(std::ostream &out) const =0
Outputs the argument element to the output stream.
void resetflags()
Resets the flags.
argelement(const char *_name)
The constructor.
char * getvalue(char *str)
Returns the argument's value string from the argument string or returns 0 if it is not this argument.
virtual ~argelement()
The destructor.
virtual void restore()=0
Restores the previous argument value (except for tables).
argflags flags
The flags associated with this argument.
char * name
The argument name (without '-').
This is a helper class which defines specific flags indicating various types of command-line argument...
argflags()
The constructor. All flags are initially cleared (unset).
void unset(int flag)
Unsets (clears) the given flag.
names
A list of specific names for the flags.
~argflags()
The destructor.
int n
The interger variable that stores the flags.
bool get(int flag) const
Returns true if any of the given flags is set or false otherwise.
void set(int flag)
Sets the given flag.
The objects of this class gather the expected command-line arguments and decode them.
int remove(char *name)
Removes all the arguments with this name from the list and return the number of removed items.
int analyze(int argc, char *argv[], std::ostream &out=std::cerr)
Analyzes the arguments from the command line strings.
~arguments()
The destructor.
void reset()
Resets the flags and returns previous argument values (except for tables).
int n
The number of arguments in the table.
void inctable()
Increases the tables if necessary.
friend std::ostream & operator<<(std::ostream &out, arguments &p)
Displays the arguments actually decoded (for debugging purpose).
arguments()
The default constructor.
int length
The allocated length of the table of arguments.
argelement ** tab
The table of pointers to specific arguments.
void add(argelement *p)
Adds an argument to the end of the list.
This is a helper class which defines one command-line argument which is bound with some specific vari...
type defaultvalue
The default value of the variable if any.
int previouscount
The initial value of the number of elements in the array.
type & value
A reference to the variable which is bound to this command line argument.
int setvalue(char *str, char *next)
Sets the argument value from the text string.
int size
The size of the array if any.
argunit(const char *_name, type &_value)
The constructor of a command line argument bound with one variable.
type * table
A pointer to the array bound with the variable.
type previousvalue
The original value of the variable (before reading the command line).
void restore()
Restores the previous argument value (except for tables).
int * count
A pointer to the number of elements currently present in the array.
void show(std::ostream &out) const
Displays the value and some information.
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
outputstream sseq
An auxiliary stream which captures sequences of processed data.
void 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.
void argstreams(arguments &a, char *&logfilename, char *&seqfilename, bool &quiet, bool &debug)
Adds typical command line arguments for manipulating output streams.
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
outputstream serr
A wrapper for the standard error stream.
std::ostream & operator<<(std::ostream &out, const bincube< Dim, twoPower > &b)
void arg(arguments &a, const char *name, type &value)
Adds a command line argument.
outputstream sbug
An output stream for writing additional debug messages.
timeused program_time
The external variable which measures the time used by the program from its start.
void argoblig(arguments &arg, const char *name, type &value)
Defines an obligatory command line argument.
void argbreak(arguments &arg, const char *name, type &value)
Adds an argument whose appearence interrupts the analysis of the command line and makes the analyzing...
outputstream scon
The console output stream to which one should put all the junk that spoils the log file,...
void 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 com...
int readfromstring(char *str, type &t)
A template for reading a variable from a string.
outputstream slog
The output stream to which one can send messages for logging only.
void arghelp(arguments &a)
Adds the typical arguments which should make the program display help information.
This namespace contains the entire CHomP library interface.