changeset 23676:e719f04a5707

new output stream operator for octave::sys::time objects * oct-time.h, oct-time.cc (time::operator <<): New operator.
author John W. Eaton <jwe@octave.org>
date Thu, 22 Jun 2017 08:22:25 -0400
parents f71c0195b19d
children 66c4d224f7cb
files liboctave/system/oct-time.cc liboctave/system/oct-time.h
diffstat 2 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/system/oct-time.cc	Thu Jun 22 08:19:10 2017 -0400
+++ b/liboctave/system/oct-time.cc	Thu Jun 22 08:22:25 2017 -0400
@@ -27,12 +27,15 @@
 #include <cmath>
 #include <ctime>
 
+#include <iomanip>
+#include <iostream>
 #include <limits>
 
 #include "lo-error.h"
 #include "lo-utils.h"
 #include "oct-locbuf.h"
 #include "oct-time.h"
+#include "octave-preserve-stream-state.h"
 #include "strftime-wrapper.h"
 #include "strptime-wrapper.h"
 #include "time-wrappers.h"
@@ -88,6 +91,17 @@
       return localtime (*this).asctime ();
     }
 
+    std::ostream&
+    operator << (std::ostream& os, const time& ot)
+    {
+      preserve_stream_state stream_state (os);
+
+      os << ot.ot_unix_time << "."
+         << std::setw (6) << std::setfill ('0') << ot.ot_usec;
+
+      return os;
+    }
+
     void
     time::stamp (void)
     {
--- a/liboctave/system/oct-time.h	Thu Jun 22 08:19:10 2017 -0400
+++ b/liboctave/system/oct-time.h	Thu Jun 22 08:22:25 2017 -0400
@@ -26,6 +26,8 @@
 #include "octave-config.h"
 
 #include <ctime>
+
+#include <iosfwd>
 #include <string>
 
 static inline double
@@ -111,6 +113,8 @@
 
       std::string ctime (void) const;
 
+      friend std::ostream& operator << (std::ostream& os, const time& ot);
+
     private:
 
       // Seconds since the epoch.