1 #ifndef UTIL_MEMORY_I_ARCHIVE_H 2 #define UTIL_MEMORY_I_ARCHIVE_H 12 #include "serialize.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)
323 const unsigned int version)
331 const unsigned int version)
339 const unsigned int version)
347 const unsigned int version)
355 const unsigned int version)
363 const unsigned int version)
371 const unsigned int version)
377 template <
typename T>
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)
415 const unsigned int version);
424 const unsigned int version)
432 const unsigned int version)
A Vector is a Cartesian vector.
Byte * end() const
Return pointer to end of packed block (one Byte past the last).
size_t capacity() const
Return capacity in Bytes.
MemoryIArchive & operator=(MemoryOArchive &other)
Assignment from MemoryOArchive.
MemoryIArchive & operator&(T &data)
Load one object.
void reset()
Reset the cursor to the beginning (for rereading).
void release()
Release memory obtained by assignment.
MemoryIArchive()
Constructor.
unsigned char Byte
Define a "Byte" type.
void allocate(size_t capacity)
Allocate memory block.
void unpack(T &data)
Unpack one object of type T.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Save archive for packed heterogeneous binary data.
Utility classes for scientific computation.
Byte * cursor() const
Return pointer to current position (cursor).
void clear()
Reset to empty state.
MemoryIArchive & operator>>(T &data)
Load one object.
static bool is_loading()
Returns false;.
Byte * begin() const
Return pointer to beginning of block.
bool isAllocated() const
Has memory been allocated?
void recv(MPI::Intracomm &comm, int source)
Receive packed data via MPI.
An IntVector is an integer Cartesian vector.
~MemoryIArchive()
Destructor.
static bool is_saving()
Returns true;.
Input archive for packed heterogeneous binary data.