PPL  1.2
Parma_Polyhedra_Library::Implementation::Watchdog::Time Class Reference

A class for representing and manipulating positive time intervals. More...

#include <Time_defs.hh>

Public Member Functions

 Time ()
 Zero seconds. More...
 
 Time (long centisecs)
 Constructor taking a number of centiseconds. More...
 
 Time (long s, long m)
 Constructor with seconds and microseconds. More...
 
long seconds () const
 Returns the number of whole seconds contained in the represented time interval. More...
 
long microseconds () const
 Returns the number of microseconds that, when added to the number of seconds returned by seconds(), give the represent time interval. More...
 
Timeoperator+= (const Time &y)
 Adds y to *this. More...
 
Timeoperator-= (const Time &y)
 Subtracts y from *this; if *this is shorter than y, *this is set to the null interval. More...
 
bool OK () const
 Checks if all the invariants are satisfied. More...
 

Private Attributes

long secs
 Number of seconds. More...
 
long microsecs
 Number of microseconds. More...
 

Static Private Attributes

static const long USECS_PER_SEC = 1000000L
 Number of microseconds in a second. More...
 
static const long CSECS_PER_SEC = 100L
 Number of centiseconds in a second. More...
 

Detailed Description

A class for representing and manipulating positive time intervals.

Definition at line 75 of file Time_defs.hh.

Constructor & Destructor Documentation

Parma_Polyhedra_Library::Implementation::Watchdog::Time::Time ( )
inline

Zero seconds.

Definition at line 36 of file Time_inlines.hh.

References OK().

37  : secs(0), microsecs(0) {
38  assert(OK());
39 }
bool OK() const
Checks if all the invariants are satisfied.
Definition: Time.cc:30
Parma_Polyhedra_Library::Implementation::Watchdog::Time::Time ( long  centisecs)
inlineexplicit

Constructor taking a number of centiseconds.

Definition at line 42 of file Time_inlines.hh.

References OK().

43  : secs(centisecs / CSECS_PER_SEC),
44  microsecs((centisecs % CSECS_PER_SEC) * (USECS_PER_SEC/CSECS_PER_SEC)) {
45  assert(OK());
46 }
static const long USECS_PER_SEC
Number of microseconds in a second.
Definition: Time_defs.hh:112
static const long CSECS_PER_SEC
Number of centiseconds in a second.
Definition: Time_defs.hh:115
bool OK() const
Checks if all the invariants are satisfied.
Definition: Time.cc:30
Parma_Polyhedra_Library::Implementation::Watchdog::Time::Time ( long  s,
long  m 
)
inline

Constructor with seconds and microseconds.

Definition at line 49 of file Time_inlines.hh.

References microsecs, OK(), secs, and USECS_PER_SEC.

50  : secs(s),
51  microsecs(m) {
52  if (microsecs >= USECS_PER_SEC) {
55  }
56  assert(OK());
57 }
static const long USECS_PER_SEC
Number of microseconds in a second.
Definition: Time_defs.hh:112
bool OK() const
Checks if all the invariants are satisfied.
Definition: Time.cc:30

Member Function Documentation

long Parma_Polyhedra_Library::Implementation::Watchdog::Time::microseconds ( ) const
inline

Returns the number of microseconds that, when added to the number of seconds returned by seconds(), give the represent time interval.

Definition at line 65 of file Time_inlines.hh.

References microsecs.

Referenced by Parma_Polyhedra_Library::Implementation::Watchdog::operator<(), and Parma_Polyhedra_Library::Implementation::Watchdog::operator==().

65  {
66  return microsecs;
67 }
bool Parma_Polyhedra_Library::Implementation::Watchdog::Time::OK ( ) const
Time & Parma_Polyhedra_Library::Implementation::Watchdog::Time::operator+= ( const Time y)
inline

Adds y to *this.

Definition at line 70 of file Time_inlines.hh.

References microsecs, OK(), secs, and USECS_PER_SEC.

70  {
71  long r_secs = secs + y.secs;
72  long r_microsecs = microsecs + y.microsecs;
73  if (r_microsecs >= USECS_PER_SEC) {
74  ++r_secs;
75  r_microsecs %= USECS_PER_SEC;
76  }
77  secs = r_secs;
78  microsecs = r_microsecs;
79  assert(OK());
80  return *this;
81 }
static const long USECS_PER_SEC
Number of microseconds in a second.
Definition: Time_defs.hh:112
bool OK() const
Checks if all the invariants are satisfied.
Definition: Time.cc:30
Time & Parma_Polyhedra_Library::Implementation::Watchdog::Time::operator-= ( const Time y)
inline

Subtracts y from *this; if *this is shorter than y, *this is set to the null interval.

Definition at line 84 of file Time_inlines.hh.

References microsecs, OK(), secs, and USECS_PER_SEC.

84  {
85  long r_secs = secs - y.secs;
86  long r_microsecs = microsecs - y.microsecs;
87  if (r_microsecs < 0) {
88  --r_secs;
89  r_microsecs += USECS_PER_SEC;
90  }
91  if (r_secs < 0) {
92  r_secs = 0;
93  r_microsecs = 0;
94  }
95  secs = r_secs;
96  microsecs = r_microsecs;
97  assert(OK());
98  return *this;
99 }
static const long USECS_PER_SEC
Number of microseconds in a second.
Definition: Time_defs.hh:112
bool OK() const
Checks if all the invariants are satisfied.
Definition: Time.cc:30
long Parma_Polyhedra_Library::Implementation::Watchdog::Time::seconds ( ) const
inline

Returns the number of whole seconds contained in the represented time interval.

Definition at line 60 of file Time_inlines.hh.

References secs.

Referenced by Parma_Polyhedra_Library::Implementation::Watchdog::operator<(), and Parma_Polyhedra_Library::Implementation::Watchdog::operator==().

60  {
61  return secs;
62 }

Member Data Documentation

const long Parma_Polyhedra_Library::Implementation::Watchdog::Time::CSECS_PER_SEC = 100L
staticprivate

Number of centiseconds in a second.

Definition at line 115 of file Time_defs.hh.

long Parma_Polyhedra_Library::Implementation::Watchdog::Time::microsecs
private

Number of microseconds.

Definition at line 121 of file Time_defs.hh.

Referenced by microseconds(), operator+=(), operator-=(), and Time().

long Parma_Polyhedra_Library::Implementation::Watchdog::Time::secs
private

Number of seconds.

Definition at line 118 of file Time_defs.hh.

Referenced by operator+=(), operator-=(), seconds(), and Time().

const long Parma_Polyhedra_Library::Implementation::Watchdog::Time::USECS_PER_SEC = 1000000L
staticprivate

Number of microseconds in a second.

Definition at line 112 of file Time_defs.hh.

Referenced by operator+=(), operator-=(), and Time().


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