serialization.hpp
Go to the documentation of this file.
1 #ifndef JULIAN_SERIALIZATION_HPP
2 #define JULIAN_SERIALIZATION_HPP
3 
4 #include <boost/archive/binary_oarchive.hpp>
5 #include <boost/archive/binary_iarchive.hpp>
6 #include <boost/archive/text_oarchive.hpp>
7 #include <boost/archive/text_iarchive.hpp>
8 #include <boost/archive/xml_oarchive.hpp>
9 #include <boost/archive/xml_iarchive.hpp>
10 #include <boost/serialization/utility.hpp>
11 #include <boost/serialization/map.hpp>
12 #include <boost/assert.hpp>
13 
16 
28 template<class T>
29 void serializeText(T object,std::string file) {
30  std::ofstream ofs(file);
31  boost::archive::text_oarchive oa(ofs);
32  oa << BOOST_SERIALIZATION_NVP(object);
33 }
34 
41 template<class T>
42 void serializeBinary(T object,std::string file) {
43  std::ofstream ofs(file);
44  boost::archive::binary_oarchive oa(ofs);
45  oa << BOOST_SERIALIZATION_NVP(object);
46 }
47 
54 template<class T>
55 void serializeXML(T object,std::string file) {
56  std::ofstream ofs(file);
57  boost::archive::xml_oarchive oa(ofs);
58  oa << BOOST_SERIALIZATION_NVP(object);
59 }
60 
61 
68 template<class T>
69 T deserializeText(std::string file) {
70  T obj;
71  std::ifstream ifs(file);
72  BOOST_ASSERT_MSG(ifs.good(),"file does not exists");
73  boost::archive::text_iarchive ia(ifs);
74  ia >> BOOST_SERIALIZATION_NVP(obj);
75 
76  return obj;
77 }
78 
85 template<class T>
86 T deserializeBinary(std::string file) {
87  T obj;
88  std::ifstream ifs(file);
89  BOOST_ASSERT_MSG(ifs.good(),"file does not exists");
90  boost::archive::binary_iarchive ia(ifs);
91  ia >> BOOST_SERIALIZATION_NVP(obj);
92 
93  return obj;
94 }
95 
102 template<class T>
103 T deserializeXML(std::string file) {
104  T obj;
105  std::ifstream ifs(file);
106  BOOST_ASSERT_MSG(ifs.good(),"file does not exists");
107  boost::archive::xml_iarchive ia(ifs);
108  ia >> BOOST_SERIALIZATION_NVP(obj);
109 
110  return obj;
111 }
112 
113 namespace boost {
114  namespace serialization {
117  template<class Archive, class T>
118  inline void save(Archive & ar,
119  const julian::SmartPointer< T > &t,
120  const unsigned int ){
121  const T * const tx = t->clone();
122  ar << BOOST_SERIALIZATION_NVP(tx);
123  }
126  template<class Archive, class T>
127  inline void load( Archive & ar,
129  const unsigned int ) {
130  T *pTarget;
131  ar >> BOOST_SERIALIZATION_NVP(pTarget);
132  t = *pTarget;
133  }
136  template<class Archive, class T>
137  inline void serialize(Archive & ar,
139  const unsigned int file_version ){
140  boost::serialization::split_free(ar, t, file_version);
141  }
142  } // namespace serialization
143 } // namespace boost
144 
145 #endif
146 
Contains headers of all files with definitions of classes gathered in interest rate module...
Template of deep-coping smart pointer.
Definition: smartPointer.hpp:14
void load(Archive &ar, julian::SmartPointer< T > &t, const unsigned int)
Definition: serialization.hpp:127
void serializeBinary(T object, std::string file)
Serialize object to binary file.
Definition: serialization.hpp:42
T deserializeText(std::string file)
Deserializes object from text file.
Definition: serialization.hpp:69
void save(Archive &ar, const julian::SmartPointer< T > &t, const unsigned int)
Definition: serialization.hpp:118
void serializeText(T object, std::string file)
Serialize object to text file.
Definition: serialization.hpp:29
void serializeXML(T object, std::string file)
Serialize object to xml file.
Definition: serialization.hpp:55
Definition: serialization.hpp:113
T deserializeXML(std::string file)
Deserializes object from xml file.
Definition: serialization.hpp:103
T deserializeBinary(std::string file)
Deserializes object from binary file.
Definition: serialization.hpp:86
Financial instruments module.