//
#include <type_traits>
+#include <iostream>
#include "core/module.hpp"
/// Serialize the specified object.
template<typename T>
void
- _proc(compat::ostream &os, const T &x) {
+ _proc(std::ostream &os, const T &x) {
_serializer<T>::proc(os, x);
}
/// Deserialize the specified object.
template<typename T>
void
- _proc(compat::istream &is, T &x) {
+ _proc(std::istream &is, T &x) {
_serializer<T>::proc(is, x);
}
template<typename T>
T
- _proc(compat::istream &is) {
+ _proc(std::istream &is) {
T x;
_serializer<T>::proc(is, x);
return x;
struct _serializer<T, typename std::enable_if<
std::is_scalar<T>::value>::type> {
static void
- proc(compat::ostream &os, const T &x) {
+ proc(std::ostream &os, const T &x) {
os.write(reinterpret_cast<const char *>(&x), sizeof(x));
}
static void
- proc(compat::istream &is, T &x) {
+ proc(std::istream &is, T &x) {
is.read(reinterpret_cast<char *>(&x), sizeof(x));
}
/// (De)serialize a vector.
template<typename T>
- struct _serializer<compat::vector<T>,
+ struct _serializer<std::vector<T>,
typename std::enable_if<
!std::is_scalar<T>::value>::type> {
static void
- proc(compat::ostream &os, const compat::vector<T> &v) {
+ proc(std::ostream &os, const std::vector<T> &v) {
_proc<uint32_t>(os, v.size());
for (size_t i = 0; i < v.size(); i++)
}
static void
- proc(compat::istream &is, compat::vector<T> &v) {
+ proc(std::istream &is, std::vector<T> &v) {
v.resize(_proc<uint32_t>(is));
for (size_t i = 0; i < v.size(); i++)
}
static void
- proc(module::size_t &sz, const compat::vector<T> &v) {
+ proc(module::size_t &sz, const std::vector<T> &v) {
sz += sizeof(uint32_t);
for (size_t i = 0; i < v.size(); i++)
};
template<typename T>
- struct _serializer<compat::vector<T>,
+ struct _serializer<std::vector<T>,
typename std::enable_if<
std::is_scalar<T>::value>::type> {
static void
- proc(compat::ostream &os, const compat::vector<T> &v) {
+ proc(std::ostream &os, const std::vector<T> &v) {
_proc<uint32_t>(os, v.size());
- os.write(reinterpret_cast<const char *>(v.begin()),
+ os.write(reinterpret_cast<const char *>(&v[0]),
v.size() * sizeof(T));
}
static void
- proc(compat::istream &is, compat::vector<T> &v) {
+ proc(std::istream &is, std::vector<T> &v) {
v.resize(_proc<uint32_t>(is));
- is.read(reinterpret_cast<char *>(v.begin()),
+ is.read(reinterpret_cast<char *>(&v[0]),
v.size() * sizeof(T));
}
static void
- proc(module::size_t &sz, const compat::vector<T> &v) {
+ proc(module::size_t &sz, const std::vector<T> &v) {
sz += sizeof(uint32_t) + sizeof(T) * v.size();
}
};
template<>
struct _serializer<std::string> {
static void
- proc(compat::ostream &os, const std::string &s) {
+ proc(std::ostream &os, const std::string &s) {
_proc<uint32_t>(os, s.size());
os.write(&s[0], s.size() * sizeof(std::string::value_type));
}
static void
- proc(compat::istream &is, std::string &s) {
+ proc(std::istream &is, std::string &s) {
s.resize(_proc<uint32_t>(is));
is.read(&s[0], s.size() * sizeof(std::string::value_type));
}
namespace clover {
void
- module::serialize(compat::ostream &os) const {
+ module::serialize(std::ostream &os) const {
_proc(os, *this);
}
module
- module::deserialize(compat::istream &is) {
+ module::deserialize(std::istream &is) {
return _proc<module>(is);
}