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>
106 template <
typename T,
size_t N>
116 template <
typename T,
size_t N>
126 template <
typename T>
135 template <
typename T>
136 void unpack(T* array,
int n);
149 template <
typename T>
150 void unpack(T* array,
int m,
int n,
int np);
159 void recv(MPI::Intracomm& comm,
int source);
211 unsigned int version_;
250 {
return capacity_; }
256 {
return (
bool) begin_; }
263 template <
typename T>
266 serialize(*
this, data, version_);
273 template <
typename T>
276 serialize(*
this, data, version_);
283 template <
typename T,
size_t N>
286 for (
size_t i=0; i < N; ++i) {
287 serialize(*
this, data[i], version_);
295 template <
typename T,
size_t N>
298 for (
size_t i=0; i < N; ++i) {
299 serialize(*
this, data[i], version_);
307 template <
typename T>
310 if (cursor_ +
sizeof(data) > end_) {
311 UTIL_THROW(
"Attempted read past end of packed block");
313 T* ptr = (T *)cursor_;
316 cursor_ = (
Byte *)ptr;
322 template <
typename T>
325 if (cursor_ + n*
sizeof(T) > end_) {
326 UTIL_THROW(
"Attempted read past end of data");
328 T* ptr = (T *)cursor_;
329 for (
int i=0; i < n; ++i) {
333 cursor_ = (
Byte *)ptr;
339 template <
typename T>
342 if (cursor_ + m*n*
sizeof(T) > end_) {
343 UTIL_THROW(
"Attempted read past end of data");
346 T* ptr = (T *)cursor_;
347 for (i = 0; i < m; ++i) {
348 for (j = 0; j < n; ++j) {
349 array[i*np + j] = *ptr;
353 cursor_ = (
Byte *)ptr;
363 const unsigned int version)
370 inline void serialize(MemoryIArchive& ar,
bool& data,
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)
419 const unsigned int version)
425 template <
typename T>
427 const unsigned int version)
434 for (
size_t i = 0; i < size; ++i) {
436 data.push_back(element);
446 inline void serialize(
MemoryIArchive& ar, std::complex<float>& data,
447 const unsigned int version)
454 inline void serialize(
MemoryIArchive& ar, std::complex<double>& data,
455 const unsigned int version)
463 const unsigned int version);
472 const unsigned int version)
480 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.
~MemoryIArchive()
Destructor.
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.