Public Member Functions | Protected Attributes | Friends

chomp::homology::timeused Class Reference

A class that stores the time at which it was initialized and then returns or displays the time used since the initialization. More...

#include <timeused.h>

List of all members.

Public Member Functions

 timeused (const char *msg=NULL)
 The default constructor.
 timeused (std::ostream &out, const char *msg=NULL)
 ~timeused ()
 The destructor.
timeusedoperator= (std::ostream &out)
 Defines an output stream for displaying program's running time at program's termination.
timeusedoperator= (outputstream &out)
 Defines an output stream for displaying program's running time at program's termination to a pair of streams.
timeusedoperator= (int n)
 Turns off writing program's running time at program's termination by assigning 0 to an object of this class.
timeusedoperator= (const char *msg)
 Changes the message displayed at program's termination.
timeusedreset ()
 Reset the timer to the current moment.
 operator double ()
 Returns the time from the initialization measured in seconds.
void show (std::ostream &out, const char *message=NULL) const
 Shows the time used from the beginning up to the current point.
void show (const char *message=NULL) const
 Shows the time used from the beginning up to the current point to the standard output stream.

Protected Attributes

double cpu0
 CPU usage start time (in seconds).
std::time_t t0
 Start time (in seconds).
std::ostream * outstream1
 Output stream 1 (0 for no output).
std::ostream * outstream2
 Output stream 2 (0 for no output).
const char * message
 A message to display instead of "Used time" (if not 0).
int display
 Should the destructor display the time? Note: -1 makes the destructor display times only > 1 sec.

Friends

std::ostream & operator<< (std::ostream &out, const timeused &t)
 Shows the time elapsed up to this point.

Detailed Description

A class that stores the time at which it was initialized and then returns or displays the time used since the initialization.

It displays this time when the destructor is invoked, e.g., at the end of program run. This class is used in most of the CHomP programs to measure the time used for the computations.

Definition at line 67 of file timeused.h.


Constructor & Destructor Documentation

chomp::homology::timeused::timeused ( const char *  msg = NULL  )  [inline]

The default constructor.

It may be given a message to be displayed when the destructor is called.

Definition at line 138 of file timeused.h.

References display, message, outstream1, outstream2, and reset().

{
        reset ();
        outstream1 = NULL;
        outstream2 = NULL;
        message = msg;
        display = -1;
        return;
} /* timeused::timeused */

chomp::homology::timeused::timeused ( std::ostream &  out,
const char *  msg = NULL 
) [inline]

Definition at line 148 of file timeused.h.

References display, message, outstream1, outstream2, and reset().

{
        reset ();
        outstream1 = &out;
        outstream2 = NULL;
        message = msg;
        display = -1;
        return;
} /* timeused::timeused */

chomp::homology::timeused::~timeused (  )  [inline]

The destructor.

Definition at line 170 of file timeused.h.

References display, outstream1, outstream2, and show().

{
        if (!display || (!outstream1 && !outstream2))
                return;
        if ((display > 0) || (double (*this) > 1))
        {
                if (outstream1)
                        show (*outstream1);
                if (outstream2)
                        show (*outstream2);
        }
        return;
} /* timeused::~timeused */


Member Function Documentation

chomp::homology::timeused::operator double (  ) 

Returns the time from the initialization measured in seconds.

timeused & chomp::homology::timeused::operator= ( outputstream out  )  [inline]

Defines an output stream for displaying program's running time at program's termination to a pair of streams.

Definition at line 192 of file timeused.h.

References outstream1, outstream2, and show().

{
        if (out. show)
                outstream1 = &(out. out);
        else
                outstream1 = NULL;
        if (out. log)
                outstream2 = out. getlogstream ();
        else
                outstream2 = NULL;
        return *this;
} /* operator = */

timeused & chomp::homology::timeused::operator= ( const char *  msg  )  [inline]

Changes the message displayed at program's termination.

Definition at line 212 of file timeused.h.

References message.

{
        message = msg;
        return *this;
} /* timeused::operator = */

timeused & chomp::homology::timeused::operator= ( int  n  )  [inline]

Turns off writing program's running time at program's termination by assigning 0 to an object of this class.

Definition at line 206 of file timeused.h.

References display.

{
        display = n;
        return *this;
} /* timeused::operator = */

timeused & chomp::homology::timeused::operator= ( std::ostream &  out  )  [inline]

Defines an output stream for displaying program's running time at program's termination.

Definition at line 184 of file timeused.h.

References outstream1, and outstream2.

{
        outstream1 = &out;
        outstream2 = NULL;
        return *this;
} /* timeused::operator = */

timeused& chomp::homology::timeused::reset (  ) 

Reset the timer to the current moment.

Referenced by timeused().

void chomp::homology::timeused::show ( std::ostream &  out,
const char *  message = NULL 
) const [inline]

Shows the time used from the beginning up to the current point.

The time is preceded with the message (default: "Time used").

Definition at line 158 of file timeused.h.

References message.

Referenced by operator=(), show(), and ~timeused().

{
        if (!msg)
                msg = message;
        if (!msg)
                msg = "Time used:";

        out << msg << ' ' << *this << '.' << std::endl;

        return;
} /* timeused::show */

void chomp::homology::timeused::show ( const char *  message = NULL  )  const [inline]

Shows the time used from the beginning up to the current point to the standard output stream.

The time is preceded with the message (default: "Time used").

Definition at line 218 of file timeused.h.

References outstream1, outstream2, and show().

{
        if (outstream1)
                show (*outstream1, msg);
        if (outstream2)
                show (*outstream2, msg);
        return;
} /* timeused::show */


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const timeused t 
) [friend]

Shows the time elapsed up to this point.


Member Data Documentation

double chomp::homology::timeused::cpu0 [protected]

CPU usage start time (in seconds).

Definition at line 116 of file timeused.h.

Should the destructor display the time? Note: -1 makes the destructor display times only > 1 sec.

Definition at line 132 of file timeused.h.

Referenced by operator=(), timeused(), and ~timeused().

const char* chomp::homology::timeused::message [protected]

A message to display instead of "Used time" (if not 0).

Definition at line 128 of file timeused.h.

Referenced by operator=(), show(), and timeused().

std::ostream* chomp::homology::timeused::outstream1 [protected]

Output stream 1 (0 for no output).

Definition at line 122 of file timeused.h.

Referenced by operator=(), show(), timeused(), and ~timeused().

std::ostream* chomp::homology::timeused::outstream2 [protected]

Output stream 2 (0 for no output).

Definition at line 125 of file timeused.h.

Referenced by operator=(), show(), timeused(), and ~timeused().

std::time_t chomp::homology::timeused::t0 [protected]

Start time (in seconds).

Definition at line 119 of file timeused.h.


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