1 #ifndef UTIL_MEMORY_O_ARCHIVE_H 2 #define UTIL_MEMORY_O_ARCHIVE_H 12 #include "serialize.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>
230 template <
typename T>
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)
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)
369 template <
typename T>
371 const unsigned int version)
373 size_t size = data.size();
375 for (
size_t i = 0; i < size; ++i) {
387 const unsigned int version)
395 const unsigned int version)
403 const unsigned int version)
405 size_t size = data.size() + 1;
407 const char* temp = data.c_str();
418 const unsigned int version)
426 const unsigned int version)
void send(MPI::Intracomm &comm, int dest)
Send packed data via MPI.
static bool is_saving()
Returns true;.
A Vector is a Cartesian vector.
Byte * begin() const
Return pointer to beginning of block.
size_t capacity() const
Return capacity in Bytes.
Byte * cursor() const
Return pointer to current position (cursor).
virtual ~MemoryOArchive()
Destructor.
void pack(const T &data)
Pack a T object.
bool isAllocated() const
Has memory been allocated?
unsigned char Byte
Define a "Byte" type.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
MemoryOArchive()
Constructor.
Save archive for packed heterogeneous binary data.
Utility classes for scientific computation.
void operator&(T &data)
Save one object.
MemoryOArchive & operator<<(T &data)
Save one object.
static bool is_loading()
Returns false;.
An IntVector is an integer Cartesian vector.
void serialize(Archive &ar, T &data, const unsigned int version)
Serialize one object of type T.
void iSend(MPI::Intracomm &comm, MPI::Request &req, int dest)
Send packed data via MPI (non-blocking)
virtual void allocate(size_t capacity)
Allocate memory.
Input archive for packed heterogeneous binary data.
void clear()
Resets the cursor to the beginning.