20 #ifndef TPIE_SERIALIZATION2_H
21 #define TPIE_SERIALIZATION2_H
32 #include <tpie/config.h>
35 #include <type_traits>
36 #include <tpie/is_simple_iterator.h>
90 template <
typename TT>
91 static char magic(TT *,
typename std::enable_if<TT::is_trivially_serializable>::type *_=0);
93 template <
typename TT>
94 static long magic(...);
96 static bool const value=
97 (std::is_pod<T>::value ||
sizeof(magic<T>((T*)
nullptr))==
sizeof(
char)) && !std::is_pointer<T>::value;
103 template <
typename D,
typename T>
106 dst.write((
const char *)&v,
sizeof(T));
112 template <
typename S,
typename T>
115 src.read((
char *)&v,
sizeof(T));
124 template <
typename D,
typename T,
126 bool is_ts=is_trivially_serializable<typename std::iterator_traits<T>::value_type>::value>
128 void operator()(D & dst, T start, T end) {
130 for (T i=start; i != end; ++i)
serialize(dst, *i);
134 template <
typename D,
typename T>
136 void operator()(D & d, T start, T end) {
141 const char * from =
reinterpret_cast<const char *
>(&*start);
142 const char * to =
reinterpret_cast<const char *
>(&*end);
143 d.write(from, to-from);
151 template <
typename D,
typename T,
155 void operator()(D & dst, T start, T end) {
157 for (T i=start; i != end; ++i)
unserialize(dst, *i);
161 template <
typename D,
typename T>
163 void operator()(D & d, T start, T end) {
168 char * from =
reinterpret_cast<char *
>(&*start);
169 char * to =
reinterpret_cast<char *
>(&*end);
170 d.read(from, to-from);
180 void write(
const void *,
size_t s) {size += s;}
191 template <
typename D,
typename T>
194 magic(dst, start, end);
203 template <
typename D,
typename T>
206 magic(dst, start, end);
212 template <
typename D,
typename T, std::
size_t size>
221 template <
typename S,
typename T, std::
size_t size>
230 template <
typename D,
typename T, std::
size_t size>
231 void serialize(D & dst,
const std::array<T, size> & v) {
239 template <
typename S,
typename T, std::
size_t size>
248 template <
typename D,
typename T,
typename alloc_t>
249 void serialize(D & dst,
const std::vector<T, alloc_t> & v) {
258 template <
typename S,
typename T,
typename alloc_t>
260 typename std::vector<T>::size_type s;
271 template <
typename D,
typename T>
272 void serialize(D & dst,
const std::basic_string<T> & v) {
275 serialize(dst, v.c_str(), v.c_str() + v.size());
282 template <
typename S,
typename T>
284 typename std::basic_string<T>::size_type s;
294 template <
typename T>
304 #endif // TPIE_SERIALIZATION2_H
Helper to facilitate fast serialization of trivially copyable arrays.
size_t serialized_size(const T &v)
Given a serializable, serialize it and measure its serialized size.
Checks if an iterator is simple.
This file contains a few deprecated definitions for legacy code.
void unserialize(S &src, foo &v)
Sample tpie::unserialize prototype.
Helper to facilitate fast unserialization of trivially copyable arrays.
Helper to count the serialized size of objects.
void serialize(D &dst, const foo &v)
Sample tpie::serialize prototype.