25 #include <type_traits> 29 namespace serialization {
32 template<
typename Archive>
33 void save(Archive &ar,
const bool &t,
const unsigned int)
35 unsigned char value(t?1:0);
39 template<
typename Archive>
40 void load(Archive &ar,
bool &t,
const unsigned int)
44 t = (value == 0)?
false:
true;
48 template<
typename Archive,
typename T>
49 typename std::enable_if<
50 std::is_same<T, unsigned char>::value or
51 std::is_same<T, signed char>::value or
52 std::is_same<T, char>::value
53 >::type
save(Archive &ar,
const T &t,
const unsigned int)
59 template<
typename Archive,
typename T>
60 typename std::enable_if<
61 std::is_same<T, unsigned char>::value or
62 std::is_same<T, signed char>::value or
63 std::is_same<T, char>::value
64 >::type
load(Archive &ar, T &t,
const unsigned int)
71 template<
typename Archive,
typename T>
72 typename std::enable_if<
73 std::is_same<T, unsigned short>::value or
74 std::is_same<T, signed short>::value
75 >::type
save(Archive &ar,
const T &t,
const unsigned int)
77 unsigned char buff[2];
78 const auto v =
static_cast<unsigned short>(t);
79 buff[0] =
static_cast<unsigned char>(v >> 0);
80 buff[1] =
static_cast<unsigned char>(v >> 8);
85 template<
typename Archive,
typename T>
86 typename std::enable_if<
87 std::is_same<T, unsigned short>::value or
88 std::is_same<T, signed short>::value
89 >::type
load(Archive &ar, T &t,
const unsigned int)
91 unsigned char buff[2];
95 (
static_cast<unsigned short>(buff[0]) << 0) |
96 (
static_cast<unsigned short>(buff[1]) << 8));
102 template<
typename Archive,
typename T>
103 typename std::enable_if<
104 std::is_same<T, signed int>::value or
105 std::is_same<T, signed long>::value or
106 std::is_same<T, signed long long>::value
107 >::type
save(Archive &ar,
const T &t,
const unsigned int)
113 byte =
static_cast<unsigned char>(value) & 0x7f;
115 const auto signbit = byte & 0x40;
116 if ((value != 0 or signbit != 0) and
117 (value != -1 or signbit == 0)) byte |= 0x80;
119 }
while ((byte & 0x80) != 0);
122 template<
typename Archive,
typename T>
123 typename std::enable_if<
124 std::is_same<T, signed int>::value or
125 std::is_same<T, signed long>::value or
126 std::is_same<T, signed long long>::value
127 >::type
load(Archive &ar, T &t,
const unsigned int)
135 t |= T(byte & 0x7f) << shift;
137 }
while ((byte & 0x80) != 0);
140 const auto signbit = byte & 0x40;
141 if (signbit != 0 and shift < (
sizeof(T)*8)) t |= -(1 << shift);
147 template<
typename Archive,
typename T>
148 typename std::enable_if<
149 std::is_same<T, unsigned int>::value or
150 std::is_same<T, unsigned long>::value or
151 std::is_same<T, unsigned long long>::value
152 >::type
save(Archive &ar,
const T &t,
const unsigned int)
158 byte =
static_cast<unsigned char>(value) & 0x7f;
160 if (value != 0) byte |= 0x80;
162 }
while ((byte & 0x80) != 0);
165 template<
typename Archive,
typename T>
166 typename std::enable_if<
167 std::is_same<T, unsigned int>::value or
168 std::is_same<T, unsigned long>::value or
169 std::is_same<T, unsigned long long>::value
170 >::type
load(Archive &ar, T &t,
const unsigned int)
178 t |= T(byte & 0x7f) << shift;
180 }
while ((byte & 0x80) != 0);
184 static_assert(std::numeric_limits<float>::is_iec559,
"System is IEEE-754");
186 template<
typename Archive>
187 typename std::enable_if<std::numeric_limits<float>::is_iec559>::type
188 save(Archive &ar,
const float &t,
const unsigned int)
191 ar << *static_cast<const unsigned int *>(bin);
194 template<
typename Archive>
195 typename std::enable_if<std::numeric_limits<float>::is_iec559>::type
196 load(Archive &ar,
float &t,
const unsigned int)
200 const void *bin(&num);
201 t = *
reinterpret_cast<const float *
>(bin);
205 static_assert(std::numeric_limits<double>::is_iec559,
"System is IEEE-754");
207 template<
typename Archive>
208 typename std::enable_if<std::numeric_limits<double>::is_iec559>::type
209 save(Archive &ar,
const double &t,
const unsigned int)
212 ar << *static_cast<const unsigned long long *>(bin);
215 template<
typename Archive>
216 typename std::enable_if<std::numeric_limits<double>::is_iec559>::type
217 load(Archive &ar,
double &t,
const unsigned int)
219 unsigned long long num;
221 const void *bin(&num);
222 t = *
reinterpret_cast<const double *
>(bin);
226 template <
typename Archive,
typename T>
227 typename std::enable_if<std::is_arithmetic<T>::value>::type
Definition: ArchiveEntry.hpp:20
std::enable_if< Archive::isSave::value >::type invokeSplit(Archive &ar, T &value, const unsigned int ver)
Definition: Invoke.hpp:69
void save(Archive &ar, const std::complex< T > &t, const unsigned int)
Definition: Complex.hpp:20
void serialize(Archive &ar, std::complex< T > &t, const unsigned int ver)
Definition: Complex.hpp:37
Definition: BinaryObject.hpp:23
void load(Archive &ar, std::complex< T > &t, const unsigned int)
Definition: Complex.hpp:27