ISerializable.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief ISerializable interface.
5  *
6  *
7  *
8  * \author T.Voss, T. Glasmachers, O.Krause
9  * \date 2010-2011
10  *
11  *
12  * \par Copyright 1995-2017 Shark Development Team
13  *
14  * <BR><HR>
15  * This file is part of Shark.
16  * <http://shark-ml.org/>
17  *
18  * Shark is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Lesser General Public License as published
20  * by the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * Shark is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU Lesser General Public License for more details.
27  *
28  * You should have received a copy of the GNU Lesser General Public License
29  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
30  *
31  */
32 #ifndef SHARK_CORE_ISERIALIZABLE_H
33 #define SHARK_CORE_ISERIALIZABLE_H
34 
35 #include <boost/version.hpp>
36 #include <boost/serialization/split_member.hpp>
37 #include <boost/serialization/tracking.hpp>
38 
39 #if (BOOST_VERSION >= 105600) && (BOOST_VERSION <= 105800)
40  #define USE_SERIALIZATION_WORKAROUND
41 #endif
42 
43 #ifdef USE_SERIALIZATION_WORKAROUND
44  #include <boost/archive/text_iarchive.hpp>
45  #include <boost/archive/text_oarchive.hpp>
46 #else
47  #include <boost/archive/polymorphic_iarchive.hpp>
48  #include <boost/archive/polymorphic_oarchive.hpp>
49  #include <boost/archive/polymorphic_text_iarchive.hpp>
50  #include <boost/archive/polymorphic_text_oarchive.hpp>
51 #endif
52 namespace shark {
53 
54 
55 
56 #ifdef USE_SERIALIZATION_WORKAROUND
57  //broken workaround for broken boost version
58  /**
59  * \brief Type of an archive to read from.
60  */
61  typedef boost::archive::text_iarchive InArchive;
62  typedef boost::archive::text_iarchive TextInArchive;
63 
64 
65  /**
66  * \brief Type of an archive to write to.
67  */
68  typedef boost::archive::text_oarchive OutArchive;
69  typedef boost::archive::text_oarchive TextOutArchive;
70 #else
71  /**
72  * \brief Type of an archive to read from.
73  */
74  typedef boost::archive::polymorphic_iarchive InArchive;
75  typedef boost::archive::polymorphic_text_iarchive TextInArchive;
76 
77  /**
78  * \brief Type of an archive to write to.
79  */
80  typedef boost::archive::polymorphic_oarchive OutArchive;
81  typedef boost::archive::polymorphic_text_oarchive TextOutArchive;
82 #endif
83  /**
84  * \brief Abstracts serializing functionality.
85  *
86  * In order to integrate alien serialization libraries
87  * with the components based on this interface, the classes
88  * boost::archive::polymorphic_iarchive and boost::archive::polymorphic_oarchive
89  * need to be implemented in terms of alien serialization library.
90  */
91  class ISerializable {
92  public:
93  /**
94  * \brief Virtual d'tor.
95  */
96  virtual ~ISerializable() {}
97 
98  /**
99  * \brief Read the component from the supplied archive.
100  * \param [in,out] archive The archive to read from.
101  */
102  virtual void read( InArchive & archive )
103  { }
104 
105  /**
106  * \brief Write the component to the supplied archive.
107  * \param [in,out] archive The archive to write to.
108  */
109  virtual void write( OutArchive & archive ) const
110  { }
111 
112  /**
113  * \brief Versioned loading of components, calls read(...).
114  */
115  void load(InArchive & archive,unsigned int version)
116  {
117  (void) version;
118  read(archive);
119  }
120 
121  /**
122  * \brief Versioned storing of components, calls write(...).
123  */
124  void save(OutArchive & archive,unsigned int version)const
125  {
126  (void) version;
127  write(archive);
128  }
130  };
131 }
132 
133 #include <vector>
134 
135 namespace boost {
136 namespace serialization {
137 
138 template< typename T >
139 struct tracking_level< std::vector<T> > {
140  typedef mpl::integral_c_tag tag;
141  BOOST_STATIC_CONSTANT( int, value = track_always );
142 };
143 
144 }
145 }
146 
147 #endif // SHARK_CORE_ISERIALIZABLE_H