This is a helper class which defines one command-line argument which is bound with some specific variable. More...
#include <arg.h>
Public Member Functions | |
| argunit (const char *_name, type &_value) | |
| The constructor of a command line argument bound with one variable. | |
| argunit (const char *_name, type &_value, type defaultvalue) | |
| The constructor of a command line argument bound with one variable which has a default value if none found in the command line. | |
| argunit (const char *_name, type *_value, int &_count, int _size) | |
| The constructor of a command line argument bound with an array of the given size. | |
| argunit (const char *_name, type *_value, int &_count, int _size, type defaultvalue) | |
| The constructor of a command line argument bound with an array of the given size; a default value is provided. | |
| int | setvalue (char *str, char *next) |
| Sets the argument value from the text string. | |
| void | restore () |
| Restores the previous argument value (except for tables). | |
| void | show (std::ostream &out) const |
| Displays the value and some information. | |
Private Attributes | |
| type & | value |
| A reference to the variable which is bound to this command line argument. | |
| type | defaultvalue |
| The default value of the variable if any. | |
| type | previousvalue |
| The original value of the variable (before reading the command line). | |
| type * | table |
| A pointer to the array bound with the variable. | |
| int * | count |
| A pointer to the number of elements currently present in the array. | |
| int | previouscount |
| The initial value of the number of elements in the array. | |
| int | size |
| The size of the array if any. | |
This is a helper class which defines one command-line argument which is bound with some specific variable.
It is an extension of the "argelement" class defined in terms of a template whose parameter is the type of the variable which is to be set based on the value provided in the command line.
Definition at line 253 of file arg.h.
| chomp::homology::argunit< type >::argunit | ( | const char * | _name, | |
| type & | _value | |||
| ) | [inline] |
The constructor of a command line argument bound with one variable.
Definition at line 312 of file arg.h.
:
argelement (_name), value (_value), previousvalue (_value),
table (NULL)
{
return;
} /* argunit<type>::argunit */
| chomp::homology::argunit< type >::argunit | ( | const char * | _name, | |
| type & | _value, | |||
| type | defaultvalue | |||
| ) | [inline] |
The constructor of a command line argument bound with one variable which has a default value if none found in the command line.
Definition at line 320 of file arg.h.
:
argelement (_name), value (_value), defaultvalue (_defaultvalue),
previousvalue (_value), table (NULL)
{
set (argflags::hasdefault);
return;
} /* argunit<type>::argunit */
| chomp::homology::argunit< type >::argunit | ( | const char * | _name, | |
| type * | _value, | |||
| int & | _count, | |||
| int | _size | |||
| ) | [inline] |
The constructor of a command line argument bound with an array of the given size.
Definition at line 330 of file arg.h.
:
argelement (_name), value (*_value), previousvalue (*_value),
table (_value), count (&_count), previouscount (_count),
size (_size)
{
return;
} /* argunit<type>::argunit */
| chomp::homology::argunit< type >::argunit | ( | const char * | _name, | |
| type * | _value, | |||
| int & | _count, | |||
| int | _size, | |||
| type | defaultvalue | |||
| ) | [inline] |
The constructor of a command line argument bound with an array of the given size; a default value is provided.
Definition at line 340 of file arg.h.
:
argelement (_name), value (*_value), defaultvalue (_defaultvalue),
previousvalue (*_value), table (_value),
count (&_count), previouscount (_count), size (_size)
{
set (argflags::hasdefault);
return;
} /* argunit<type>::argunit */
| void chomp::homology::argunit< type >::restore | ( | ) | [virtual] |
Restores the previous argument value (except for tables).
Implements chomp::homology::argelement.
Definition at line 477 of file arg.h.
References chomp::homology::argunit< type >::count, chomp::homology::argunit< type >::previouscount, chomp::homology::argunit< type >::previousvalue, chomp::homology::argelement::resetflags(), chomp::homology::argunit< type >::table, and chomp::homology::argunit< type >::value.
{
if (!table)
value = previousvalue;
else
*count = previouscount;
resetflags ();
return;
} /* argunit<type>::restore */
| int chomp::homology::argunit< type >::setvalue | ( | char * | str, | |
| char * | next | |||
| ) | [inline, virtual] |
Sets the argument value from the text string.
Implements chomp::homology::argelement.
Definition at line 413 of file arg.h.
References chomp::homology::argunit< type >::count, chomp::homology::argunit< type >::defaultvalue, chomp::homology::argflags::hasdefault, chomp::homology::readfromstring(), chomp::homology::argunit< type >::size, chomp::homology::argunit< type >::table, and chomp::homology::argunit< type >::value.
{
// determine the string from which the value should be read
int usenext = 0;
char *s;
if (str && *str)
s = str;
else
{
if (next && *next && ((*next != '-') ||
std::isdigit (next [1])))
{
s = next;
usenext = 1;
}
else
s = NULL;
}
// read the element from the string if available
int result = -1;
type element;
if (s)
result = readfromstring (s, element);
// if could not read the string, try the default value
if (result < 0)
{
if (get (argflags::hasdefault))
{
element = defaultvalue;
usenext = 0;
}
else
{
if (s)
set (argflags::readerror);
else
set (argflags::missingvalue);
return 0;
}
}
// put the element to its place
if (table)
// if there is still room in the table, put the element there
if (*count < size)
table [(*count) ++] = element;
// if the table is full, indicate it
else
{
set (argflags::toomany);
set (argflags::filled);
}
else
{
value = element;
set (argflags::filled);
}
return usenext;
} /* argunit<type>::setvalue */
| void chomp::homology::argunit< type >::show | ( | std::ostream & | out | ) | const [virtual] |
Displays the value and some information.
Implements chomp::homology::argelement.
Definition at line 488 of file arg.h.
References chomp::homology::argunit< type >::count, chomp::homology::argunit< type >::defaultvalue, chomp::homology::argflags::filled, chomp::homology::argelement::getname(), chomp::homology::argflags::hasdefault, chomp::homology::argflags::ignorevalue, chomp::homology::argflags::obligatory, chomp::homology::argunit< type >::table, chomp::homology::argflags::toomany, and chomp::homology::argunit< type >::value.
{
if (get (argflags::obligatory))
out << "Oblig. ";
if (getname () && *getname ())
{
if (get (argflags::ignorevalue))
out << "Switch";
else
out << "Param.";
out << " '-" << getname () << "'";
}
else
out << "Word";
if (!table && get (argflags::filled))
out << " set to '" << value << "'";
else if (table && *count)
{
for (int i = 0; i < *count; ++ i)
out << (i ? ", " : " set to '") << table [i];
out << "'";
if (get (argflags::toomany))
out << " [too many!]";
}
else
out << " not found";
if (get (argflags::hasdefault))
out << " (default: '" << defaultvalue << "')";
else
out << " (no default value)";
out << "." << std::endl;
return;
} /* argunit<type>::show */
int* chomp::homology::argunit< type >::count [private] |
A pointer to the number of elements currently present in the array.
Definition at line 301 of file arg.h.
Referenced by chomp::homology::argunit< type >::restore(), chomp::homology::argunit< type >::setvalue(), and chomp::homology::argunit< type >::show().
type chomp::homology::argunit< type >::defaultvalue [private] |
The default value of the variable if any.
Definition at line 290 of file arg.h.
Referenced by chomp::homology::argunit< type >::setvalue(), and chomp::homology::argunit< type >::show().
int chomp::homology::argunit< type >::previouscount [private] |
The initial value of the number of elements in the array.
Definition at line 304 of file arg.h.
Referenced by chomp::homology::argunit< type >::restore().
type chomp::homology::argunit< type >::previousvalue [private] |
The original value of the variable (before reading the command line).
Definition at line 294 of file arg.h.
Referenced by chomp::homology::argunit< type >::restore().
int chomp::homology::argunit< type >::size [private] |
The size of the array if any.
Definition at line 307 of file arg.h.
Referenced by chomp::homology::argunit< type >::setvalue().
type* chomp::homology::argunit< type >::table [private] |
A pointer to the array bound with the variable.
Definition at line 297 of file arg.h.
Referenced by chomp::homology::argunit< type >::restore(), chomp::homology::argunit< type >::setvalue(), and chomp::homology::argunit< type >::show().
type& chomp::homology::argunit< type >::value [private] |
A reference to the variable which is bound to this command line argument.
Definition at line 287 of file arg.h.
Referenced by chomp::homology::argunit< type >::restore(), chomp::homology::argunit< type >::setvalue(), and chomp::homology::argunit< type >::show().
1.7.1