8 #ifndef NUKLEI_BOOST_SERIALIZATION_H
9 #define NUKLEI_BOOST_SERIALIZATION_H
11 #include <boost/config.hpp>
13 #ifdef NUKLEI_USE_CEREAL
14 # define NUKLEI_SERIALIZATION_IMPL 1
16 # define NUKLEI_SERIALIZATION_IMPL 0
23 #if NUKLEI_SERIALIZATION_IMPL == 0 // Boost Serialization
25 #include <boost/archive/archive_exception.hpp>
27 #include <boost/archive/text_iarchive.hpp>
28 #include <boost/archive/text_oarchive.hpp>
29 #include <boost/archive/xml_iarchive.hpp>
30 #include <boost/archive/xml_oarchive.hpp>
31 #include <boost/archive/binary_iarchive.hpp>
32 #include <boost/archive/binary_oarchive.hpp>
34 #include <boost/serialization/nvp.hpp>
35 #include <boost/serialization/utility.hpp>
36 #include <boost/serialization/vector.hpp>
37 #include <boost/serialization/list.hpp>
38 #include <boost/serialization/map.hpp>
39 #include <boost/serialization/shared_ptr.hpp>
40 #include <boost/serialization/string.hpp>
41 #include <boost/serialization/version.hpp>
42 #include <boost/serialization/optional.hpp>
44 #include <boost/serialization/split_free.hpp>
46 #if BOOST_VERSION < 104100
47 #error Nuklei requires Boost >= 1.41
50 #define NUKLEI_SERIALIZATION_NVP(T) BOOST_SERIALIZATION_NVP(T)
51 #define NUKLEI_SERIALIZATION_FRIEND_CLASSNAME boost::serialization::access
52 #define NUKLEI_SERIALIZATION_MAKE_NVP boost::serialization::make_nvp
53 #define NUKLEI_SERIALIZATION_BASE(T) boost::serialization::base_object<T>( *this )
54 #define NUKLEI_SERIALIZATION_CLASS_VERSION BOOST_CLASS_VERSION
55 #define NUKLEI_SERIALIZATION_REGISTER_TYPE BOOST_CLASS_EXPORT_IMPLEMENT
56 #define NUKLEI_SERIALIZATION_DECLARE_TYPE_WITH_NAME BOOST_CLASS_EXPORT_KEY2
57 #define NUKLEI_SERIALIZATION_BINARY_IARCHIVE boost::archive::binary_iarchive
58 #define NUKLEI_SERIALIZATION_BINARY_OARCHIVE boost::archive::binary_oarchive
59 #define NUKLEI_SERIALIZATION_XML_IARCHIVE boost::archive::xml_iarchive
60 #define NUKLEI_SERIALIZATION_XML_OARCHIVE boost::archive::xml_oarchive
61 #define NUKLEI_SERIALIZATION_NAMESPACE_BEGIN namespace boost { namespace serialization {
62 #define NUKLEI_SERIALIZATION_NAMESPACE_END } }
67 #if (NUKLEI_UNIQUE_PTR_IMPL == 0 && defined(BOOST_NO_CXX11_SMART_PTR)) || NUKLEI_UNIQUE_PTR_IMPL == 1
74 namespace serialization {
80 template<
class Archive,
class T>
83 const std::auto_ptr<T> &t,
84 const unsigned int file_version
88 const T *
const raw_ptr = t.get();
89 ar << NUKLEI_SERIALIZATION_NVP(raw_ptr);
92 template<
class Archive,
class T>
96 const unsigned int file_version
99 ar >> NUKLEI_SERIALIZATION_NVP(raw_ptr);
105 template<
class Archive,
class T>
106 inline void serialize(
109 const unsigned int file_version
111 boost::serialization::split_free(ar, t, file_version);
119 #include <boost/serialization/unique_ptr.hpp>
123 #include <boost/ptr_container/serialize_ptr_vector.hpp>
124 #include <boost/ptr_container/serialize_ptr_array.hpp>
127 #include <boost/serialization/export.hpp>
128 #include <boost/serialization/base_object.hpp>
134 #elif NUKLEI_SERIALIZATION_IMPL == 1 // Cereal
136 #include <nuklei/cereal/archives/binary.hpp>
137 #include <nuklei/cereal/archives/xml.hpp>
139 #include <nuklei/cereal/types/polymorphic.hpp>
141 #include <nuklei/cereal/types/vector.hpp>
142 #include <nuklei/cereal/types/list.hpp>
143 #include <nuklei/cereal/types/string.hpp>
144 #include <nuklei/cereal/types/utility.hpp>
145 #include <nuklei/cereal/types/map.hpp>
146 #include <nuklei/cereal/types/memory.hpp>
147 #include <nuklei/cereal/types/common.hpp>
149 #if BOOST_VERSION < 104100
150 #error Nuklei requires Boost >= 1.41
153 #include <boost/optional.hpp>
155 namespace nuklei_cereal
158 template <
class Archive,
class Optioned>
inline
159 void save(Archive & ar, ::boost::optional<Optioned>
const & optional)
161 bool initFlag = (bool)optional;
164 ar(NUKLEI_CEREAL_NVP_(
"initialized",
true));
165 ar(NUKLEI_CEREAL_NVP_(
"value", optional.get()));
169 ar(NUKLEI_CEREAL_NVP_(
"initialized",
false));
174 template <
class Archive,
class Optioned>
inline
175 void load(Archive & ar, ::boost::optional<Optioned> & optional)
179 ar(NUKLEI_CEREAL_NVP_(
"initialized", initFlag));
183 ar(NUKLEI_CEREAL_NVP_(
"value", val));
184 optional = std::move(val);
187 optional = ::boost::none;
192 #define NUKLEI_SERIALIZATION_NVP(T) NUKLEI_CEREAL_NVP(T)
193 #define NUKLEI_SERIALIZATION_FRIEND_CLASSNAME nuklei_cereal::access
194 #define NUKLEI_SERIALIZATION_MAKE_NVP nuklei_cereal::make_nvp
195 #define NUKLEI_SERIALIZATION_BASE(T) nuklei_cereal::base_class<T>( this )
196 #define NUKLEI_SERIALIZATION_CLASS_VERSION NUKLEI_CEREAL_CLASS_VERSION
197 #define NUKLEI_SERIALIZATION_REGISTER_TYPE NUKLEI_CEREAL_REGISTER_TYPE
198 #define NUKLEI_SERIALIZATION_DECLARE_TYPE_WITH_NAME(T, U)
199 #define NUKLEI_SERIALIZATION_BINARY_IARCHIVE nuklei_cereal::BinaryInputArchive
200 #define NUKLEI_SERIALIZATION_BINARY_OARCHIVE nuklei_cereal::BinaryOutputArchive
201 #define NUKLEI_SERIALIZATION_XML_IARCHIVE nuklei_cereal::XMLInputArchive
202 #define NUKLEI_SERIALIZATION_XML_OARCHIVE nuklei_cereal::XMLOutputArchive
203 #define NUKLEI_SERIALIZATION_NAMESPACE_BEGIN namespace nuklei_cereal {
204 #define NUKLEI_SERIALIZATION_NAMESPACE_END }
208 #if (NUKLEI_UNIQUE_PTR_IMPL == 0 && defined(BOOST_NO_CXX11_SMART_PTR)) || NUKLEI_UNIQUE_PTR_IMPL == 1
209 #error Cereal requires C++ 11
212 #include <nuklei/cereal/types/base_class.hpp>