1#ifndef UTIL_MEMORY_I_ARCHIVE_H
2#define UTIL_MEMORY_I_ARCHIVE_H
14#include <util/space/Vector.h>
15#include <util/space/IntVector.h>
107 template <
typename T,
size_t N>
117 template <
typename T,
size_t N>
127 template <
typename T>
136 template <
typename T>
137 void unpack(T* array,
int n);
150 template <
typename T>
151 void unpack(T* array,
int m,
int n,
int np);
160 void recv(MPI::Intracomm& comm,
int source);
212 unsigned int version_;
251 {
return capacity_; }
257 {
return (
bool) begin_; }
264 template <
typename T>
267 serialize(*
this, data, version_);
274 template <
typename T>
277 serialize(*
this, data, version_);
284 template <
typename T,
size_t N>
287 for (
size_t i=0; i < N; ++i) {
288 serialize(*
this, data[i], version_);
296 template <
typename T,
size_t N>
299 for (
size_t i=0; i < N; ++i) {
300 serialize(*
this, data[i], version_);
308 template <
typename T>
311 if (cursor_ +
sizeof(data) > end_) {
312 UTIL_THROW(
"Attempted read past end of packed block");
316 std::memcpy(
static_cast<void*
>(&data), cursor_,
sizeof(T));
317 cursor_ +=
sizeof(T);
323 template <
typename T>
326 if (cursor_ + n*
sizeof(T) > end_) {
327 UTIL_THROW(
"Attempted read past end of data");
329 std::memcpy(
static_cast<void*
>(array), cursor_, n*
sizeof(T));
330 cursor_ += n*
sizeof(T);
336 template <
typename T>
339 if (cursor_ + m*n*
sizeof(T) > end_) {
340 UTIL_THROW(
"Attempted read past end of data");
342 for (
int i = 0; i < m; ++i) {
343 std::memcpy(
static_cast<void*
>(array + i*np), cursor_, n*
sizeof(T));
344 cursor_ += n*
sizeof(T);
355 const unsigned int version)
362 inline void serialize(MemoryIArchive& ar,
bool& data,
363 const unsigned int version)
371 const unsigned int version)
379 const unsigned int version)
387 const unsigned int version)
395 const unsigned int version)
403 const unsigned int version)
411 const unsigned int version)
417 template <
typename T>
419 const unsigned int version)
426 for (
size_t i = 0; i < size; ++i) {
428 data.push_back(element);
438 inline void serialize(
MemoryIArchive& ar, std::complex<float>& data,
439 const unsigned int version)
446 inline void serialize(
MemoryIArchive& ar, std::complex<double>& data,
447 const unsigned int version)
455 const unsigned int version);
464 const unsigned int version)
472 const unsigned int version)
An IntVector is an integer Cartesian vector.
Input archive for packed heterogeneous binary data.
Byte * begin() const
Return pointer to beginning of block.
static bool is_saving()
Returns true;.
MemoryIArchive & operator&(T &data)
Load (read) one object of type T via the & operator.
static bool is_loading()
Returns false;.
MemoryIArchive & operator=(MemoryOArchive &other)
Assignment from MemoryOArchive.
void allocate(size_t capacity)
Allocate memory block.
void reset()
Reset the cursor to the beginning (for rereading).
size_t capacity() const
Return capacity in Bytes.
void clear()
Reset to empty state.
void unpack(T &data)
Unpack one object of type T.
Byte * cursor() const
Return pointer to current position (cursor).
MemoryIArchive & operator>>(T &data)
Load (read) one object of type T via the >> operator.
void release()
Release memory obtained by assignment.
MemoryIArchive()
Constructor.
Byte * end() const
Return pointer to end of packed block (one Byte past the last).
bool isAllocated() const
Has memory been allocated?
Save archive for packed heterogeneous binary data.
A Vector is a Cartesian vector.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.
unsigned char Byte
Define a "Byte" type.