9 static const char rcsid[] __attribute__((used)) =
"$Id: TimeStamp.cpp 1653 2016-02-28 19:54:59Z sella $";
11 #include "TimeStamp.h"
17 using namespace sella::util;
19 TimeStamp::TimeStamp(
const struct timeval &tv)
throw () :
20 stamp((tv.tv_sec * 1000000) + tv.tv_usec)
23 TimeStamp::TimeStamp(int64_t usec)
throw () :
27 TimeStamp::TimeStamp() throw () :
31 TimeStamp::TimeStamp(
const TimeStamp &other)
throw () :
35 TimeStamp::~TimeStamp() throw () { }
39 this->stamp = other.stamp;
44 TimeStamp & TimeStamp::operator = (
const struct timeval &tv)
throw () {
45 this->stamp = (tv.tv_sec * 1000000) + tv.tv_usec;
50 TimeStamp & TimeStamp::operator = (int64_t micro)
throw () {
58 this->stamp += other.stamp;
63 TimeStamp & TimeStamp::operator += (
const struct timeval &tv)
throw () {
64 this->stamp += (tv.tv_sec * 1000000) + tv.tv_usec;
69 TimeStamp & TimeStamp::operator += (int64_t micro)
throw () {
77 this->stamp -= other.stamp;
82 TimeStamp & TimeStamp::operator -= (
const struct timeval &tv)
throw () {
83 this->stamp -= (tv.tv_sec * 1000000) + tv.tv_usec;
88 TimeStamp & TimeStamp::operator -= (int64_t micro)
throw () {
96 this->stamp *= other.stamp;
101 TimeStamp & TimeStamp::operator *= (
const struct timeval &tv)
throw () {
102 this->stamp *= (tv.tv_sec * 1000000) + tv.tv_usec;
107 TimeStamp & TimeStamp::operator *= (int64_t micro)
throw () {
108 this->stamp *= micro;
114 if (
this != &other) {
115 this->stamp /= other.stamp;
120 TimeStamp & TimeStamp::operator /= (
const struct timeval &tv)
throw () {
121 this->stamp /= (tv.tv_sec * 1000000) + tv.tv_usec;
126 TimeStamp & TimeStamp::operator /= (int64_t micro)
throw () {
127 this->stamp /= micro;
133 return TimeStamp(this->stamp + other.stamp);
136 TimeStamp TimeStamp::operator + (
const struct timeval &tv)
throw () {
137 return TimeStamp(this->stamp + ((tv.tv_sec * 1000000) + tv.tv_usec));
140 TimeStamp TimeStamp::operator + (int64_t micro)
throw () {
145 return TimeStamp(this->stamp - other.stamp);
148 TimeStamp TimeStamp::operator - (
const struct timeval &tv)
throw () {
149 return TimeStamp(this->stamp - ((tv.tv_sec * 1000000) + tv.tv_usec));
152 TimeStamp TimeStamp::operator - (int64_t micro)
throw () {
157 return TimeStamp(this->stamp * other.stamp);
160 TimeStamp TimeStamp::operator * (
const struct timeval &tv)
throw () {
161 return TimeStamp(this->stamp * ((tv.tv_sec * 1000000) + tv.tv_usec));
164 TimeStamp TimeStamp::operator * (int64_t micro)
throw () {
169 return TimeStamp(this->stamp / other.stamp);
172 TimeStamp TimeStamp::operator / (
const struct timeval &tv)
throw () {
173 return TimeStamp(this->stamp / ((tv.tv_sec * 1000000) + tv.tv_usec));
176 TimeStamp TimeStamp::operator / (int64_t micro)
throw () {
180 bool TimeStamp::operator == (
const TimeStamp &other)
const throw () {
181 return this->stamp == other.stamp;
184 bool TimeStamp::operator != (
const TimeStamp &other)
const throw () {
185 return this->stamp != other.stamp;
188 bool TimeStamp::operator >= (
const TimeStamp &other)
const throw () {
189 return this->stamp >= other.stamp;
192 bool TimeStamp::operator <= (
const TimeStamp &other)
const throw () {
193 return this->stamp <= other.stamp;
196 bool TimeStamp::operator > (
const TimeStamp &other)
const throw () {
197 return this->stamp > other.stamp;
200 bool TimeStamp::operator < (
const TimeStamp &other)
const throw () {
201 return this->stamp < other.stamp;
204 void TimeStamp::update() throw () {
205 this->stamp = TimeStamp::now();
208 int64_t TimeStamp::now() throw () {
211 gettimeofday(&tv, NULL);
213 return (tv.tv_sec * 1000000) + tv.tv_usec;
216 int64_t TimeStamp::getEpochMicroseconds()
const throw () {
220 int64_t TimeStamp::getEpochSeconds()
const throw () {
221 return this->stamp / 1000000;