OPAL (Object Oriented Parallel Accelerator Library)
2024.1
OPAL
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
ippl
src
Message
MsgBuffer.h
Go to the documentation of this file.
1
//
2
// Class MsgBuffer
3
// MsgBuffer class to allow serializing message objects into plain buffers
4
// to send directly with mpi calls or similar means
5
//
6
// Copyright (c) 2008 - 2020, Paul Scherrer Institut, Villigen PSI, Switzerland
7
// All rights reserved
8
//
9
// This file is part of OPAL.
10
//
11
// OPAL is free software: you can redistribute it and/or modify
12
// it under the terms of the GNU General Public License as published by
13
// the Free Software Foundation, either version 3 of the License, or
14
// (at your option) any later version.
15
//
16
// You should have received a copy of the GNU General Public License
17
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
18
//
19
#ifndef MSGBUFFER_H
20
#define MSGBUFFER_H
21
22
#include <algorithm>
23
#include <cstring>
24
#include <vector>
25
#include "
Message/Message.h
"
26
27
class
Format
;
28
29
class
MsgBuffer
{
30
public
:
31
// creates buffer with space to hold count messages of format f
32
MsgBuffer
(
Format
* f,
int
count,
int
offset = 0);
33
MsgBuffer
(
Format
* f,
char
* d,
int
size);
34
35
bool
add
(
Message
*);
36
Message
*
get
();
37
38
template
<
class
T>
39
void
get
(
T
& v) {
40
std::memcpy(&v,
data
.data() +
readpos
,
sizeof
(
T
));
41
readpos
+=
sizeof
(
T
);
42
}
43
44
template
<
class
T>
45
void
put
(
T
& v) {
46
std::memcpy(
data
.data() +
writepos
, &v,
sizeof
(
T
));
47
writepos
+=
sizeof
(
T
);
48
}
49
50
int
getSize
() {
51
return
writepos
;
52
}
53
54
void
*
getBuffer
() {
55
char
* data_ptr =
data
.empty() ?
static_cast<
char
*
>
(0) : &(
data
[0]);
56
return
data_ptr;
57
}
58
59
Format
*
getFormat
() {
60
return
format
;
61
}
62
63
~MsgBuffer
();
64
65
private
:
66
Format
*
format
;
67
unsigned
int
datasize
,
writepos
,
readpos
;
68
std::vector<char>
data
;
69
};
70
71
#endif
MsgBuffer::add
bool add(Message *)
Definition:
MsgBuffer.cpp:44
MsgBuffer::format
Format * format
Definition:
MsgBuffer.h:66
MsgBuffer::put
void put(T &v)
Definition:
MsgBuffer.h:45
Message
Definition:
Message.h:142
MsgBuffer::MsgBuffer
MsgBuffer(Format *f, int count, int offset=0)
Definition:
MsgBuffer.cpp:23
MsgBuffer::getBuffer
void * getBuffer()
Definition:
MsgBuffer.h:54
MsgBuffer::writepos
unsigned int writepos
Definition:
MsgBuffer.h:67
MsgBuffer::getFormat
Format * getFormat()
Definition:
MsgBuffer.h:59
MsgBuffer::getSize
int getSize()
Definition:
MsgBuffer.h:50
MsgBuffer::readpos
unsigned int readpos
Definition:
MsgBuffer.h:67
MsgBuffer::datasize
unsigned int datasize
Definition:
MsgBuffer.h:67
Attrib::Legacy::Distribution::T
Definition:
Distribution.h:171
MsgBuffer::~MsgBuffer
~MsgBuffer()
Definition:
MsgBuffer.cpp:40
Message.h
Format
Definition:
Format.h:27
MsgBuffer::data
std::vector< char > data
Definition:
MsgBuffer.h:68
MsgBuffer
Definition:
MsgBuffer.h:29
Generated on Tue Jul 2 2024 15:05:14 for OPAL (Object Oriented Parallel Accelerator Library) by
1.8.5