/* name: timestamp.cxx author: the C++ course @X purpose: example for INF585 - time stamp method implementation source: GNU C++ history: 100126 work started */ #include #include #include "timestamp.h" TimeStamp::TimeStamp() : timestamp(0) { using namespace std; cout << "TimeStamp constructor: called by " << this << endl; } TimeStamp::~TimeStamp() { using namespace std; cout << "TimeStamp destructor: called by " << this << endl; } void TimeStamp::update(void) throw (TimeStampException) { using namespace std; struct timeval tv; struct timezone tz; try { int ret = gettimeofday(&tv, &tz); } catch (...) { std::cout << "catching all exceptions" << std::endl; throw TimeStampException(); } timestamp = tv.tv_sec; } long TimeStamp::get(void) const { return timestamp; } TimeStampException::TimeStampException() {} TimeStampException::~TimeStampException() {} int TimeStamp::operator/(int a) { return timestamp / a; }