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)
}
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
return tv;
}
-const Time Time::start;
+const Time Time::start(true);
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;