The Original CHomP Software
Public Member Functions | Private Attributes | List of all members
chomp::homology::argunit< type > Class Template Reference

This is a helper class which defines one command-line argument which is bound with some specific variable. More...

#include <arg.h>

Inheritance diagram for chomp::homology::argunit< type >:
chomp::homology::argelement

Public Member Functions

 argunit (const char *_name, type &_value)
 The constructor of a command line argument bound with one variable. More...
 
 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. More...
 
 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. More...
 
 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. More...
 
int setvalue (char *str, char *next)
 Sets the argument value from the text string. More...
 
void restore ()
 Restores the previous argument value (except for tables). More...
 
void show (std::ostream &out) const
 Displays the value and some information. More...
 
- Public Member Functions inherited from chomp::homology::argelement
 argelement (const char *_name)
 The constructor. More...
 
virtual ~argelement ()
 The destructor. More...
 
const char * getname () const
 Returns the name of the command-line argument. More...
 
char * getvalue (char *str)
 Returns the argument's value string from the argument string or returns 0 if it is not this argument. More...
 
virtual int setvalue (char *str, char *next)=0
 Sets the value of this argument according to the string. More...
 
virtual void restore ()=0
 Restores the previous argument value (except for tables). More...
 
virtual void show (std::ostream &out) const =0
 Outputs the argument element to the output stream. More...
 
void resetflags ()
 Resets the flags. More...
 
void set (int flag)
 Sets the given flag. More...
 
void unset (int flag)
 Unsets (clears) the given flag. More...
 
bool get (int flag) const
 Returns the value of the given flag. More...
 

Private Attributes

type & value
 A reference to the variable which is bound to this command line argument. More...
 
type defaultvalue
 The default value of the variable if any. More...
 
type previousvalue
 The original value of the variable (before reading the command line). More...
 
type * table
 A pointer to the array bound with the variable. More...
 
int * count
 A pointer to the number of elements currently present in the array. More...
 
int previouscount
 The initial value of the number of elements in the array. More...
 
int size
 The size of the array if any. More...
 

Detailed Description

template<class type>
class chomp::homology::argunit< type >

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 252 of file arg.h.

Constructor & Destructor Documentation

◆ argunit() [1/4]

template<class type >
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 311 of file arg.h.

311 :
312 argelement (_name), value (_value), previousvalue (_value),
313 table (NULL)
314{
315 return;
316} /* argunit<type>::argunit */
argelement(const char *_name)
The constructor.
Definition: arg.h:185
type & value
A reference to the variable which is bound to this command line argument.
Definition: arg.h:286
type * table
A pointer to the array bound with the variable.
Definition: arg.h:296
type previousvalue
The original value of the variable (before reading the command line).
Definition: arg.h:293

◆ argunit() [2/4]

template<class type >
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 319 of file arg.h.

320 :
321 argelement (_name), value (_value), defaultvalue (_defaultvalue),
322 previousvalue (_value), table (NULL)
323{
325 return;
326} /* argunit<type>::argunit */
void set(int flag)
Sets the given flag.
Definition: arg.h:218
type defaultvalue
The default value of the variable if any.
Definition: arg.h:289

References chomp::homology::argflags::hasdefault, and chomp::homology::argelement::set().

◆ argunit() [3/4]

template<class type >
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 329 of file arg.h.

330 :
331 argelement (_name), value (*_value), previousvalue (*_value),
332 table (_value), count (&_count), previouscount (_count),
333 size (_size)
334{
335 return;
336} /* argunit<type>::argunit */
int previouscount
The initial value of the number of elements in the array.
Definition: arg.h:303
int size
The size of the array if any.
Definition: arg.h:306
int * count
A pointer to the number of elements currently present in the array.
Definition: arg.h:300

◆ argunit() [4/4]

template<class type >
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 339 of file arg.h.

340 :
341 argelement (_name), value (*_value), defaultvalue (_defaultvalue),
342 previousvalue (*_value), table (_value),
343 count (&_count), previouscount (_count), size (_size)
344
345{
347 return;
348} /* argunit<type>::argunit */

References chomp::homology::argflags::hasdefault, and chomp::homology::argelement::set().

Member Function Documentation

◆ restore()

template<class type >
void chomp::homology::argunit< type >::restore
virtual

Restores the previous argument value (except for tables).

Implements chomp::homology::argelement.

