Minor changes to Time
base/time.cc: base/time.hh: Don't set the current time in the constructor. Use a flag and make the default to not set the time. Change reset() to set(). Dunno. Just seems right. --HG-- extra : convert_revision : 5a3b09ed30376d4863b45b2bae551ba1c3aff8e1
This commit is contained in:
parent
832a0917cf
commit
2484aeaee7
2 changed files with 10 additions and 9 deletions
15
base/time.cc
15
base/time.cc
|
@ -47,10 +47,11 @@ convert(const timeval &tv)
|
|||
return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
|
||||
}
|
||||
|
||||
Time::Time()
|
||||
Time::Time(bool set_now)
|
||||
{
|
||||
time = new _timeval;
|
||||
::gettimeofday(&time->tv, NULL);
|
||||
if (set_now)
|
||||
set();
|
||||
}
|
||||
|
||||
Time::Time(const timeval &val)
|
||||
|
@ -77,15 +78,15 @@ Time::get() const
|
|||
}
|
||||
|
||||
void
|
||||
Time::set(const timeval &tv)
|
||||
Time::set()
|
||||
{
|
||||
memcpy(&time->tv, &tv, sizeof(timeval));
|
||||
::gettimeofday(&time->tv, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
Time::reset()
|
||||
Time::set(const timeval &tv)
|
||||
{
|
||||
::gettimeofday(&time->tv, NULL);
|
||||
memcpy(&time->tv, &tv, sizeof(timeval));
|
||||
}
|
||||
|
||||
double
|
||||
|
@ -127,4 +128,4 @@ operator-(const Time &l, const Time &r)
|
|||
return tv;
|
||||
}
|
||||
|
||||
const Time Time::start;
|
||||
const Time Time::start(true);
|
||||
|
|
|
@ -42,15 +42,15 @@ class Time
|
|||
mutable _timeval *time;
|
||||
|
||||
public:
|
||||
Time();
|
||||
explicit Time(bool set_now = false);
|
||||
Time(const timeval &val);
|
||||
Time(const Time &val);
|
||||
~Time();
|
||||
|
||||
void set();
|
||||
const timeval &get() const;
|
||||
void set(const timeval &val);
|
||||
|
||||
void reset();
|
||||
double operator()() const;
|
||||
std::string date(std::string format = "") const;
|
||||
|
||||
|
|
Loading…
Reference in a new issue