diff options
author | Steve Reinhardt <stever@eecs.umich.edu> | 2003-10-28 12:56:17 -0800 |
---|---|---|
committer | Steve Reinhardt <stever@eecs.umich.edu> | 2003-10-28 12:56:17 -0800 |
commit | e12e64a0718f6805c1203e1d11a39abaf0d9483b (patch) | |
tree | 3908a0650ad9a4022fb906c553c3648d31c1fcb4 /sim/serialize.hh | |
parent | 18205206972932a236d0bf4f427918b57f9857f0 (diff) | |
parent | b90f810575679442d78c0e9cd0c98a057ba4871b (diff) | |
download | gem5-e12e64a0718f6805c1203e1d11a39abaf0d9483b.tar.xz |
Merge zizzer:bk/m5 into isabel.reinhardt.house:/z/stever/ser/m5
--HG--
extra : convert_revision : 50aa3791d27a17c4ea2fb4aee1a67011bd2abec1
Diffstat (limited to 'sim/serialize.hh')
-rw-r--r-- | sim/serialize.hh | 80 |
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 §ion, + 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 §ion, + 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 §ion) {} }; 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 |