Time: Add serialization functions to the Time class.
authorGabe Black <gblack@eecs.umich.edu>
Thu, 3 Feb 2011 02:05:03 +0000 (18:05 -0800)
committerGabe Black <gblack@eecs.umich.edu>
Thu, 3 Feb 2011 02:05:03 +0000 (18:05 -0800)
src/base/time.cc
src/base/time.hh

index 0fab938a4adc6dc494882320a5f47f53d115d03a..8ce2e21375fb9c9560a668ea5c9c200bc9d09a32 100644 (file)
@@ -34,6 +34,7 @@
 #include "base/time.hh"
 #include "config/use_posix_clock.hh"
 #include "sim/core.hh"
+#include "sim/serialize.hh"
 
 using namespace std;
 
@@ -113,6 +114,25 @@ Time::time() const
     return str.str();
 }
 
+void
+Time::serialize(const std::string &base, ostream &os)
+{
+    paramOut(os, base + ".sec", sec());
+    paramOut(os, base + ".nsec", nsec());
+}
+
+void
+Time::unserialize(const std::string &base, Checkpoint *cp,
+                  const string &section)
+{
+    time_t secs;
+    time_t nsecs;
+    paramIn(cp, section, base + ".sec", secs);
+    paramIn(cp, section, base + ".nsec", nsecs);
+    sec(secs);
+    nsec(nsecs);
+}
+
 void
 sleep(const Time &time)
 {
index 4fc3dd3ef41f1524bcbb42e12c6e21fc20e6ffcb..20b1c6d3588714da13223aa5ead5c0fcf2aec058 100644 (file)
 #include <cstring>
 #include <ctime>
 #include <iosfwd>
+#include <iostream>
 #include <string>
 
 #include "base/types.hh"
 
+class Checkpoint;
+
 class Time
 {
   protected:
@@ -195,6 +198,10 @@ class Time
 
     std::string date(const std::string &format = "") const;
     std::string time() const;
+
+    void serialize(const std::string &base, std::ostream &os);
+    void unserialize(const std::string &base, Checkpoint *cp,
+                     const std::string &section);
 };
 
 void sleep(const Time &time);