Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
Timer Class Reference

#include <timer.hh>

Inheritance diagram for Timer:

Public Member Functions

 Timer (const Timer &t)
 
 Timer (long int seconds, long int useconds)
 
 Timer ()
 
bool hasExpired () const
 
bool hasExpiredWrt (Timer const &t) const
 
void set (long int seconds, long int useconds)
 
void set (const Timer &t)
 

Detailed Description

Author
cpellegrino

Definition at line 10 of file timer.hh.

Constructor & Destructor Documentation

◆ Timer() [1/3]

Timer::Timer ( const Timer & t)
inline

Definition at line 15 of file timer.hh.

16 {
17 set(t);
18 }
void set(long int seconds, long int useconds)
Definition timer.cc:27

◆ Timer() [2/3]

Timer::Timer ( long int seconds,
long int useconds )
inline

Definition at line 20 of file timer.hh.

21 {
22 set(seconds, useconds);
23 }

◆ Timer() [3/3]

Timer::Timer ( )
inline

Definition at line 26 of file timer.hh.

27 {}

Member Function Documentation

◆ hasExpired()

bool Timer::hasExpired ( ) const

Definition at line 21 of file timer.cc.

22{
23 Timer const t(0, 0);
24 return Timer::hasExpiredWrt(t);
25}
Definition timer.hh:11
bool hasExpiredWrt(Timer const &t) const
Definition timer.cc:7

◆ hasExpiredWrt()

bool Timer::hasExpiredWrt ( Timer const & t) const
Author
cpellegrino

Definition at line 7 of file timer.cc.

8{
9 if (t.tv_sec > tv_sec)
10 return true;
11
12 if (t.tv_sec < tv_sec)
13 return false;
14
15 if (t.tv_usec > tv_usec)
16 return true;
17
18 return false;
19}

◆ set() [1/2]

void Timer::set ( long int seconds,
long int useconds )

Definition at line 27 of file timer.cc.

28{
29 static const int usec_in_a_sec = 1000000;
30
31 gettimeofday(this, 0);
32
33 tv_sec += seconds;
34 tv_usec += useconds;
35 tv_sec += (tv_usec) / usec_in_a_sec;
36 tv_usec %= usec_in_a_sec;
37}

◆ set() [2/2]

void Timer::set ( const Timer & t)
inline

Definition at line 36 of file timer.hh.

37 {
38 tv_sec = t.tv_sec;
39 tv_usec = t.tv_usec;
40 }

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