#ifndef _utl_TimeInterval_h_ #define _utl_TimeInterval_h_ #include #include namespace utl { /** \class TimeInterval TimeInterval.h "utl/TimeInterval.h" \brief A TimeInterval is used to represent time elapsed between two events For information on how to use TimeInterval's together with TimeStamp's in your code, see the documentation in utl::TimeStamp. From a TimeInterval, one can extract the lower bound on the number of seconds in the interval (the seconds floor) as well as the number of nanoseconds past the seconds floor. When subracting TimeInvervals or TimeStamps to yield a TimeInterval, there are two cases to consider: Note that this class uses a double precision floating point to represent the elapsed time between two events. 52 bits are allocated for the mantissa of a double precision number, this interval is precise to about 1 part in 5.4e15. If for example 1 ns precision were required, one could use this class to describe intervals up to about 62 days. Basic arithmetic operations are defined for TimeInterval. See the documentation for utl::TimeStamp for some examples. \author T. Paul \author D. Veberic \date 19 Feb 2003 \version $Id: TimeInterval.h 20387 2012-02-05 19:07:37Z darko $ \ingroup time */ class TimeInterval : public SafeBoolCast { public: TimeInterval(const double interval = 0) : fInterval(interval) { } TimeInterval(const TimeInterval& ti) : fInterval(ti.fInterval) { } TimeInterval& operator=(const TimeInterval& ti) { fInterval = ti.fInterval; return *this; } /// [TimeInterval] = double TimeInterval& operator=(const double& d) { fInterval = d; return *this; } /// Get the seconds floor for the interval /*! This number is positive if the interval is positive, and negative if the interval is negative */ int GetSecond() const; /// Get integer number of nanoseconds past seconds boundary. /*! This number is always positive */ double GetNanoSecond() const; /// Get the time interval as a double (in Auger base units) double GetInterval() const { return fInterval; } /// Implicitly convert TimeInterval to double operator double() const { return fInterval; } /// [TimeInterval] + [TimeInterval] = [TimeInterval] TimeInterval operator+(const TimeInterval& ti) const { return TimeInterval(fInterval + ti.fInterval); } /// [TimeInterval] - [TimeInterval] = [TimeInterval] TimeInterval operator-(const TimeInterval& ti) const { return TimeInterval(fInterval - ti.fInterval); } /// [TimeInterval] * [double] = [TimeInterval] TimeInterval operator*(const double& d) const { return TimeInterval(fInterval * d); } /// [double] * [TimeInterval] = [TimeInterval] friend TimeInterval operator*(const double& d, const TimeInterval& ti) { return TimeInterval(d * ti.fInterval); } /// [TimeInterval] / [TimeInterval] = [double] double operator/(const TimeInterval& ti) const { return fInterval / ti.fInterval; } /// [TimeInterval] / [double] = [TimeInterval] TimeInterval operator/(const double& d) const { return TimeInterval(fInterval / d); } /// [TimeInterval] += [TimeInterval] = [TimeInterval] TimeInterval operator+=(const TimeInterval& ti) { fInterval += ti.fInterval; return *this; } /// [TimeInterval] -= [TimeInterval] = [TimeInterval] TimeInterval& operator-=(const TimeInterval& ti) { fInterval -= ti.fInterval; return *this; } /// [TimeInterval] *= [TimeInterval] = [TimeInterval] TimeInterval& operator*=(const double& d) { fInterval *= d; return *this; } /// [TimeInterval] /= [double] = [TimeInterval] TimeInterval& operator/=(const double& d) { fInterval /= d; return *this; } /// unary sign reversal TimeInterval operator-() const { return TimeInterval(-fInterval); } bool operator>(const TimeInterval& ti) const { return (fInterval > ti.fInterval); } bool operator>=(const TimeInterval& ti) const { return (fInterval >= ti.fInterval); } bool operator<(const TimeInterval& ti) const { return (fInterval < ti.fInterval); } bool operator<=(const TimeInterval& ti) const { return (fInterval <= ti.fInterval); } bool operator==(const TimeInterval& ti) const { return (fInterval == ti.fInterval); } bool operator!=(const TimeInterval& ti) const { return (fInterval != ti.fInterval); } bool BoolCast() const { return fInterval; } /// stream output friend std::ostream& operator<<(std::ostream& os, const TimeInterval& ti) { return os << ti.fInterval; } // TODO double min/max? static TimeInterval Min() { return -4.294967296e9; } static TimeInterval Max() { return 4.294967296e9; } private: /** stored in Auger base time units (see Utilities/Units/include/utl/AugerUnits.h) */ double fInterval; }; } #endif