From 76cd4393c08b83fa9006ee7bce1fb62457e053c1 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Tue, 7 Jul 2015 09:51:03 +0100 Subject: sim: Refactor the serialization base class Objects that are can be serialized are supposed to inherit from the Serializable class. This class is meant to provide a unified API for such objects. However, so far it has mainly been used by SimObjects due to some fundamental design limitations. This changeset redesigns to the serialization interface to make it more generic and hide the underlying checkpoint storage. Specifically: * Add a set of APIs to serialize into a subsection of the current object. Previously, objects that needed this functionality would use ad-hoc solutions using nameOut() and section name generation. In the new world, an object that implements the interface has the methods serializeSection() and unserializeSection() that serialize into a named /subsection/ of the current object. Calling serialize() serializes an object into the current section. * Move the name() method from Serializable to SimObject as it is no longer needed for serialization. The fully qualified section name is generated by the main serialization code on the fly as objects serialize sub-objects. * Add a scoped ScopedCheckpointSection helper class. Some objects need to serialize data structures, that are not deriving from Serializable, into subsections. Previously, this was done using nameOut() and manual section name generation. To simplify this, this changeset introduces a ScopedCheckpointSection() helper class. When this class is instantiated, it adds a new /subsection/ and subsequent serialization calls during the lifetime of this helper class happen inside this section (or a subsection in case of nested sections). * The serialize() call is now const which prevents accidental state manipulation during serialization. Objects that rely on modifying state can use the serializeOld() call instead. The default implementation simply calls serialize(). Note: The old-style calls need to be explicitly called using the serializeOld()/serializeSectionOld() style APIs. These are used by default when serializing SimObjects. * Both the input and output checkpoints now use their own named types. This hides underlying checkpoint implementation from objects that need checkpointing and makes it easier to change the underlying checkpoint storage code. --- src/python/swig/core.i | 4 ++-- src/python/swig/pyobject.cc | 4 ++-- src/python/swig/pyobject.hh | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/python/swig') diff --git a/src/python/swig/core.i b/src/python/swig/core.i index ed520e17a..862c0e37e 100644 --- a/src/python/swig/core.i +++ b/src/python/swig/core.i @@ -86,8 +86,8 @@ Tick curTick(); class Checkpoint; void serializeAll(const std::string &cpt_dir); -Checkpoint *getCheckpoint(const std::string &cpt_dir); -void unserializeGlobals(Checkpoint *cp); +CheckpointIn *getCheckpoint(const std::string &cpt_dir); +void unserializeGlobals(CheckpointIn &cp); bool want_warn, warn_verbose; bool want_info, info_verbose; diff --git a/src/python/swig/pyobject.cc b/src/python/swig/pyobject.cc index 08b9ee69f..f90e456e2 100644 --- a/src/python/swig/pyobject.cc +++ b/src/python/swig/pyobject.cc @@ -192,8 +192,8 @@ PythonSimObjectResolver::resolveSimObject(const string &name) return obj; } -Checkpoint * +CheckpointIn * getCheckpoint(const std::string &cpt_dir) { - return new Checkpoint(cpt_dir, pythonSimObjectResolver); + return new CheckpointIn(cpt_dir, pythonSimObjectResolver); } diff --git a/src/python/swig/pyobject.hh b/src/python/swig/pyobject.hh index a4f06555e..ea2948826 100644 --- a/src/python/swig/pyobject.hh +++ b/src/python/swig/pyobject.hh @@ -58,11 +58,11 @@ serializeAll(const std::string &cpt_dir) Serializable::serializeAll(cpt_dir); } -Checkpoint * +CheckpointIn * getCheckpoint(const std::string &cpt_dir); inline void -unserializeGlobals(Checkpoint *cp) +unserializeGlobals(CheckpointIn &cp) { Serializable::unserializeGlobals(cp); } -- cgit v1.2.3