Serialization.h

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 //
00003 // $Id$
00004 //
00005 // Copyright 2008, 2009, 2010, 2011, 2012  Antonio Franchi and Paolo Stegagno    
00006 //
00007 // This file is part of MIP.
00008 //
00009 // MIP is free software: you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation, either version 3 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // MIP is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with MIP. If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Contact info: antonio.franchi@tuebingen.mpg.de stegagno@diag.uniroma1.it
00023 //
00024 // ----------------------------------------------------------------------------
00025 
00026 
00030 
00034 
00036 /* @{ */
00037 
00038 
00039 #ifndef __SERIALIZATION_H_
00040 #define __SERIALIZATION_H_
00041 
00042 #ifdef MIP_HOST_APPLE
00043 #include <applePatch.h>
00044 #endif
00045 
00046 #include <stdio.h>
00047 #include <math.h>
00048 #include <vector>
00049 #include <iostream>
00050 #include <string>
00051 #include <sstream>
00052 #include <boost/archive/text_oarchive.hpp>
00053 #include <boost/archive/text_iarchive.hpp>
00054 
00055 using namespace std;
00056 
00061 template <class T>
00062  class Serialization{
00063  private:
00064   T _obj;
00065   string _str;
00066  public:
00069   Serialization(T obj){
00070    _obj = obj;
00071    
00072    stringstream s;
00073    {
00074     boost::archive::text_oarchive oa(s);
00075     const T cObj = obj;
00076     oa << cObj;
00077    }
00078    
00079    _str = s.str();
00080   }
00081   
00084   Serialization(string str){
00085    _str   = str;
00086    
00087    stringstream s;
00088    s << str;
00089    
00090    {
00091     boost::archive::text_iarchive ia(s);
00092     ia >> _obj;
00093    }
00094   }
00095 
00098   T getObj(void){
00099    return _obj;
00100   }
00103   string getStr(void){
00104    return _str;
00105   }
00106 };
00107 
00108 
00109 
00110 
00111 #endif
00112 
00113 
00114 /* @} */
00115 

Generated on Mon Feb 20 07:01:07 2017 for MIP by  doxygen 1.5.6