types: Move stuff for global types into src/base/types.hh
[gem5.git] / src / sim / serialize.hh
index 880fb0785859d85427ee31239fce4b77315752f7..0069f56144d0d95b2edd6714f250e7b15e8e94f9 100644 (file)
 
 
 #include <list>
+#include <vector>
 #include <iostream>
 #include <map>
 
-#include "sim/host.hh"
+#include "base/types.hh"
 
 class IniFile;
 class Serializable;
 class Checkpoint;
+class SimObject;
 
 template <class T>
 void paramOut(std::ostream &os, const std::string &name, const T &param);
@@ -59,46 +61,54 @@ template <class T>
 void arrayParamOut(std::ostream &os, const std::string &name,
                    const T *param, int size);
 
+template <class T>
+void arrayParamOut(std::ostream &os, const std::string &name,
+                   const std::vector<T> &param);
+
 template <class T>
 void arrayParamIn(Checkpoint *cp, const std::string &section,
                   const std::string &name, T *param, int size);
 
+template <class T>
+void arrayParamIn(Checkpoint *cp, const std::string &section,
+                  const std::string &name, std::vector<T> &param);
+
 void
 objParamIn(Checkpoint *cp, const std::string &section,
-           const std::string &name, Serializable * &param);
+           const std::string &name, SimObject * &param);
 
 
 //
 // 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 'cp' and 'section'.
-#define SERIALIZE_SCALAR(scalar)       paramOut(os, #scalar, scalar)
+#define SERIALIZE_SCALAR(scalar)        paramOut(os, #scalar, scalar)
 
-#define UNSERIALIZE_SCALAR(scalar)     paramIn(cp, section, #scalar, scalar)
+#define UNSERIALIZE_SCALAR(scalar)      paramIn(cp, section, #scalar, scalar)
 
 // ENUMs are like SCALARs, but we cast them to ints on the way out
-#define SERIALIZE_ENUM(scalar)         paramOut(os, #scalar, (int)scalar)
+#define SERIALIZE_ENUM(scalar)          paramOut(os, #scalar, (int)scalar)
 
-#define UNSERIALIZE_ENUM(scalar)               \
- do {                                          \
-    int tmp;                                   \
-    paramIn(cp, section, #scalar, tmp);                \
-    scalar = (typeof(scalar))tmp;              \
+#define UNSERIALIZE_ENUM(scalar)                \
+ do {                                           \
+    int tmp;                                    \
+    paramIn(cp, section, #scalar, tmp);         \
+    scalar = (typeof(scalar))tmp;               \
   } while (0)
 
-#define SERIALIZE_ARRAY(member, size)  \
+#define SERIALIZE_ARRAY(member, size)           \
         arrayParamOut(os, #member, member, size)
 
-#define UNSERIALIZE_ARRAY(member, size)        \
+#define UNSERIALIZE_ARRAY(member, size)         \
         arrayParamIn(cp, section, #member, member, size)
 
-#define SERIALIZE_OBJPTR(objptr)       paramOut(os, #objptr, (objptr)->name())
+#define SERIALIZE_OBJPTR(objptr)        paramOut(os, #objptr, (objptr)->name())
 
-#define UNSERIALIZE_OBJPTR(objptr)                     \
-  do {                                                 \
-    Serializable *sptr;                                \
-    objParamIn(cp, section, #objptr, sptr);            \
-    objptr = dynamic_cast<typeof(objptr)>(sptr);       \
+#define UNSERIALIZE_OBJPTR(objptr)                      \
+  do {                                                  \
+    SimObject *sptr;                                    \
+    objParamIn(cp, section, #objptr, sptr);             \
+    objptr = dynamic_cast<typeof(objptr)>(sptr);        \
   } while (0)
 
 /*
@@ -111,17 +121,16 @@ class Serializable
     void nameOut(std::ostream &os, const std::string &_name);
 
   public:
-    Serializable() {}
-    virtual ~Serializable() {}
+    Serializable();
+    virtual ~Serializable();
 
     // manditory virtual function, so objects must provide names
     virtual const std::string name() const = 0;
 
-    virtual void serialize(std::ostream &os) {}
-    virtual void unserialize(Checkpoint *cp, const std::string &section) {}
+    virtual void serialize(std::ostream &os);
+    virtual void unserialize(Checkpoint *cp, const std::string &section);
 
-    static Serializable *create(Checkpoint *cp,
-                                 const std::string &section);
+    static Serializable *create(Checkpoint *cp, const std::string &section);
 
     static int ckptCount;
     static int ckptMaxCount;
@@ -201,8 +210,8 @@ class SerializableClass
 // SerializableBuilder and SerializableClass objects
 //
 
-#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS)                     \
-SerializableClass the##OBJ_CLASS##Class(CLASS_NAME,                       \
+#define REGISTER_SERIALIZEABLE(CLASS_NAME, OBJ_CLASS)                      \
+SerializableClass the##OBJ_CLASS##Class(CLASS_NAME,                        \
                                          OBJ_CLASS::createForUnserialize);
 
 void
@@ -225,7 +234,7 @@ class Checkpoint
               std::string &value);
 
     bool findObj(const std::string &section, const std::string &entry,
-                 Serializable *&value);
+                 SimObject *&value);
 
     bool sectionExists(const std::string &section);