/*! ========================================================================
** Extended Template and Library
** gettimeofday() Clock Description Implementation
-** $Id: _clock_gettimeofday.h,v 1.1.1.1 2005/01/04 01:31:46 darco Exp $
+** $Id$
**
** Copyright (c) 2002 Robert B. Quattlebaum Jr.
**
{
timestamp(int sec, int usec)
{ tv_sec=sec; tv_usec=usec; }
-
- friend class clock_desc_gettimeofday;
+
+ friend class clock_desc_gettimeofday;
public:
timestamp() { }
-
-
+
+
inline timestamp operator-(const timestamp &rhs)const
{
timestamp ret;
ret.tv_usec=tv_usec-rhs.tv_usec;
-
+
if(ret.tv_usec<0)
{
ret.tv_sec=tv_sec-rhs.tv_sec-1;
return ret;
}
- inline timestamp &operator+(timestamp rhs)const
+ inline timestamp operator+(timestamp rhs)const
{
rhs.tv_usec+=tv_usec;
-
+
if(rhs.tv_usec>1000000)
{
rhs.tv_sec+=tv_sec+1;
rhs.tv_sec+=tv_sec;
return rhs;
}
-
+
inline bool operator<(const timestamp &rhs)const
{ return tv_sec<rhs.tv_sec || tv_usec<rhs.tv_usec; }
inline bool operator!=(const timestamp &rhs)const
{ return tv_usec!=rhs.tv_usec || tv_sec!=rhs.tv_sec; }
};
-
+
static void
get_current_time(timestamp &x)
{ gettimeofday(&x,NULL);}
static timestamp
get_current_time()
{ timestamp ret; get_current_time(ret); return ret; }
-
+
static value_type
timestamp_to_seconds(const timestamp &x)
- { return (value_type)x.tv_sec + precision()*x.tv_usec; }
+ { return (value_type)x.tv_sec + precision()*x.tv_usec; }
static timestamp
seconds_to_timestamp(const value_type &x)
- { return timestamp((int)floor(x), (int)((x-floor(x))/precision()+0.5)); }
+ { return timestamp((int)floor(x), (int)((x-floor(x))/precision()+0.5)); }
};
_ETL_END_NAMESPACE