View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

serialize.h
Go to the documentation of this file.
1#ifndef SERIALIZE_H
2#define SERIALIZE_H
3
4#include "archives_config.h"
5
6#include <boost/config.hpp>
7#include <boost/version.hpp>
8
9#ifndef NO_SHMEM
11#include <boost/interprocess/containers/map.hpp>
12#include <boost/interprocess/containers/string.hpp>
13#include <boost/interprocess/containers/vector.hpp>
14#endif
15
16#ifdef USE_BOOST_ARCHIVE
17#include <boost/serialization/utility.hpp>
18#include <boost/serialization/collections_save_imp.hpp>
19#include <boost/serialization/collections_load_imp.hpp>
20#include <boost/serialization/split_free.hpp>
21#include <boost/serialization/map.hpp>
22#include <boost/serialization/string.hpp>
23#include <boost/serialization/level.hpp>
24#include <boost/serialization/array.hpp>
25#include <boost/serialization/vector.hpp>
26#endif
27
28#ifdef USE_YAS
29#include <yas/serialize.hpp>
30#include <yas/boost_types.hpp>
31#include <yas/std_types.hpp>
32#include <yas/object.hpp>
33#endif
34
35namespace boost {
36namespace serialization {
37
38
39#ifndef NO_SHMEM
40#ifdef USE_BOOST_ARCHIVE
41/* serialize boost::container::map */
42
43template<class Archive, class Type, class Key, class Compare, class Allocator>
44inline void save(Archive &ar, const boost::interprocess::map<Key, Type, Compare, Allocator> &t,
45 const unsigned int /* file_version */
46)
47{
48 boost::serialization::stl::save_collection<Archive, boost::interprocess::map<Key, Type, Compare, Allocator>>(ar, t);
49}
50
51template<class Archive, class Type, class Key, class Compare, class Allocator>
52inline void load(Archive &ar, boost::interprocess::map<Key, Type, Compare, Allocator> &t,
53 const unsigned int /* file_version */
54)
55{
56#if BOOST_VERSION >= 105900
57 boost::serialization::load_map_collection<Archive, boost::interprocess::map<Key, Type, Compare, Allocator>>(ar, t);
58#else
59 boost::serialization::stl::load_collection<
60 Archive, boost::interprocess::map<Key, Type, Compare, Allocator>,
61 boost::serialization::stl::archive_input_map<Archive, boost::interprocess::map<Key, Type, Compare, Allocator>>,
62 boost::serialization::stl::no_reserve_imp<boost::interprocess::map<Key, Type, Compare, Allocator>>>(ar, t);
63#endif
64}
65
66// split non-intrusive serialization function member into separate
67// non intrusive save/load member functions
68template<class Archive, class Type, class Key, class Compare, class Allocator>
69inline void serialize(Archive &ar, boost::interprocess::map<Key, Type, Compare, Allocator> &t,
70 const unsigned int file_version)
71{
72 boost::serialization::split_free(ar, t, file_version);
73}
74#endif
75#endif
76
77
78#ifndef NO_SHMEM
79#ifdef USE_BOOST_ARCHIVE
80/* serialize boost::container::vector */
81
82template<class Archive, class U, class Allocator>
83inline void save(Archive &ar, const boost::container::vector<U, Allocator> &t, const unsigned int /* file_version */
84)
85{
86 size_t count = t.size();
87 ar &boost::serialization::make_nvp("count", count);
88 auto it = t.begin();
89 while (count-- > 0) {
90 ar &boost::serialization::make_nvp("item", *it);
91 ++it;
92 }
93}
94
95template<class Archive, class U, class Allocator>
96inline void load(Archive &ar, boost::container::vector<U, Allocator> &t, const unsigned int /* file_version */
97)
98{
99 size_t count = 0;
100 ar &boost::serialization::make_nvp("count", count);
101 t.clear();
102 t.reserve(count);
103 while (count-- > 0) {
104 detail::stack_construct<Archive, U> u(ar, 0);
105 ar >> boost::serialization::make_nvp("item", u.reference());
106 t.push_back(u.reference());
107 ar.reset_object_address(&t.back(), &u.reference());
108 }
109}
110
111// split non-intrusive serialization function member into separate
112// non intrusive save/load member functions
113template<class Archive, class Type, class Allocator>
114inline void serialize(Archive &ar, boost::container::vector<Type, Allocator> &t, const unsigned int file_version)
115{
116 boost::serialization::split_free(ar, t, file_version);
117}
118#endif
119#endif
120
121#ifndef NO_SHMEM
122#ifdef USE_BOOST_ARCHIVE
123/* serialize boost::container::string */
124
125template<class Archive, class CharT, class Allocator>
126inline void save(Archive &ar, const boost::container::basic_string<CharT, std::char_traits<CharT>, Allocator> &t,
127 const unsigned int file_version)
128{
129 size_t count = t.size();
130 ar &boost::serialization::make_nvp("count", count);
131 auto it = t.begin();
132 while (count-- > 0) {
133 ar &boost::serialization::make_nvp("item", *it);
134 ++it;
135 }
136}
137
138template<class Archive, class CharT, class Allocator>
139inline void load(Archive &ar, boost::container::basic_string<CharT, std::char_traits<CharT>, Allocator> &t,
140 const unsigned int file_version)
141{
142 size_t count = 0;
143 ar &boost::serialization::make_nvp("count", count);
144 t.clear();
145 t.reserve(count);
146 while (count-- > 0) {
147 detail::stack_construct<Archive, CharT> u(ar, 0);
148 ar >> boost::serialization::make_nvp("item", u.reference());
149 t.push_back(u.reference());
150 ar.reset_object_address(&t[t.length() - 1], &u.reference());
151 }
152}
153
154// split non-intrusive serialization function member into separate
155// non intrusive save/load member functions
156template<class Archive, class CharT, class Allocator>
157inline void serialize(Archive &ar, boost::container::basic_string<CharT, std::char_traits<CharT>, Allocator> &t,
158 const unsigned int file_version)
159{
160 boost::serialization::split_free(ar, t, file_version);
161}
162#endif
163#endif
164
165} // namespace serialization
166} // namespace boost
167
168#endif
void serialize(Archive &ar, vistle::Vector1 &v, const unsigned int version)
Definition: vector.h:105
Definition: serialize.h:35