20 #ifndef TPIE_SERIALIZATION2_H
21 #define TPIE_SERIALIZATION2_H
32 #include <tpie/config.h>
35 #include <boost/type_traits/is_pod.hpp>
36 #include <boost/type_traits/is_pointer.hpp>
37 #include <boost/utility/enable_if.hpp>
38 #include <tpie/is_simple_iterator.h>
94 template <
typename TT>
97 template <
typename TT>
98 static long magic(...);
100 static bool const value=
101 boost::is_pod<T>::value ||
sizeof(magic<T>((T*)0))==
sizeof(
char);
107 template <
typename D,
typename T>
110 typename boost::disable_if<boost::is_pointer<T> >::type * = 0) {
111 dst.write((
const char *)&v,
sizeof(T));
117 template <
typename S,
typename T>
120 typename boost::disable_if<boost::is_pointer<T> >::type * = 0) {
121 src.read((
char *)&v,
sizeof(T));
130 template <
typename D,
typename T,
132 bool is_pod=boost::is_pod<typename std::iterator_traits<T>::value_type>::value,
133 bool is_pointer=boost::is_pointer<typename std::iterator_traits<T>::value_type>::value>
135 void operator()(D & dst, T start, T end) {
137 for (T i=start; i != end; ++i)
serialize(dst, *i);
141 template <
typename D,
typename T>
143 void operator()(D & d, T start, T end) {
144 const char * from =
reinterpret_cast<const char *
>(&*start);
145 const char * to =
reinterpret_cast<const char *
>(&*end);
146 d.write(from, to-from);
154 template <
typename D,
typename T,
156 bool is_pod=boost::is_pod<typename std::iterator_traits<T>::value_type>::value,
157 bool is_pointer=boost::is_pointer<typename std::iterator_traits<T>::value_type>::value>
159 void operator()(D & dst, T start, T end) {
161 for (T i=start; i != end; ++i)
unserialize(dst, *i);
165 template <
typename D,
typename T>
167 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,
typename alloc_t>
213 void serialize(D & dst,
const std::vector<T, alloc_t> & v) {
222 template <
typename S,
typename T,
typename alloc_t>
224 typename std::vector<T>::size_type s;
235 template <
typename D,
typename T>
236 void serialize(D & dst,
const std::basic_string<T> & v) {
246 template <
typename S,
typename T>
248 typename std::basic_string<T>::size_type s;
258 template <
typename T>
268 #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.