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>
80 void pack(
const T& data);
89 void pack(
const T* array,
int n);
102 template <
typename T>
103 void pack(
const T* array,
int m,
int n,
int np);
112 void send(MPI::Intracomm& comm,
int dest);
121 void iSend(MPI::Intracomm& comm, MPI::Request& req,
int dest);
162 unsigned int version_;
200 {
return (
bool) begin_; }
206 {
return capacity_; }
223 template <
typename T>
225 { serialize(*
this, data, version_); }
230 template <
typename T>
233 serialize(*
this, data, version_);
242 template <
typename T>
248 if (cursor_ +
sizeof(data) > endAllocated_) {
249 UTIL_THROW(
"Attempted write past end of allocated block");
251 T* ptr = (T *)cursor_;
254 cursor_ = (
Byte *)ptr;
260 template <
typename T>
266 if (cursor_ + n*
sizeof(T) > endAllocated_) {
267 UTIL_THROW(
"Attempted write past end of allocated block");
269 T* ptr = (T *)cursor_;
270 for (
int i=0; i < n; ++i) {
274 cursor_ = (
Byte *)ptr;
280 template <
typename T>
286 if (cursor_ + m*n*
sizeof(T) > endAllocated_) {
287 UTIL_THROW(
"Attempted write past end of allocated block");
290 T* ptr = (T *)cursor_;
291 for (i=0; i < m; ++i) {
292 for (j=0; j < n; ++j) {
293 *ptr = array[i*np + j];
297 cursor_ = (
Byte *)ptr;
307 const unsigned int version)
314 inline void serialize(MemoryOArchive& ar,
char& data,
315 const unsigned int version)
322 inline void serialize(MemoryOArchive& ar,
unsigned int& data,
323 const unsigned int version)
330 inline void serialize(MemoryOArchive& ar,
int& data,
331 const unsigned int version)
338 inline void serialize(MemoryOArchive& ar,
unsigned long& data,
339 const unsigned int version)
346 inline void serialize(MemoryOArchive& ar,
long& data,
347 const unsigned int version)
354 inline void serialize(MemoryOArchive& ar,
float& data,
355 const unsigned int version)
362 inline void serialize(MemoryOArchive& ar,
double& data,
363 const unsigned int version)
369 template <
typename T>
370 void serialize(MemoryOArchive& ar, std::vector<T>& data,
371 const unsigned int version)
373 size_t size = data.size();
375 for (
size_t i = 0; i < size; ++i) {
386 inline void serialize(MemoryOArchive& ar, std::complex<float>& data,
387 const unsigned int version)
394 inline void serialize(MemoryOArchive& ar, std::complex<double>& data,
395 const unsigned int version)
402 inline void serialize(MemoryOArchive& ar, std::string& data,
403 const unsigned int version)
405 size_t size = data.size() + 1;
407 const char* temp = data.c_str();
417 inline void serialize(MemoryOArchive& ar, Vector& data,
418 const unsigned int version)
425 inline void serialize(MemoryOArchive& ar, IntVector& data,
426 const unsigned int version)
Input archive for packed heterogeneous binary data.
Save archive for packed heterogeneous binary data.
virtual ~MemoryOArchive()
Destructor.
void iSend(MPI::Intracomm &comm, MPI::Request &req, int dest)
Send packed data via MPI (non-blocking)
void operator&(T &data)
Save one object.
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 one object.
Byte * begin() const
Return pointer to beginning of block.
size_t capacity() const
Return capacity in Bytes.
MemoryOArchive()
Constructor.
void send(MPI::Intracomm &comm, int dest)
Send packed data via MPI.
void clear()
Resets the cursor to the beginning.
#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.