]> git.tdb.fi Git - libs/core.git/blobdiff - source/time/timedelta.h
Use format instead of stringstream in TimeDelta
[libs/core.git] / source / time / timedelta.h
index ad985c7e2c1d13a7a738237c9d9f3af33c4b7212..631c4b0554a6549bcc79b810854a4167990cd72e 100644 (file)
@@ -1,13 +1,16 @@
-/*
+/* $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 <time.h>
-#include <ostream>
+#include <sys/time.h>
+#include <msp/strings/lexicalcast.h>
 #include "types.h"
 
 namespace Msp {
@@ -18,6 +21,9 @@ Represents a quantity of time, such as five seconds.
 */
 class TimeDelta
 {
+private:
+       RawTime usec;
+
 public:
        /**
        Constructs a zero TimeDelta.
@@ -42,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); }
@@ -70,14 +78,12 @@ public:
        bool      operator!=(const TimeDelta &t) const { return usec!=t.usec; }
 
        operator const void *() const                  { return usec ? this : 0; }
-private:
-       RawTime usec;
 };
 
 template<typename T>
 inline TimeDelta operator*(T a, const TimeDelta &t)   { return t*a; }
 
-extern std::ostream &operator<<(std::ostream &, const TimeDelta &);
+void operator<<(LexicalConverter &, const TimeDelta &);
 
 } // namespace Time
 } // namespace Msp