The Original CHomP Software
Public Member Functions | Protected Attributes | Friends | List of all members
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>

Public Member Functions

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

Protected Attributes

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

Friends

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

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 66 of file timeused.h.

Constructor & Destructor Documentation

◆ timeused() [1/2]

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 137 of file timeused.h.

138{
139 reset ();
140 outstream1 = NULL;
141 outstream2 = NULL;
142 message = msg;
143 display = -1;
144 return;
145} /* timeused::timeused */
timeused & reset()
Reset the timer to the current moment.
int display
Should the destructor display the time? Note: -1 makes the destructor display times only > 1 sec.
Definition: timeused.h:131
std::ostream * outstream2
Output stream 2 (0 for no output).
Definition: timeused.h:124
std::ostream * outstream1
Output stream 1 (0 for no output).
Definition: timeused.h:121
const char * message
A message to display instead of "Used time" (if not 0).
Definition: timeused.h:127

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

◆ timeused() [2/2]

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

Definition at line 147 of file timeused.h.

148{
149 reset ();
150 outstream1 = &out;
151 outstream2 = NULL;
152 message = msg;
153 display = -1;
154 return;
155} /* timeused::timeused */

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

◆ ~timeused()

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

The destructor.

Definition at line 169 of file timeused.h.

170{
171 if (!display || (!outstream1 && !outstream2))
172 return;
173 if ((display > 0) || (double (*this) > 1))
174 {
175 if (outstream1)
176 show (*outstream1);
177 if (outstream2)
178 show (*outstream2);
179 }
180 return;
181} /* timeused::~timeused */
void show(std::ostream &out, const char *message=NULL) const
Shows the time used from the beginning up to the current point.
Definition: timeused.h:157

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

Member Function Documentation

◆ operator double()

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

Returns the time from the initialization measured in seconds.

◆ operator=() [1/4]

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

Changes the message displayed at program's termination.

Definition at line 211 of file timeused.h.

212{
213 message = msg;
214 return *this;
215} /* timeused::operator = */

References message.

◆ operator=() [2/4]

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 205 of file timeused.h.

206{
207 display = n;
208 return *this;
209} /* timeused::operator = */

References display.

◆ operator=() [3/4]

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 191 of file timeused.h.

192{
193 if (out. show)
194 outstream1 = &(out. out);
195 else
196 outstream1 = NULL;
197 if (out. log)
198 outstream2 = out. getlogstream ();
199 else
200 outstream2 = NULL;
201 return *this;
202} /* operator = */

References outstream1, outstream2, and show().

◆ operator=() [4/4]

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 183 of file timeused.h.

184{
185 outstream1 = &out;
186 outstream2 = NULL;
187 return *this;
188} /* timeused::operator = */

References outstream1, and outstream2.

◆ reset()

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

Reset the timer to the current moment.

Referenced by timeused().

◆ show() [1/2]

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 217 of file timeused.h.

218{
219 if (outstream1)
220 show (*outstream1, msg);
221 if (outstream2)
222 show (*outstream2, msg);
223 return;
224} /* timeused::show */

References outstream1, outstream2, and show().

◆ show() [2/2]

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 157 of file timeused.h.

158{
159 if (!msg)
160 msg = message;
161 if (!msg)
162 msg = "Time used:";
163
164 out << msg << ' ' << *this << '.' << std::endl;
165
166 return;
167} /* timeused::show */

References message.

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

Friends And Related Function Documentation

◆ operator<<

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

Shows the time elapsed up to this point.

Member Data Documentation

◆ cpu0

double chomp::homology::timeused::cpu0
protected

CPU usage start time (in seconds).

Definition at line 115 of file timeused.h.

◆ display

int chomp::homology::timeused::display
protected

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

Definition at line 131 of file timeused.h.

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

◆ message

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

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

Definition at line 127 of file timeused.h.

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

◆ outstream1

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

Output stream 1 (0 for no output).

Definition at line 121 of file timeused.h.

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

◆ outstream2

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

Output stream 2 (0 for no output).

Definition at line 124 of file timeused.h.

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

◆ t0

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

Start time (in seconds).

Definition at line 118 of file timeused.h.


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