OPAL (Object Oriented Parallel Accelerator Library)
2.2.0
OPAL
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
ippl
src
Message
Formatter.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
/***************************************************************************
3
*
4
* The IPPL Framework
5
*
6
*
7
* Visit http://people.web.psi.ch/adelmann/ for more details
8
*
9
***************************************************************************/
10
11
#ifndef FORMATTER_H
12
#define FORMATTER_H
13
14
#include "
Message/Message.h
"
15
#include <cstring>
16
#include <vector>
17
#include <algorithm>
18
19
/*
20
* Format and MsgBuffer class to allow serializing message objects into plain buffers
21
* to send directly with mpi calls or similar means
22
*/
23
24
class
Format
25
{
26
public
:
27
Format
(
Message
*);
28
unsigned
int
getItemCount
()
29
{
30
return
items
;
31
}
32
unsigned
int
getSize
()
33
{
34
return
size
;
35
}
36
unsigned
int
getFormatSize
()
37
{
38
return
2*
items
*
sizeof
(int);
39
}
40
unsigned
int
getItemElems
(
int
i)
41
{
42
return
format_array
[2*i+0];
43
}
44
unsigned
int
getItemBytes
(
int
i)
45
{
46
return
format_array
[2*i+1];
47
}
48
49
void
print
();
50
51
private
:
52
unsigned
int
items
,
size
;
53
std::vector<unsigned int>
format_array
;
54
};
55
56
57
class
MsgBuffer
58
{
59
public
:
60
//creates buffer with space to hold count messages of format f
61
MsgBuffer
(
Format
*f,
int
count,
int
offset = 0);
62
MsgBuffer
(
Format
*f,
char
* d,
int
size);
63
64
bool
add
(
Message
*);
65
Message
*
get
();
66
67
template
<
class
T>
68
void
get
(
T
&v)
69
{
70
std::memcpy(&v,
data
.data()+
readpos
,
sizeof
(
T
));
71
readpos
+=
sizeof
(
T
);
72
}
73
74
template
<
class
T>
75
void
put
(
T
&v)
76
{
77
std::memcpy(
data
.data()+
writepos
, &v,
sizeof
(
T
));
78
writepos
+=
sizeof
(
T
);
79
}
80
81
int
getSize
()
82
{
83
return
writepos
;
84
}
85
void
*
getBuffer
()
86
{
87
return
data
.data();
88
}
89
90
Format
*
getFormat
() {
return
format
; }
91
92
~MsgBuffer
();
93
private
:
94
Format
*
format
;
95
unsigned
int
datasize
,
writepos
,
readpos
;
96
std::vector<char>
data
;
97
};
98
99
#endif // FORMATTER_H
Format::getSize
unsigned int getSize()
Definition:
Formatter.h:32
Format::getFormatSize
unsigned int getFormatSize()
Definition:
Formatter.h:36
MsgBuffer::getSize
int getSize()
Definition:
Formatter.h:81
Format::Format
Format(Message *)
Definition:
Formatter.cpp:3
Format::items
unsigned int items
Definition:
Formatter.h:52
T
Definition:
rbendmap.h:8
Message
Definition:
Message.h:150
MsgBuffer::getBuffer
void * getBuffer()
Definition:
Formatter.h:85
Format
Definition:
Formatter.h:24
MsgBuffer::data
std::vector< char > data
Definition:
Formatter.h:96
Format::size
unsigned int size
Definition:
Formatter.h:52
Format::format_array
std::vector< unsigned int > format_array
Definition:
Formatter.h:53
MsgBuffer::~MsgBuffer
~MsgBuffer()
Definition:
Formatter.cpp:45
Format::getItemCount
unsigned int getItemCount()
Definition:
Formatter.h:28
MsgBuffer::readpos
unsigned int readpos
Definition:
Formatter.h:95
Format::print
void print()
Definition:
Formatter.cpp:18
Format::getItemBytes
unsigned int getItemBytes(int i)
Definition:
Formatter.h:44
MsgBuffer
Definition:
Formatter.h:57
MsgBuffer::getFormat
Format * getFormat()
Definition:
Formatter.h:90
MsgBuffer::format
Format * format
Definition:
Formatter.h:94
MsgBuffer::writepos
unsigned int writepos
Definition:
Formatter.h:95
MsgBuffer::datasize
unsigned int datasize
Definition:
Formatter.h:95
Message.h
Format::getItemElems
unsigned int getItemElems(int i)
Definition:
Formatter.h:40
MsgBuffer::MsgBuffer
MsgBuffer(Format *f, int count, int offset=0)
Definition:
Formatter.cpp:28
MsgBuffer::add
bool add(Message *)
Definition:
Formatter.cpp:49
MsgBuffer::put
void put(T &v)
Definition:
Formatter.h:75
Generated on Sat Jan 4 2020 14:47:37 for OPAL (Object Oriented Parallel Accelerator Library) by
1.8.5