Belle II Software development
Time Class Reference
Inheritance diagram for Time:
Serializable

Public Member Functions

 Time (const double)
 
 Time (const long, const long)
 
void clear ()
 
void set ()
 
void set (const double)
 
void set (const long, const long)
 
double get () const
 
long getSecond () const
 
long getMicroSecond () const
 
std::string toString () const
 
void readObject (Reader &) override
 
void writeObject (Writer &) const override
 
bool operator== (const Time &) const
 
Time operator+ (const Time &) const
 
Time operator- (const Time &) const
 

Private Member Functions

void adjust ()
 

Private Attributes

long m_s
 
long m_us
 

Detailed Description

Definition at line 21 of file Time.h.

Constructor & Destructor Documentation

◆ Time() [1/3]

Time ( )
explicit

Definition at line 23 of file Time.cc.

24{
25 timeval tv;
26 gettimeofday(&tv, 0);
27 m_s = tv.tv_sec;
28 m_us = tv.tv_usec;
29}

◆ Time() [2/3]

Time ( const double  t)

Definition at line 31 of file Time.cc.

32{
33 set(t);
34}

◆ Time() [3/3]

Time ( const long  s,
const long  us 
)

Definition at line 36 of file Time.cc.

37 : m_s(s), m_us(us)
38{
39 adjust();
40}

◆ ~Time()

~Time ( )

Definition at line 42 of file Time.cc.

43{
44}

Member Function Documentation

◆ adjust()

void adjust ( )
private

Definition at line 46 of file Time.cc.

47{
48 if (MEGA <= labs(m_us)) {
49 m_s += m_us / MEGA;
50 m_us = m_us - (m_us / MEGA) * MEGA;
51 }
52 if (0 < m_s && m_us < 0) {
53 m_s--;
54 m_us += MEGA;
55 }
56 if (m_s < 0 && 0 < m_us) {
57 m_s++;
58 m_us -= MEGA;
59 }
60}

◆ clear()

void clear ( )

Definition at line 62 of file Time.cc.

63{
64 m_s = m_us = 0;
65}

◆ get()

double get ( ) const

Definition at line 91 of file Time.cc.

92{
93 return (double)m_s + ((double)m_us) / 1000000.;
94}

◆ getMicroSecond()

long getMicroSecond ( ) const

Definition at line 101 of file Time.cc.

102{
103 return m_us;
104}

◆ getSecond()

long getSecond ( ) const

Definition at line 96 of file Time.cc.

97{
98 return m_s;
99}

◆ operator+()

Time operator+ ( const Time t) const

Definition at line 130 of file Time.cc.

131{
132 Time tt = *this;
133 tt.m_s += t.m_s;
134 tt.m_us += t.m_us;
135 return tt;
136}

◆ operator-()

Time operator- ( const Time t) const

Definition at line 138 of file Time.cc.

139{
140 Time tt = *this;
141 tt.m_s -= t.m_s;
142 tt.m_us -= t.m_us;
143 return tt;
144}

◆ operator==()

bool operator== ( const Time t) const

Definition at line 125 of file Time.cc.

126{
127 return (m_s == t.m_s) && (m_us == t.m_us);
128}

◆ readObject()

void readObject ( Reader r)
overridevirtual

Implements Serializable.

Definition at line 113 of file Time.cc.

114{
115 m_s = r.readLong();
116 m_us = r.readLong();
117}

◆ set() [1/3]

void set ( )

Definition at line 67 of file Time.cc.

68{
69 timeval tv;
70 gettimeofday(&tv, 0);
71 m_s = tv.tv_sec;
72 m_us = tv.tv_usec;
73}

◆ set() [2/3]

void set ( const double  t)

Definition at line 75 of file Time.cc.

76{
77 double s, us;
78 us = modf(t, &s);
79 m_s = (long)s;
80 m_us = (long)(us * 1000000);
81 adjust();
82}

◆ set() [3/3]

void set ( const long  s,
const long  us 
)

Definition at line 84 of file Time.cc.

85{
86 m_s = s;
87 m_us = us;
88 adjust();
89}

◆ toString()

std::string toString ( ) const

Definition at line 106 of file Time.cc.

107{
108 std::stringstream ss;
109 ss << m_s << "." << m_us;
110 return ss.str();
111}

◆ writeObject()

void writeObject ( Writer w) const
overridevirtual

Implements Serializable.

Definition at line 119 of file Time.cc.

120{
121 w.writeLong(m_s);
122 w.writeLong(m_us);
123}

Member Data Documentation

◆ m_s

long m_s
private

Definition at line 57 of file Time.h.

◆ m_us

long m_us
private

Definition at line 58 of file Time.h.


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