//
// C++ Implementation: time
//
// Description: 
//
//
// Author: Messenger of death aka Denis A. Birukov <messengerofdeath@gmail.com>, (C) 2009
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "me_time.h"
#include <sys/time.h>

Time::Time()
{
	timeval tv;
	gettimeofday(&tv, 0);
	_last_access_time_ = tv.tv_sec * 1000000 + tv.tv_usec; 
}
Time::~Time()
{
}
double Time::get_elapsed_time( )
{
	timeval tv;
	gettimeofday(&tv, 0);
        uint64_t dtime, cur_time;
        cur_time = tv.tv_sec * 1000000 + tv.tv_usec;
        dtime = cur_time - _last_access_time_;
        _last_access_time_ = cur_time;
        return (double)dtime/1000000.;
}
double Time::get_elapsed_time_noreset( )
{
	timeval tv;
	gettimeofday(&tv, 0);
        uint64_t dtime, cur_time;
        cur_time = tv.tv_sec * 1000000 + tv.tv_usec;
        dtime = cur_time - _last_access_time_;
        return (double)dtime/1000000.;
}
void Time::reset()
{
	timeval tv;
	gettimeofday(&tv, 0);
        _last_access_time_ = tv.tv_sec * 1000000 + tv.tv_usec;
}


