1#ifndef UTIL_MEMORY_O_ARCHIVE_H
2#define UTIL_MEMORY_O_ARCHIVE_H
14#include <util/space/Vector.h>
15#include <util/space/IntVector.h>
91 template <
typename T,
size_t N>
101 template <
typename T,
size_t N>
109 template <
typename T>
110 void pack(
const T& data);
118 template <
typename T>
119 void pack(
const T* array,
int n);
132 template <
typename T>
133 void pack(
const T* array,
int m,
int n,
int np);
142 void send(MPI::Intracomm& comm,
int dest);
151 void iSend(MPI::Intracomm& comm, MPI::Request& req,
int dest);
192 unsigned int version_;
212 friend class MemoryIArchive;
230 {
return (
bool) begin_; }
236 {
return capacity_; }
253 template <
typename T>
256 serialize(*
this, data, version_);
263 template <
typename T>
266 serialize(*
this, data, version_);
273 template <
typename T,
size_t N>
276 for (
size_t i = 0; i < N; ++i) {
277 serialize(*
this, data[i], version_);
285 template <
typename T,
size_t N>
288 for (
size_t i = 0; i < N; ++i) {
289 serialize(*
this, data[i], version_);
299 template <
typename T>
305 if (cursor_ +
sizeof(data) > endAllocated_) {
306 UTIL_THROW(
"Attempted write past end of allocated block");
308 T* ptr = (T *)cursor_;
311 cursor_ = (
Byte *)ptr;
317 template <
typename T>
323 if (cursor_ + n*
sizeof(T) > endAllocated_) {
324 UTIL_THROW(
"Attempted write past end of allocated block");
326 T* ptr = (T *)cursor_;
327 for (
int i=0; i < n; ++i) {
331 cursor_ = (
Byte *)ptr;
337 template <
typename T>
343 if (cursor_ + m*n*
sizeof(T) > endAllocated_) {
344 UTIL_THROW(
"Attempted write past end of allocated block");
347 T* ptr = (T *)cursor_;
348 for (i=0; i < m; ++i) {
349 for (j=0; j < n; ++j) {
350 *ptr = array[i*np + j];
354 cursor_ = (
Byte *)ptr;
364 const unsigned int version)
371 inline void serialize(MemoryOArchive& ar,
char& data,
372 const unsigned int version)
380 const unsigned int version)
388 const unsigned int version)
396 const unsigned int version)
404 const unsigned int version)
412 const unsigned int version)
420 const unsigned int version)
426 template <
typename T>
428 const unsigned int version)
430 size_t size = data.size();
432 for (
size_t i = 0; i < size; ++i) {
443 inline void serialize(
MemoryOArchive& ar, std::complex<float>& data,
444 const unsigned int version)
451 inline void serialize(
MemoryOArchive& ar, std::complex<double>& data,
452 const unsigned int version)
460 const unsigned int version)
462 size_t size = data.size() + 1;
464 const char* temp = data.c_str();
475 const unsigned int version)
483 const unsigned int version)
An IntVector is an integer Cartesian vector.
Input archive for packed heterogeneous binary data.
Save archive for packed heterogeneous binary data.
virtual ~MemoryOArchive()
Destructor.
virtual void allocate(size_t capacity)
Allocate memory.
void pack(const T &data)
Pack a T object.
static bool is_loading()
Returns false;.
bool isAllocated() const
Has memory been allocated?
Byte * cursor() const
Return pointer to current position (cursor).
static bool is_saving()
Returns true;.
MemoryOArchive & operator<<(T &data)
Save (write) one object to this archive via the << operator.
MemoryOArchive & operator&(T &data)
Save (write) one object to this archive via the & operator.
Byte * begin() const
Return pointer to beginning of block.
size_t capacity() const
Return capacity in Bytes.
MemoryOArchive()
Constructor.
void clear()
Resets the cursor to the beginning.
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.