// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

BALL_INLINE
PreciseTime::PreciseTime(long secs, long usecs)
	
	:	secs_(secs),
		usecs_(usecs)
{
}

BALL_INLINE
PreciseTime::~PreciseTime()
	
{
}

BALL_INLINE
void PreciseTime::set(const PreciseTime& time)
	
{
	secs_ = time.secs_;
	usecs_ = time.usecs_;
}

BALL_INLINE
void PreciseTime::set(long secs, long usecs)
	
{
	secs_ = secs;
	usecs_ = usecs;
}

BALL_INLINE
const PreciseTime& PreciseTime::operator = (const PreciseTime& time)
	
{
	set(time);
	return *this;
}

BALL_INLINE
void PreciseTime::clear() 
	
{
	secs_ = 0;
	usecs_ = 0;
}

BALL_INLINE
bool PreciseTime::operator < (const PreciseTime& time) const
	
{
	return ((secs_ < time.secs_) || ((secs_ == time.secs_) && (usecs_ < time.usecs_)));
}

BALL_INLINE
bool PreciseTime::operator > (const PreciseTime& time) const 
	
{
	return ((secs_ > time.secs_) || ((secs_ == time.secs_) && (usecs_ > time.usecs_)));
}

BALL_INLINE
bool PreciseTime::operator == (const PreciseTime& time) const 
	
{
	return ((secs_ == time.secs_) && (usecs_ == time.usecs_));
}

BALL_INLINE
long PreciseTime::getSeconds() const 
	
{
	return secs_;
}

BALL_INLINE
long PreciseTime::getMicroSeconds() const 
	
{
	return usecs_;
}

BALL_INLINE
bool TimeStamp::isOlderThan(const PreciseTime& time) const 
	
{
	return (time_ < time);
}

BALL_INLINE
bool TimeStamp::isNewerThan(const PreciseTime& time) const 
	
{
	return (time_ > time);
}

BALL_INLINE
bool TimeStamp::isOlderThan(const TimeStamp& stamp) const 
	
{
	return (time_ < stamp.time_);
}

BALL_INLINE
bool TimeStamp::isNewerThan(const TimeStamp& stamp) const 
	
{
	return (time_ > stamp.time_);
}

BALL_INLINE
void TimeStamp::clear()
	
{
	time_.clear();
}

BALL_INLINE
TimeStamp::~TimeStamp()
	
{
	clear();
}

BALL_INLINE
void TimeStamp::stamp(const PreciseTime& time) 
	
{
	// in the default case, stamp with the current 
	// time
	if (time == PreciseTime::ZERO)
	{
		time_ = PreciseTime::now();
	}
	else 
	{
		time_ = time;
	}
}

BALL_INLINE
const PreciseTime& TimeStamp::getTime() const 
	
{
	return time_;
}

BALL_INLINE
void TimeStamp::write(PersistenceManager& pm) const
	
{
	pm.writeStorableObject(time_, "time_");
}

BALL_INLINE
bool TimeStamp::read(PersistenceManager& pm)
	
{
	return pm.readStorableObject(time_, "time_");
}

BALL_INLINE
bool TimeStamp::operator == (const TimeStamp& stamp) const 
	
{
	return time_ == stamp.time_;
}
