From 2a0239ea0f0cdbce0a51b405806cb2c7b042ed4e Mon Sep 17 00:00:00 2001
From: Thomas Witkowski <thomas.witkowski@gmx.de>
Date: Wed, 30 Sep 2009 10:11:09 +0000
Subject: [PATCH] Code refactoring.

---
 AMDiS/src/ElementRegion_ED.h    |   5 +-
 AMDiS/src/LeafData.cc           | 150 ++++++++++++++++++++++++++++++--
 AMDiS/src/LeafData.h            | 147 ++++---------------------------
 AMDiS/src/Parameters.cc         |  47 +++++++++-
 AMDiS/src/Parameters.h          | 127 ++++++++-------------------
 AMDiS/src/Serializer.h          |   1 -
 AMDiS/src/SolutionDataStorage.h |  28 +++---
 AMDiS/src/SurfaceRegion_ED.h    |   9 +-
 AMDiS/src/SystemVector.h        |   5 +-
 9 files changed, 267 insertions(+), 252 deletions(-)

diff --git a/AMDiS/src/ElementRegion_ED.h b/AMDiS/src/ElementRegion_ED.h
index 60b6b71a..b6ad52fe 100644
--- a/AMDiS/src/ElementRegion_ED.h
+++ b/AMDiS/src/ElementRegion_ED.h
@@ -24,6 +24,7 @@
 
 #include "ElementData.h"
 #include "FixVec.h"
