Serialization.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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