X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ftime%2Ftimedelta.h;h=0ced98ecd3e7e581795056959895a8941ae3e966;hb=b56eb5ec1da675da0c66abc53c1e4f6c4e4cccbd;hp=a4595e6680e05ac8185b3e7273ec4acad8cc3136;hpb=dff78b5a8a1d947eb3391dd919abfa04a48d589c;p=libs%2Fcore.git diff --git a/source/time/timedelta.h b/source/time/timedelta.h index a4595e6..0ced98e 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. @@ -43,7 +48,9 @@ public: Fills in a timespec struct. To get a meaningful scalar value from the 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_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