X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=inline;f=source%2Ftime%2Ftimedelta.h;h=a601f8dd6fbcf1fa46daa6ed6e4885ee06475d7f;hb=35f587ac1df01d9e0018fb8cb77e603b07ebf1b4;hp=a4595e6680e05ac8185b3e7273ec4acad8cc3136;hpb=dff78b5a8a1d947eb3391dd919abfa04a48d589c;p=libs%2Fcore.git diff --git a/source/time/timedelta.h b/source/time/timedelta.h index a4595e6..a601f8d 100644 --- a/source/time/timedelta.h +++ b/source/time/timedelta.h @@ -1,13 +1,15 @@ -/* +/* $Id$ + This file is part of libmspcore Copyright © 2006 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ + #ifndef MSP_TIME_TIMEDELTA_H_ #define MSP_TIME_TIMEDELTA_H_ -#include #include +#include #include #include "types.h" @@ -19,6 +21,9 @@ Represents a quantity of time, such as five seconds. */ class TimeDelta { +private: + RawTime usec; + public: /** Constructs a zero TimeDelta. @@ -44,6 +49,8 @@ public: TimeDelta, divide with one of the values in units.h. */ void fill_timespec(timespec &ts) const { ts.tv_sec=usec/1000000; ts.tv_nsec=(usec%1000000)*1000; } + + void fill_timeval(timeval &tv) const { tv.tv_sec=usec/1000000; tv.tv_usec=usec%1000000; } #endif TimeDelta operator+(const TimeDelta &t) const { return TimeDelta(usec+t.usec); } @@ -52,14 +59,14 @@ public: TimeDelta &operator-=(const TimeDelta &t) { usec-=t.usec; return *this; } template - TimeDelta operator*(T a) const { return TimeDelta(int64_t(usec*a)); } + TimeDelta operator*(T a) const { return TimeDelta(RawTime(usec*a)); } template - TimeDelta &operator*=(T a) { usec=int64_t(usec*a); return *this; } + TimeDelta &operator*=(T a) { usec=RawTime(usec*a); return *this; } template - TimeDelta operator/(T a) const { return TimeDelta(int64_t(usec/a)); } + TimeDelta operator/(T a) const { return TimeDelta(RawTime(usec/a)); } template - TimeDelta &operator/=(T a) { usec=int64_t(usec/a); return *this; } + TimeDelta &operator/=(T a) { usec=RawTime(usec/a); return *this; } double operator/(const TimeDelta &t) const { return double(usec)/t.usec; } @@ -71,8 +78,6 @@ public: bool operator!=(const TimeDelta &t) const { return usec!=t.usec; } operator const void *() const { return usec ? this : 0; } -private: - RawTime usec; }; template