+#include "Serializer.h"
 
 namespace AMDiS {
 
@@ -92,13 +93,13 @@ namespace AMDiS {
     void serialize(std::ostream& out) 
     {
       ElementData::serialize(out);
-      out.write(reinterpret_cast<const char*>(&region), sizeof(int));
+      SerUtil::serialize(out, region);
     }
 
     void deserialize(std::istream& in) 
     {
       ElementData::deserialize(in);
-      in.read(reinterpret_cast<char*>(&region), sizeof(int));
+      SerUtil::deserialize(in, region);
     }
 
     inline void setRegion(int r) 
diff --git a/AMDiS/src/LeafData.cc b/AMDiS/src/LeafData.cc
index 0ffabbd9..3fd84e7a 100644
--- a/AMDiS/src/LeafData.cc
+++ b/AMDiS/src/LeafData.cc
@@ -1,6 +1,7 @@
 #include "LeafData.h"
 #include "Element.h"
 #include "Mesh.h"
+#include "Serializer.h"
 
 namespace AMDiS {
 
@@ -42,6 +43,18 @@ namespace AMDiS {
     ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent);
   }
 
+  void LeafDataEstimatable::serialize(std::ostream& out)
+  {
+    ElementData::serialize(out);
+    SerUtil::serialize(out, errorEstimate);
+  }
+
+  void LeafDataEstimatable::deserialize(std::istream& in)
+  {
+    ElementData::deserialize(in);
+    SerUtil::deserialize(in, errorEstimate);
+  }
+  
   bool LeafDataEstimatableVec::refineElementData(Element* parent, 
 						 Element* child1,
 						 Element* child2,
@@ -65,8 +78,35 @@ namespace AMDiS {
     TEST_EXIT_DBG(test)("couldn't delete LeafDataEstimatableVec at otherChild");
     parent->setElementData(new LeafDataEstimatableVec(parent->getElementData()));
     ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent);
-   }
+  }
 
+  void LeafDataEstimatableVec::serialize(std::ostream& out) 
+  {
+    ElementData::serialize(out);
+    unsigned int size = errorEstimate.size();
+    SerUtil::serialize(out, size);
+    
+    for (std::map<int, double>::iterator it = errorEstimate.begin(); 
+	 it != errorEstimate.end(); ++it) {
+      SerUtil::serialize(out, it->first);
+      SerUtil::serialize(out, it->second);
+    }
+  }
+  
+  void LeafDataEstimatableVec::deserialize(std::istream& in) 
+  {
+    ElementData::deserialize(in);
+    unsigned size;
+    SerUtil::deserialize(in, size);
+    for (unsigned int i = 0; i < size; i++) {
+      int index;
+      double estimate;
+      SerUtil::deserialize(in, index);
+      SerUtil::deserialize(in, estimate);
+      errorEstimate[index] = estimate;
+    }
+  }
+  
   bool LeafDataCoarsenable::refineElementData(Element* parent, 
 					      Element* child1,
 					      Element* child2,
@@ -90,6 +130,18 @@ namespace AMDiS {
     ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent);
   }
 
+  void LeafDataCoarsenable::serialize(std::ostream& out) 
+  {
+    ElementData::serialize(out);
+    SerUtil::serialize(out, coarseningError);
+  }
+
+  void LeafDataCoarsenable::deserialize(std::istream& in) 
+  {
+    ElementData::deserialize(in);
+    SerUtil::deserialize(in, coarseningError);
+  }
+
   bool LeafDataCoarsenableVec::refineElementData(Element* parent, 
 						 Element* child1,
 						 Element* child2,
@@ -112,6 +164,33 @@ namespace AMDiS {
     ElementData::coarsenElementData(parent, thisChild, otherChild, elTypeParent);
   }
 
+  void LeafDataCoarsenableVec::serialize(std::ostream& out) 
+  {
+    ElementData::serialize(out);
+    unsigned int size = coarseningError.size();
+    SerUtil::serialize(out, size);
+    
+    for (std::map<int, double>::iterator it = coarseningError.begin(); 
+	 it != coarseningError.end(); ++it) {
+      SerUtil::serialize(out, it->first);
+      SerUtil::serialize(out, it->second);
+    }
+  }
+  
+  void LeafDataCoarsenableVec::deserialize(std::istream& in) 
+  {
+    ElementData::deserialize(in);
+    unsigned int size;
+    SerUtil::deserialize(in, size);
+    for (unsigned int i = 0; i < size; i++) {
+      int index;
+      double estimate;
+      SerUtil::deserialize(in, index);
+      SerUtil::deserialize(in, estimate);
+      coarseningError[index] = estimate;
+    }
+  }
+
   bool LeafDataPeriodic::refineElementData(Element* parent, 
 					   Element* child1,
 					   Element* child2,
@@ -176,6 +255,27 @@ namespace AMDiS {
     return false;
   }
 
+  void LeafDataPeriodic::serialize(std::ostream& out) 
+  {
+    ElementData::serialize(out);
+    unsigned int size = periodicInfoList.size();
+    SerUtil::serialize(out, size);      
+    for (std::list<PeriodicInfo>::iterator it = periodicInfoList.begin(); 
+	 it != periodicInfoList.end(); ++it)
+      it->serialize(out);
+  }
+  
+  void LeafDataPeriodic::deserialize(std::istream& in) 
+  {
+    ElementData::deserialize(in);
+    unsigned int size;
+    SerUtil::deserialize(in, size);
+    periodicInfoList.resize(size);
+    for (std::list<PeriodicInfo>::iterator it = periodicInfoList.begin(); 
+	 it != periodicInfoList.end(); ++it)
+      it->deserialize(in);
+  }
+  
   LeafDataPeriodic::PeriodicInfo::PeriodicInfo(const PeriodicInfo &rhs) 
   {
     periodicMode = rhs.periodicMode;
@@ -184,17 +284,14 @@ namespace AMDiS {
     if (rhs.periodicCoords) {
       int dim = rhs.periodicCoords->getSize() - 1;
       periodicCoords = new DimVec<WorldVector<double> >(dim, NO_INIT);
-      for (int i = 0; i < dim + 1; i++) {
+      for (int i = 0; i < dim + 1; i++)
 	(*periodicCoords)[i] = (*(rhs.periodicCoords))[i];
-      }   
     } else {
       periodicCoords = NULL;
     }
   }
-
-  LeafDataPeriodic::PeriodicInfo::PeriodicInfo(int mode,
-					       BoundaryType t,
-					       int side,
+  
+  LeafDataPeriodic::PeriodicInfo::PeriodicInfo(int mode, BoundaryType t, int side,
 					       const DimVec<WorldVector<double> > *coords)
     : periodicMode(mode),
       type(t),
@@ -204,9 +301,44 @@ namespace AMDiS {
     if (coords) {
       int dim = coords->getSize() - 1;
       periodicCoords = new DimVec<WorldVector<double> >(dim, NO_INIT);
-      for (int i = 0; i < dim + 1; i++) {
+      for (int i = 0; i < dim + 1; i++)
 	(*periodicCoords)[i] = (*coords)[i];
-      }
     }
   }
+
+  void LeafDataPeriodic::PeriodicInfo::serialize(std::ostream &out) 
+  {
+    SerUtil::serialize(out, periodicMode);
+    SerUtil::serialize(out, type);
+    SerUtil::serialize(out, elementSide);
+    if (periodicCoords) {
+      int size = periodicCoords->getSize();
+      SerUtil::serialize(out, size);
+      for (int i = 0; i < size; i++)
+	(*periodicCoords)[i].serialize(out);
+    } else {
+      int size = 0;
+      SerUtil::serialize(out, size);
+    }
+  }
+  
+  void LeafDataPeriodic::PeriodicInfo::deserialize(std::istream &in)
+  {
+    SerUtil::deserialize(in, periodicMode);
+    SerUtil::deserialize(in, type);
+    SerUtil::deserialize(in, elementSide);
+    
+    int size;
+    SerUtil::deserialize(in, size);
+    if (periodicCoords) 
+      delete periodicCoords;
+    if (size == 0) {
+      periodicCoords = NULL;
+    } else {
+      periodicCoords = new DimVec<WorldVector<double> >(size-1, NO_INIT);
+      for (int i = 0; i < size; i++) 
+	(*periodicCoords)[i].deserialize(in);
+    }
+  }
+
 }
diff --git a/AMDiS/src/LeafData.h b/AMDiS/src/LeafData.h
index ded8a065..84127837 100644
--- a/AMDiS/src/LeafData.h
+++ b/AMDiS/src/LeafData.h
@@ -29,7 +29,6 @@
 #include "ElementData.h"
 #include "Boundary.h"
 
-
 namespace AMDiS {
 
   class LeafDataEstimatableInterface
@@ -119,17 +118,9 @@ namespace AMDiS {
       return ESTIMATABLE; 
     }
 
-    void serialize(std::ostream& out) 
-    {
-      ElementData::serialize(out);
-      out.write(reinterpret_cast<const char*>(&errorEstimate), sizeof(double));
-    }
+    void serialize(std::ostream& out);
 
-    void deserialize(std::istream& in) 
-    {
-      ElementData::deserialize(in);
-      in.read(reinterpret_cast<char*>(&errorEstimate), sizeof(double));
-    }
+    void deserialize(std::istream& in); 
 
   private:
     double errorEstimate;
@@ -199,31 +190,9 @@ namespace AMDiS {
       return newObj;
     }
 
-    void serialize(std::ostream& out) 
-    {
-      ElementData::serialize(out);
-      unsigned int size = errorEstimate.size();
-      out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int));
-      std::map<int, double>::iterator it;
-      for (it = errorEstimate.begin(); it != errorEstimate.end(); ++it) {
-	out.write(reinterpret_cast<const char*>(&(it->first)), sizeof(int));
-	out.write(reinterpret_cast<const char*>(&(it->second)), sizeof(double));
-      }
-    }
+    void serialize(std::ostream& out);
 
-    void deserialize(std::istream& in) 
-    {
-      ElementData::deserialize(in);
-      unsigned size;
-      in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int));
-      for (unsigned int i = 0; i < size; i++) {
-	int index;
-	double estimate;
-	in.read(reinterpret_cast<char*>(&index), sizeof(int));
-	in.read(reinterpret_cast<char*>(&estimate), sizeof(double));
-	errorEstimate[index] = estimate;
-      }
-    }
+    void deserialize(std::istream& in);
 
     std::string getTypeName() const 
     {
@@ -293,7 +262,8 @@ namespace AMDiS {
 			    int elTypeParent);
 
     /// Implements ElementData::clone().
-    inline ElementData *clone() const {
+    inline ElementData *clone() const 
+    {
       // create new estimatable leaf data
       LeafDataCoarsenable *newObj = new LeafDataCoarsenable(NULL);
 
@@ -316,23 +286,17 @@ namespace AMDiS {
       return coarseningError; 
     }
 
-    void serialize(std::ostream& out) 
-    {
-      ElementData::serialize(out);
-      out.write(reinterpret_cast<const char*>(&coarseningError), sizeof(double));
-    }
+    void serialize(std::ostream& out);
 
-    void deserialize(std::istream& in) 
-    {
-      ElementData::deserialize(in);
-      in.read(reinterpret_cast<char*>(&coarseningError), sizeof(double));
-    }
+    void deserialize(std::istream& in);
 
-    std::string getTypeName() const {
+    std::string getTypeName() const 
+    {
       return "LeafDataCoarsenable";
     }
   
-    inline const int getTypeID() const { 
+    inline const int getTypeID() const 
+    { 
       return COARSENABLE; 
     }
 
@@ -407,31 +371,9 @@ namespace AMDiS {
       return coarseningError[index]; 
     }
 
-    void serialize(std::ostream& out) 
-    {
-      ElementData::serialize(out);
-      unsigned int size = coarseningError.size();
-      out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int));
-      std::map<int, double>::iterator it;
-      for (it = coarseningError.begin(); it != coarseningError.end(); ++it) {
-	out.write(reinterpret_cast<const char*>(&(it->first)), sizeof(int));
-	out.write(reinterpret_cast<const char*>(&(it->second)), sizeof(double));
-      }
-    }
+    void serialize(std::ostream& out);
 
-    void deserialize(std::istream& in) 
-    {
-      ElementData::deserialize(in);
-      unsigned int size;
-      in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int));
-      for (unsigned int i = 0; i < size; i++) {
-	int index;
-	double estimate;
-	in.read(reinterpret_cast<char*>(&index), sizeof(int));
-	in.read(reinterpret_cast<char*>(&estimate), sizeof(double));
-	coarseningError[index] = estimate;
-      }
-    }
+    void deserialize(std::istream& in);
 
     std::string getTypeName() const 
     {
@@ -489,41 +431,9 @@ namespace AMDiS {
 
       PeriodicInfo(const PeriodicInfo &rhs);
 
-      void serialize(std::ostream &out) 
-      {
-	out.write(reinterpret_cast<const char*>(&periodicMode), sizeof(int));
-	out.write(reinterpret_cast<const char*>(&type), sizeof(BoundaryType));
-	out.write(reinterpret_cast<const char*>(&elementSide), sizeof(int));
-	if (periodicCoords) {
-	  int size = periodicCoords->getSize();
-	  out.write(reinterpret_cast<const char*>(&size), sizeof(int));
-	  for (int i = 0; i < size; i++) {
-	    (*periodicCoords)[i].serialize(out);
-	  }
-	} else {
-	  int size = 0;
-	  out.write(reinterpret_cast<const char*>(&size), sizeof(int));
-	}
-      }
-
-      void deserialize(std::istream &in)
-      {
-	in.read(reinterpret_cast<char*>(&periodicMode), sizeof(int));
-	in.read(reinterpret_cast<char*>(&type), sizeof(BoundaryType));
-	in.read(reinterpret_cast<char*>(&elementSide), sizeof(int));
+      void serialize(std::ostream &out);
 
-	int size;
-	in.read(reinterpret_cast<char*>(&size), sizeof(int));
-	if (periodicCoords) 
-	  delete periodicCoords;
-	if (size == 0) {
-	  periodicCoords = NULL;
-	} else {
-	  periodicCoords = new DimVec<WorldVector<double> >(size-1, NO_INIT);
-	  for (int i = 0; i < size; i++) 
-	    (*periodicCoords)[i].deserialize(in);
-	}
-      }
+      void deserialize(std::istream &in);
 
       int periodicMode;
 
@@ -565,26 +475,9 @@ namespace AMDiS {
       return periodicInfoList;
     }
 
-    void serialize(std::ostream& out) 
-    {
-      ElementData::serialize(out);
-      unsigned int size = periodicInfoList.size();
-      out.write(reinterpret_cast<const char*>(&size), sizeof(unsigned int));
-      std::list<PeriodicInfo>::iterator it;
-      for (it = periodicInfoList.begin(); it != periodicInfoList.end(); ++it)
-	it->serialize(out);
-    }
+    void serialize(std::ostream& out);
 
-    void deserialize(std::istream& in) 
-    {
-      ElementData::deserialize(in);
-      unsigned int size;
-      in.read(reinterpret_cast<char*>(&size), sizeof(unsigned int));
-      periodicInfoList.resize(size);
-      std::list<PeriodicInfo>::iterator it;
-      for (it = periodicInfoList.begin(); it != periodicInfoList.end(); ++it)
-	it->deserialize(in);
-    }
+    void deserialize(std::istream& in);
 
     std::string getTypeName() const
     {
@@ -596,9 +489,7 @@ namespace AMDiS {
       return PERIODIC; 
     }
 
-    bool refineElementData(Element* parent, 
-			   Element* child1,
-			   Element* child2,
+    bool refineElementData(Element* parent, Element* child1, Element* child2, 
 			   int elType);
 
   private:
diff --git a/AMDiS/src/Parameters.cc b/AMDiS/src/Parameters.cc
index 3c654269..c8cdcb6f 100644
--- a/AMDiS/src/Parameters.cc
+++ b/AMDiS/src/Parameters.cc
@@ -1,4 +1,3 @@
-#include "Parameters.h"
 #include <fstream>
 #include <sstream>
 #include <algorithm>
@@ -8,6 +7,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include "Parameters.h"
+#include "Serializer.h"
 
 namespace AMDiS {
 
@@ -752,8 +753,50 @@ namespace AMDiS {
       delete singlett;
   }
 
-  int Parameters::param::operator==(const param& aParam)const{ 
+  void Parameters::serialize(std::ostream &out)
+  {
+    SerUtil::serialize(out, paramInfo);
+    SerUtil::serialize(out, msgInfo);
+    SerUtil::serialize(out, msgWait);
+    int size = static_cast<int>(allParam.size());
+    SerUtil::serialize(out, size);
+    for (int i = 0; i < size; i++)
+      allParam[i].serialize(out);
+  }
+
+  void Parameters::deserialize(std::istream &in)
+  {
+    SerUtil::deserialize(in, paramInfo);
+    SerUtil::deserialize(in, msgInfo);
+    SerUtil::deserialize(in, msgWait);
+    int size;
+    SerUtil::deserialize(in, size);
+    allParam.resize(size);
+    for (int i = 0; i < size; i++)
+      allParam[i].deserialize(in);
+  }
+
+  int Parameters::param::operator==(const param& aParam) const
+  { 
     return key == aParam.key;
   }
 
+  void Parameters::param::serialize(std::ostream &out)
+  {
+    out << key << std::endl;
+    out << parameters << std::endl;
+    out << filename << std::endl;
+    out << funcName << std::endl;
+    SerUtil::serialize(out, lineNo);
+  }
+  
+  void Parameters::param::deserialize(std::istream &in)
+  {
+    in >> key; in.get();
+    in >> parameters; in.get();
+    in >> filename; in.get();
+    in >> funcName; in.get();
+    SerUtil::deserialize(in, lineNo);
+  }
+
 }
diff --git a/AMDiS/src/Parameters.h b/AMDiS/src/Parameters.h
index d7e691f8..4eb0ed27 100644
--- a/AMDiS/src/Parameters.h
+++ b/AMDiS/src/Parameters.h
@@ -31,10 +31,6 @@
 
 namespace AMDiS {
 
-  // ============================================================================
-  // ===== class Parameters =====================================================
-  // ============================================================================
-
   /** \ingroup Common
    * \brief
    * Many procedures need parameters, for example the maximal number of 
@@ -71,9 +67,7 @@ namespace AMDiS {
      * argument flags, replacing macros by their definitions in the parameter 
      * file and including files specified by \#include"...".
      */
-    static void init(int         print, 
-		     std::string filename, 
-		     const char *flags=NULL);
+    static void init(int print, std::string filename, const char *flags = NULL);
 
     /** \brief
      * Reads all arguments which are provided to the program. The init filenames
@@ -182,37 +176,24 @@ namespace AMDiS {
 				  const char         *format, 
 				  ...);  
 
-    /** \brief
-     * Like getGlobalParameter(flag, key, "%s", param->c_str()).
-     */
-    static int getGlobalParameter(int                 flag, 
-				  const std::string&  key, 
-				  std::string        *param);
+    /// Like getGlobalParameter(flag, key, "%s", param->c_str()).
+    static int getGlobalParameter(int flag, const std::string& key, std::string *param);
 
-    /** \brief
-     * Prints all defined parameters to the message stream
-     */
+    /// Prints all defined parameters to the message stream
     static void printParameters();
 
-    /** \brief
-     * Used by macro \ref GET_PARAMETER to generate infos about the calling
-     * function.
-     */
-    static int initFuncName(const char *, 
-			    const char *, 
-			    int call_line);
+    /// Used by macro \ref GET_PARAMETER to generate infos about the calling function.
+    static int initFuncName(const char *, const char *, int call_line);
 
-    /** \brief
-     * Returns specified info level
-     */
-    static int getMsgInfo() { 
+    /// Returns specified info level
+    static int getMsgInfo() 
+    { 
       return (singlett) ? singlett->msgInfo : 0; 
     }
 
-    /** \brief
-     * Returns specified wait value
-     */
-    static int getMsgWait() { 
+    /// Returns specified wait value
+    static int getMsgWait() 
+    { 
       return (singlett) ? singlett->msgWait : 0; 
     }
 
@@ -224,43 +205,24 @@ namespace AMDiS {
      */
     static void save(const std::string file, int info);
 
-    /** \brief
-     * Checks whether parameters are initialized. if not, call init()
-     */
-    static bool initialized() { 
+    /// Checks whether parameters are initialized. if not, call init()
+    static bool initialized() 
+    { 
       return (singlett != NULL); 
     }
 
-    static Parameters *getSingleton() { 
+    static Parameters *getSingleton() 
+    { 
       return singlett; 
     }
 
     static void clear();
 
-    // ===== Serializable implementation =====
+    /// Writes parameters to an output stream.
+    void serialize(std::ostream &out); 
 
-    void serialize(std::ostream &out) {
-      out.write(reinterpret_cast<const char*>(&paramInfo), sizeof(int));
-      out.write(reinterpret_cast<const char*>(&msgInfo), sizeof(int));
-      out.write(reinterpret_cast<const char*>(&msgWait), sizeof(int));
-      int i, size = static_cast<int>(allParam.size());
-      out.write(reinterpret_cast<const char*>(&size), sizeof(int));
-      for(i = 0; i < size; i++) {
-	allParam[i].serialize(out);
-      }
-    }
-
-    void deserialize(std::istream &in) {
-      in.read(reinterpret_cast<char*>(&paramInfo), sizeof(int));
-      in.read(reinterpret_cast<char*>(&msgInfo), sizeof(int));
-      in.read(reinterpret_cast<char*>(&msgWait), sizeof(int));
-      int i, size;
-      in.read(reinterpret_cast<char*>(&size), sizeof(int));
-      allParam.resize(size);
-      for(i = 0; i < size; i++) {
-	allParam[i].deserialize(in);
-      }
-    }
+    /// Reads parameters from an input stream.
+    void deserialize(std::istream &in); 
 
   private:
     static Parameters * singlett;
@@ -271,10 +233,7 @@ namespace AMDiS {
 
     static int param_call_line;
 
-
-    /** \brief
-     * Used internally.
-     */
+    /// Used internally.
     class param : public Serializable
     {
     public:
@@ -300,27 +259,16 @@ namespace AMDiS {
 
       int operator==(const class param& aParam) const;
 
-      int operator!=(const class param& aParam) const {
-	return !(aParam==*this);
+      int operator!=(const class param& aParam) const 
+      {
+	return !(aParam == *this);
       }
 
-      // ===== Serializable implementation =====
-
-      void serialize(std::ostream &out) {
-	out << key << std::endl;
-	out << parameters << std::endl;
-	out << filename << std::endl;
-	out << funcName << std::endl;
-	out.write(reinterpret_cast<const char*>(&lineNo), sizeof(int));
-      }
+      /// Writes one parameter to an output stream.
+      void serialize(std::ostream &out); 
 
-      void deserialize(std::istream &in) {
-	in >> key; in.get();
-	in >> parameters; in.get();
-	in >> filename; in.get();
-	in >> funcName; in.get();
-	in.read(reinterpret_cast<char*>(&lineNo), sizeof(int));
-      }
+      /// Reads one parameter from an inputput stream.
+      void deserialize(std::istream &in); 
 
     public:
       std::string key;
@@ -334,29 +282,30 @@ namespace AMDiS {
 
     std::string buffer;
 
-    inline bool isBlankChar(const char s) {
+    inline bool isBlankChar(const char s) 
+    {
       return (s == ' ' || s == '\t' || s == '\f' || s == '\r'); 
     }
 
     const char *getNextWord(std::string *s) const;
 
-    void read(const std::string& filename,const std::string& maxKey="");
+    void read(const std::string& filename,const std::string& maxKey = "");
 
     const std::string& getActFile(const std::string& filename);
 
     const std::string getKey(const std::string& s, 
-			       int nLine, 
-			       const std::string& filename);
+			     int nLine, 
+			     const std::string& filename);
 
     const std::string getPar(const std::string& key, 
-			       const std::string& s, 
-			       int *nl, 
-			       const std::string& fn);
+			     const std::string& s, 
+			     int *nl, 
+			     const std::string& fn);
 
     void addParam(const std::string& key, 
 		  const std::string& parameter,
 		  const std::string& actfile, 
-		  int  nLine, 
+		  int nLine, 
 		  const std::string& fname);
 
     Parameters() 
diff --git a/AMDiS/src/Serializer.h b/AMDiS/src/Serializer.h
index 5c54b9af..b5f31204 100644
--- a/AMDiS/src/Serializer.h
+++ b/AMDiS/src/Serializer.h
@@ -28,7 +28,6 @@
 #include "FileWriter.h"
 #include "Parameters.h"
 #include "AdaptInfo.h"
-#include "ProblemStatBase.h"
 
 namespace AMDiS {
 
diff --git a/AMDiS/src/SolutionDataStorage.h b/AMDiS/src/SolutionDataStorage.h
index d3c8d1bd..5c0f663b 100644
--- a/AMDiS/src/SolutionDataStorage.h
+++ b/AMDiS/src/SolutionDataStorage.h
@@ -127,7 +127,7 @@ namespace AMDiS {
       out << fe->getMesh()->getName() << "\n";
 
       int dim = fe->getMesh()->getDim();
-      out.write(reinterpret_cast<const char*>(&dim), sizeof(int));
+      SerUtil::serialize(out, dim);
 
       fe->getMesh()->serialize(out);
 
@@ -135,8 +135,8 @@ namespace AMDiS {
       dim = fe->getBasisFcts()->getDim();
       int degree = fe->getBasisFcts()->getDegree();
       out << ((fe->getName() != "") ? fe->getName() : "noname") << "\n";
-      out.write(reinterpret_cast<const char*>(&dim), sizeof(int));
-      out.write(reinterpret_cast<const char*>(&degree), sizeof(int));
+      SerUtil::serialize(out, dim);
+      SerUtil::serialize(out, degree);
     }
 
     /** \brief 
@@ -149,7 +149,7 @@ namespace AMDiS {
     void serializeFeSpace(std::ofstream &out, std::vector<FiniteElemSpace*>& fe)
     {
       int size = fe.size();     
-      out.write(reinterpret_cast<const char*>(&size), sizeof(int));
+      SerUtil::serialize(out, size);
 
       for (int i = 0; i < size; i++) {
 	// Check, if the pointer points to an fe space serialized before.
@@ -161,7 +161,7 @@ namespace AMDiS {
 	  }
 	}
 
-        out.write(reinterpret_cast<const char*>(&found), sizeof(int));
+	SerUtil::serialize(out, found);
 	// Only in case this fe space was not serialized before, write it to the file.
 	if (found == -1)
 	  serializeFeSpace(out, fe[i]);
@@ -176,15 +176,14 @@ namespace AMDiS {
 
       in >> name;
       in.get();
-      in.read(reinterpret_cast<char*>(&dim), sizeof(int));
+      SerUtil::deserialize(in, dim);
       Mesh *mesh = new Mesh(name, dim);
       mesh->deserialize(in);
 
       in >> name;
       in.get();
-      in.read(reinterpret_cast<char*>(&dim), sizeof(int));
-      in.read(reinterpret_cast<char*>(&degree), sizeof(int));
-
+      SerUtil::deserialize(in, dim);
+      SerUtil::deserialize(in, degree);
       *fe = FiniteElemSpace::provideFESpace(NULL,
 					    Lagrange::getLagrange(dim, degree),
 					    mesh,
@@ -195,17 +194,16 @@ namespace AMDiS {
     void deserializeFeSpace(std::ifstream &in, std::vector<FiniteElemSpace*>& fe)
     {
       int size;
-      in.read(reinterpret_cast<char*>(&size), sizeof(int));
+      SerUtil::deserialize(in, size);
 
       fe.resize(size);
       for (int i = 0; i < size; i++) {
 	int found;
-	in.read(reinterpret_cast<char*>(&found), sizeof(int));
-	if (found == -1) {
+	SerUtil::deserialize(in, found);
+	if (found == -1)
 	  deserializeFeSpace(in, &(fe[i]));
-	} else {
-	  fe[i] = fe[found];
-	}
+	else
+	  fe[i] = fe[found];	
       }
     }
 
diff --git a/AMDiS/src/SurfaceRegion_ED.h b/AMDiS/src/SurfaceRegion_ED.h
index c861ad29..7d262e33 100644
--- a/AMDiS/src/SurfaceRegion_ED.h
+++ b/AMDiS/src/SurfaceRegion_ED.h
@@ -24,6 +24,7 @@
 
 #include "ElementData.h"
 #include "FixVec.h"
+#include "Serializer.h"
 
 namespace AMDiS {
 
@@ -103,15 +104,15 @@ namespace AMDiS {
     void serialize(std::ostream& out) 
     {
       ElementData::serialize(out);
-      out.write(reinterpret_cast<const char*>(&side), sizeof(int));
-      out.write(reinterpret_cast<const char*>(&region), sizeof(int));
+      SerUtil::serialize(out, side);
+      SerUtil::serialize(out, region);
     }
 
     void deserialize(std::istream& in) 
     {
       ElementData::deserialize(in);
-      in.read(reinterpret_cast<char*>(&side), sizeof(int));
-      in.read(reinterpret_cast<char*>(&region), sizeof(int));
+      SerUtil::deserialize(in, side);
+      SerUtil::deserialize(in, region);
     }
 
     inline void setSide(int s) 
diff --git a/AMDiS/src/SystemVector.h b/AMDiS/src/SystemVector.h
index afb69325..383a3bd8 100644
--- a/AMDiS/src/SystemVector.h
+++ b/AMDiS/src/SystemVector.h
@@ -27,6 +27,7 @@
 #include "CreatorInterface.h"
 #include "Serializable.h"
 #include "OpenMP.h"
+#include "Serializer.h"
 
 namespace AMDiS {
 
@@ -242,7 +243,7 @@ namespace AMDiS {
     void serialize(std::ostream &out) 
     {
       int size = vectors.getSize();
-      out.write(reinterpret_cast<const char*>(&size), sizeof(int));
+      SerUtil::serialize(out, size);
       for (int i = 0; i < size; i++)
 	vectors[i]->serialize(out);
     }
@@ -250,7 +251,7 @@ namespace AMDiS {
     void deserialize(std::istream &in) 
     {
       int size, oldSize = vectors.getSize();
-      in.read(reinterpret_cast<char*>(&size), sizeof(int));
+      SerUtil::deserialize(in, size);
       vectors.resize(size);
       for (int i = oldSize; i < size; i++)
 	vectors[i] = new DOFVector<double>(feSpace[i], "");
-- 
GitLab