25#ifndef __BITPIT_COMMON_BINARY_UTILS_TPP__
26#define __BITPIT_COMMON_BINARY_UTILS_TPP__
42template<typename T, typename std::enable_if<std::is_pod<T>::value>::type*>
43void write(std::ostream &stream,
const std::vector<T> &container)
45 size_t size = container.size();
48 write(stream, container.data(), size *
sizeof(T));
59template<typename T, std::size_t dim, typename std::enable_if<std::is_pod<T>::value>::type*>
60void write(std::ostream &stream,
const std::array<T, dim> &container)
62 write(stream, container.data(), dim *
sizeof(T));
73template<typename T, std::size_t dim, typename std::enable_if<!std::is_pod<T>::value>::type*>
74void write(std::ostream &stream,
const std::array<T, dim> &container)
76 for (std::size_t i = 0; i < dim; ++i) {
77 write(stream, container[i]);
89template<typename T, typename std::enable_if<utils::is_iterable<T>::value>::type*>
90void write(std::ostream &stream,
const T &value)
92 write(stream, value.size());
94 for (
const auto &item : value) {
107template<typename T, typename std::enable_if<std::is_pod<T>::value>::type*>
108void write(std::ostream &stream,
const T &value)
110 write(stream, &value,
sizeof(T));
123void write(std::ostream &stream,
const T &value,
size_t size)
125 stream.write(&value, size);
138void write(std::ostream &stream,
const T *value,
size_t size)
140 stream.write(
reinterpret_cast<const char*
>(value), size);
153void write(std::ostream &stream, T *value,
size_t size)
155 stream.write(
reinterpret_cast<char*
>(value), size);
166template<typename T, typename std::enable_if<std::is_pod<T>::value>::type*>
167void read(std::istream &stream, std::vector<T> &container)
172 container.resize(size);
173 read(stream, container.data(), size *
sizeof(T));
184template<typename T, std::size_t dim, typename std::enable_if<std::is_pod<T>::value>::type*>
185void read(std::istream &stream, std::array<T, dim> &container)
187 read(stream, container.data(), dim *
sizeof(T));
198template<typename T, std::size_t dim, typename std::enable_if<!std::is_pod<T>::value>::type*>
199void read(std::istream &stream, std::array<T, dim> &container)
201 for (std::size_t i = 0; i < dim; ++i) {
202 read(stream, container[i]);
214template<typename T, typename std::enable_if<utils::is_iterable<T>::value>::type*>
215void read(std::istream &stream, T &value)
221 for (
auto &item : value) {
234template<typename T, typename std::enable_if<std::is_pod<T>::value>::type*>
235void read(std::istream &stream, T &value)
237 read(stream, &value,
sizeof(T));
250void read(std::istream &stream, T &value,
size_t size)
252 read(stream, &value, size);
265void read(std::istream &stream, T *value,
size_t size)
267 stream.read(
reinterpret_cast<char*
>(value), size);
void write(std::ostream &stream, const std::vector< bool > &container)
void read(std::istream &stream, std::vector< bool > &container)