/******************************************************* ** Name: timestamp.cxx ** Author: Leo Liberti ** Source: GNU C++ ** Purpose: www exploring topologizer: TimeStamp class ** History: 060820 work started *******************************************************/ #include #include #include "timestamp.h" TimeStampException::TimeStampException() { } TimeStampException::~TimeStampException() { } long TimeStamp::get(void) const { return timestamp; } void TimeStamp::set(long theTimeStamp) { timestamp = theTimeStamp; } void TimeStamp::update(void) throw (TimeStampException) { struct timeval tv; struct timezone tz; using namespace std; try { int retVal = gettimeofday(&tv, &tz); if (retVal == -1) { cerr << "TimeStamp::updateTimeStamp(): couldn't get system time" << endl; throw TimeStampException(); } } catch (...) { cerr << "TimeStamp::updateTimeStamp(): couldn't get system time" << endl; throw TimeStampException(); } timestamp = tv.tv_sec; } std::ostream& operator<<(std::ostream& s, TimeStamp& t) throw (TimeStampException) { using namespace std; time_t theTime = (time_t) t.get(); char* buffer; try { buffer = ctime(&theTime); } catch (...) { cerr << "TimeStamp::updateTimeStamp(): couldn't print system time" << endl; throw TimeStampException(); } buffer[strlen(buffer) - 1] = '\0'; s << buffer; return s; }