changeset 20da8e9ed59f in /z/repo/m5
details: http://repo.m5sim.org/m5?cmd=changeset;node=20da8e9ed59f
description:
        Serialization: Allow serialization of stl lists

diffstat:

 src/sim/serialize.cc |  56 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/sim/serialize.hh |   8 +++++++
 2 files changed, 63 insertions(+), 1 deletions(-)

diffs (105 lines):

diff -r 6d07db809a81 -r 20da8e9ed59f src/sim/serialize.cc
--- a/src/sim/serialize.cc      Fri Feb 11 18:29:35 2011 -0600
+++ b/src/sim/serialize.cc      Fri Feb 11 18:29:35 2011 -0600
@@ -201,6 +201,23 @@
     os << "\n";
 }
 
+template <class T>
+void
+arrayParamOut(ostream &os, const string &name, const list<T> &param)
+{
+    typename list<T>::const_iterator it = param.begin();
+
+    os << name << "=";
+    if (param.size() > 0)
+        showParam(os, *it);
+    it++;
+    while (it != param.end()) {
+        os << " ";
+        showParam(os, *it);
+        it++;
+    }
+    os << "\n";
+}
 
 template <class T>
 void
@@ -326,6 +343,37 @@
     }
 }
 
+template <class T>
+void
+arrayParamIn(Checkpoint *cp, const string &section,
+             const string &name, list<T> &param)
+{
+    string str;
+    if (!cp->find(section, name, str)) {
+        fatal("Can't unserialize '%s:%s'\n", section, name);
+    }
+    param.clear();
+
+    vector<string> tokens;
+    tokenize(tokens, str, ' ');
+
+    for (vector<string>::size_type i = 0; i < tokens.size(); i++) {
+        T scalar_value = 0;
+        if (!parseParam(tokens[i], scalar_value)) {
+            string err("could not parse \"");
+
+            err += str;
+            err += "\"";
+
+            fatal(err);
+        }
+
+        // assign parsed value to vector
+        param.push_back(scalar_value);
+    }
+}
+
+
 void
 objParamIn(Checkpoint *cp, const string &section,
            const string &name, SimObject * &param)
@@ -356,7 +404,13 @@
               const vector<type> &param);                               \
 template void                                                           \
 arrayParamIn(Checkpoint *cp, const string &section,                     \
-             const string &name, vector<type> &param);
+             const string &name, vector<type> &param);                  \
+template void                                                           \
+arrayParamOut(ostream &os, const string &name,                          \
+              const list<type> &param);                                 \
+template void                                                           \
+arrayParamIn(Checkpoint *cp, const string &section,                     \
+             const string &name, list<type> &param);
 
 INSTANTIATE_PARAM_TEMPLATES(char)
 INSTANTIATE_PARAM_TEMPLATES(signed char)
diff -r 6d07db809a81 -r 20da8e9ed59f src/sim/serialize.hh
--- a/src/sim/serialize.hh      Fri Feb 11 18:29:35 2011 -0600
+++ b/src/sim/serialize.hh      Fri Feb 11 18:29:35 2011 -0600
@@ -70,6 +70,10 @@
                    const std::vector<T> &param);
 
 template <class T>
+void arrayParamOut(std::ostream &os, const std::string &name,
+                   const std::list<T> &param);
+
+template <class T>
 void arrayParamIn(Checkpoint *cp, const std::string &section,
                   const std::string &name, T *param, unsigned size);
 
@@ -77,6 +81,10 @@
 void arrayParamIn(Checkpoint *cp, const std::string &section,
                   const std::string &name, std::vector<T> &param);
 
+template <class T>
+void arrayParamIn(Checkpoint *cp, const std::string &section,
+                  const std::string &name, std::list<T> &param);
+
 void
 objParamIn(Checkpoint *cp, const std::string &section,
            const std::string &name, SimObject * &param);
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to