summaryrefslogtreecommitdiff
path: root/sim/serialize.hh
diff options
context:
space:
mode:
authorSteve Reinhardt <stever@eecs.umich.edu>2003-10-28 12:55:12 -0800
committerSteve Reinhardt <stever@eecs.umich.edu>2003-10-28 12:55:12 -0800
commitb90f810575679442d78c0e9cd0c98a057ba4871b (patch)
tree8882e14d0f8cbee6f7c630ecb2408b62974a32d2 /sim/serialize.hh
parentcec7f73abf841a65bdce38d6eb67a643e4879335 (diff)
downloadgem5-b90f810575679442d78c0e9cd0c98a057ba4871b.tar.xz
Revamp serialization to make it easier.
--HG-- extra : convert_revision : c57a538d7cf606dbdf5fa244f92da46bd830e335
Diffstat (limited to 'sim/serialize.hh')
-rw-r--r--sim/serialize.hh80
1 files changed, 34 insertions, 46 deletions
diff --git a/sim/serialize.hh b/sim/serialize.hh
index ffcbbcdc2..5ebbfaba5 100644
--- a/sim/serialize.hh
+++ b/sim/serialize.hh
@@ -36,44 +36,52 @@
#include <list>
#include <iostream>
+#include <map>
#include "sim/host.hh"
#include "sim/configfile.hh"
class IniFile;
+template <class T>
+void paramOut(std::ostream &os, const std::string &name, const T& param);
+
+template <class T>
+void paramIn(IniFile &db, const std::string &section,
+ const std::string &name, T& param);
+
+template <class T>
+void arrayParamOut(std::ostream &os, const std::string &name,
+ const T *param, int size);
+
+template <class T>
+void arrayParamIn(IniFile &db, const std::string &section,
+ const std::string &name, T *param, int size);
+
+//
+// These macros are streamlined to use in serialize/unserialize
+// functions. It's assumed that serialize() has a parameter 'os' for
+// the ostream, and unserialize() has parameters 'db' and 'section'.
+#define SERIALIZE_MEMBER(member) paramOut(os, #member, member)
+
+#define UNSERIALIZE_MEMBER(member) paramIn(db, section, #member, member)
+
+#define SERIALIZE_ARRAY(member, size) \
+ arrayParamOut(os, #member, member, size)
+
+#define UNSERIALIZE_ARRAY(member, size) \
+ arrayParamIn(db, section, #member, member, size)
+
/*
* Basic support for object serialization.
*/
class Serializeable
{
public:
- // To allow other classes to do some of the serialization work.
- class Proxy {
- private:
- Serializeable *obj;
-
- // Make it so only Serializables can construct one of these.
- Proxy(Serializeable *o) : obj(o) {};
-
- friend class Serializeable;
-
- public:
- template <class T>
- void paramOut(const std::string &name, const T& param) const {
- obj->paramOut(name, param);
- };
- };
friend class Serializer;
- friend class Proxy;
-
- private:
- Proxy proxy;
protected:
- const Proxy &getProxy() { return(proxy); };
-
// object name: should be unique
std::string objName;
@@ -81,13 +89,8 @@ class Serializeable
static Serializer *serializer;
void mark();
- void nameOut();
- void nameOut(const std::string &_name);
- void childOut(const std::string &name, Serializeable *child);
- template <class T>
- void paramOut(const std::string &name, const T& param);
-
- std::ostream &out() const;
+ void nameOut(std::ostream& os);
+ void nameOut(std::ostream& os, const std::string &_name);
public:
Serializeable(const std::string &n);
@@ -99,12 +102,8 @@ class Serializeable
const std::string &name() const { return objName; }
virtual void nameChildren() {}
- virtual void serialize() {}
- virtual void unserialize(IniFile &db, const std::string &category,
- ConfigNode *node = NULL)
- {
- std::cout << name() << " is being unserialized" << std::endl;
- }
+ virtual void serialize(std::ostream& os) {}
+ virtual void unserialize(IniFile &db, const std::string &section) {}
};
class Serializer
@@ -131,17 +130,6 @@ class Serializer
const std::string &filename() const { return file; }
};
-template <class T>
-inline void
-Serializeable::paramOut(const std::string &name, const T& param)
-{
- out() << name << "=" << param << "\n";
-}
-
-template <> void
-Serializeable::paramOut(const std::string &name, const uint64_t& param);
-
-
//
// A SerializeableBuilder serves as an evaluation context for a set of
// parameters that describe a specific instance of a Serializeable. This