Definition at line 476 of file arg.h.

477{
478 if (!table)
480 else
482 resetflags ();
483 return;
484} /* argunit<type>::restore */
void resetflags()
Resets the flags.
Definition: arg.h:209

◆ setvalue()

template<class type >
int chomp::homology::argunit< type >::setvalue ( char *  str,
char *  next 
)
inlinevirtual

Sets the argument value from the text string.

Implements chomp::homology::argelement.

Definition at line 412 of file arg.h.

413{
414 // determine the string from which the value should be read
415 int usenext = 0;
416 char *s;
417 if (str && *str)
418 s = str;
419 else
420 {
421 if (next && *next && ((*next != '-') ||
422 std::isdigit (next [1])))
423 {
424 s = next;
425 usenext = 1;
426 }
427 else
428 s = NULL;
429 }
430
431 // read the element from the string if available
432 int result = -1;
433 type element;
434 if (s)
435 result = readfromstring (s, element);
436
437 // if could not read the string, try the default value
438 if (result < 0)
439 {
441 {
442 element = defaultvalue;
443 usenext = 0;
444 }
445 else
446 {
447 if (s)
449 else
451 return 0;
452 }
453 }
454
455 // put the element to its place
456 if (table)
457 // if there is still room in the table, put the element there
458 if (*count < size)
459 table [(*count) ++] = element;
460 // if the table is full, indicate it
461 else
462 {
465 }
466 else
467 {
468 value = element;
470 }
471
472 return usenext;
473} /* argunit<type>::setvalue */
bool get(int flag) const
Returns the value of the given flag.
Definition: arg.h:230
int readfromstring(char *str, type &t)
A template for reading a variable from a string.
Definition: arg.h:353

References chomp::homology::argflags::filled, chomp::homology::argflags::hasdefault, chomp::homology::argflags::missingvalue, chomp::homology::argflags::readerror, chomp::homology::readfromstring(), and chomp::homology::argflags::toomany.

◆ show()

template<class type >
void chomp::homology::argunit< type >::show ( std::ostream &  out) const
virtual

Displays the value and some information.

Implements chomp::homology::argelement.

Definition at line 487 of file arg.h.

488{
490 out << "Oblig. ";
491 if (getname () && *getname ())
492 {
494 out << "Switch";
495 else
496 out << "Param.";
497 out << " '-" << getname () << "'";
498 }
499 else
500 out << "Word";
501 if (!table && get (argflags::filled))
502 out << " set to '" << value << "'";
503 else if (table && *count)
504 {
505 for (int i = 0; i < *count; ++ i)
506 out << (i ? ", " : " set to '") << table [i];
507 out << "'";
509 out << " [too many!]";
510 }
511 else
512 out << " not found";
514 out << " (default: '" << defaultvalue << "')";
515 else
516 out << " (no default value)";
517 out << "." << std::endl;
518 return;
519} /* argunit<type>::show */
const char * getname() const
Returns the name of the command-line argument.
Definition: arg.h:204

References chomp::homology::argflags::filled, chomp::homology::argflags::hasdefault, chomp::homology::argflags::ignorevalue, chomp::homology::argflags::obligatory, and chomp::homology::argflags::toomany.

Member Data Documentation

◆ count

template<class type >
int* chomp::homology::argunit< type >::count
private

A pointer to the number of elements currently present in the array.

Definition at line 300 of file arg.h.

◆ defaultvalue

template<class type >
type chomp::homology::argunit< type >::defaultvalue
private

The default value of the variable if any.

Definition at line 289 of file arg.h.

◆ previouscount

template<class type >
int chomp::homology::argunit< type >::previouscount
private

The initial value of the number of elements in the array.

Definition at line 303 of file arg.h.

◆ previousvalue

template<class type >
type chomp::homology::argunit< type >::previousvalue
private

The original value of the variable (before reading the command line).

Definition at line 293 of file arg.h.

◆ size

template<class type >
int chomp::homology::argunit< type >::size
private

The size of the array if any.

Definition at line 306 of file arg.h.

◆ table

template<class type >
type* chomp::homology::argunit< type >::table
private

A pointer to the array bound with the variable.

Definition at line 296 of file arg.h.

◆ value

template<class type >
type& chomp::homology::argunit< type >::value
private

A reference to the variable which is bound to this command line argument.

Definition at line 286 of file arg.h.


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