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>
102 template <
typename T>
111 template <
typename T>
112 void unpack(T* array,
int n);
125 template <
typename T>
126 void unpack(T* array,
int m,
int n,
int np);
135 void recv(MPI::Intracomm& comm,
int source);
187 unsigned int version_;
226 {
return capacity_; }
232 {
return (
bool) begin_; }
239 template <
typename T>
242 serialize(*
this, data, version_);
249 template <
typename T>
252 serialize(*
this, data, version_);
259 template <
typename T>
262 if (cursor_ +
sizeof(data) > end_) {
263 UTIL_THROW(
"Attempted read past end of packed block");
265 T* ptr = (T *)cursor_;
268 cursor_ = (
Byte *)ptr;
274 template <
typename T>
277 if (cursor_ + n*
sizeof(T) > end_) {
278 UTIL_THROW(
"Attempted read past end of data");
280 T* ptr = (T *)cursor_;
281 for (
int i=0; i < n; ++i) {
285 cursor_ = (
Byte *)ptr;
291 template <
typename T>
294 if (cursor_ + m*n*
sizeof(T) > end_) {
295 UTIL_THROW(
"Attempted read past end of data");
298 T* ptr = (T *)cursor_;
299 for (i = 0; i < m; ++i) {
300 for (j = 0; j < n; ++j) {
301 array[i*np + j] = *ptr;
305 cursor_ = (
Byte *)ptr;
315 const unsigned int version)
322 inline void serialize(MemoryIArchive& ar,
bool& data,
323 const unsigned int version)
330 inline void serialize(MemoryIArchive& ar,
unsigned int& data,
331 const unsigned int version)
338 inline void serialize(MemoryIArchive& ar,
int& data,
339 const unsigned int version)
346 inline void serialize(MemoryIArchive& ar,
unsigned long& data,
347 const unsigned int version)
354 inline void serialize(MemoryIArchive& ar,
long& data,
355 const unsigned int version)
362 inline void serialize(MemoryIArchive& ar,
float& data,
363 const unsigned int version)
370 inline void serialize(MemoryIArchive& ar,
double& data,
371 const unsigned int version)
377 template <
typename T>
378 void serialize(MemoryIArchive& ar, std::vector<T>& data,
379 const unsigned int version)
386 for (
size_t i = 0; i < size; ++i) {
388 data.push_back(element);
398 inline void serialize(MemoryIArchive& ar, std::complex<float>& data,
399 const unsigned int version)
406 inline void serialize(MemoryIArchive& ar, std::complex<double>& data,
407 const unsigned int version)
414 void serialize(MemoryIArchive& ar, std::string& data,
415 const unsigned int version);
423 inline void serialize(MemoryIArchive& ar, Vector& data,
424 const unsigned int version)
431 inline void serialize(MemoryIArchive& ar, IntVector& data,
432 const unsigned int version)
Input archive for packed heterogeneous binary data.
void recv(MPI::Intracomm &comm, int source)
Receive packed data via MPI.
Byte * begin() const
Return pointer to beginning of block.
static bool is_saving()
Returns true;.
MemoryIArchive & operator&(T &data)
Load one object.
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 one object.
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.
#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.