Loading...
Searching...
No Matches
communications_buffers.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_COMMUNICATIONS_BUFFERS_HPP__
26#define __BITPIT_COMMUNICATIONS_BUFFERS_HPP__
27
28#include <vector>
29
30#include "bitpit_containers.hpp"
31
32// Declarations of the stream operators
33namespace bitpit{
34 class SendBuffer;
35 class RecvBuffer;
36};
37
38// Declaration of the communications buffers
39namespace bitpit {
40
41class DataCommunicator;
42
43typedef OBinaryStream RawSendBuffer;
44typedef IBinaryStream RawRecvBuffer;
45
46template<typename T>
47SendBuffer & operator<<(SendBuffer &buffer, const T &value);
48
49template<typename T>
50RecvBuffer & operator>>(RecvBuffer &buffer, T &value);
51
59template<typename RawBufferType>
61{
62
63public:
64 CommunicationBuffer(size_t size = 0, bool doubleBuffer = false);
65
66 size_t getSize() const;
67 void setSize(size_t size);
68
69 bool seekg (size_t pos);
70 std::ifstream::pos_type tellg(void) const;
71
72 bool isDouble() const;
73
74protected:
75 RawBufferType & getFront();
76 RawBufferType & getBack();
77
78 void swap();
79
80 std::vector<RawBufferType> & getBuffers();
81 const std::vector<RawBufferType> & getBuffers() const;
82
83private:
84 std::vector<RawBufferType> m_buffers;
85 RawBufferType *m_front;
86 RawBufferType *m_back;
87
88};
89
90class SendBuffer : public CommunicationBuffer<RawSendBuffer>
91{
92 friend DataCommunicator;
93
94 template<typename T>
95 friend SendBuffer & (operator<<) (SendBuffer &buffer, const T &value);
96
97public:
98 SendBuffer(size_t size = 0, bool doubleBuffer = false);
99
100 void squeeze();
101
102 void write(const char *data, std::size_t size);
103
104};
105
106class RecvBuffer : public CommunicationBuffer<RawRecvBuffer>
107{
108 friend DataCommunicator;
109
110 template<typename T>
111 friend RecvBuffer & (operator>>) (RecvBuffer &buffer, T &value);
112
113public:
114 RecvBuffer(size_t size = 0, bool doubleBuffer = false);
115
116 void read(char *data, std::size_t size);
117
118};
119
120}
121
122#include "communications_buffers.tpp"
123
124# endif
Buffer to be used for data communications.
std::ifstream::pos_type tellg(void) const
CommunicationBuffer(size_t size=0, bool doubleBuffer=false)
std::vector< RawBufferType > & getBuffers()
The DataCommunicator class provides the infrastructure needed to exchange data among processes.
Buffer to be used for receive communications.
RecvBuffer(size_t size=0, bool doubleBuffer=false)
void read(char *data, std::size_t size)
Buffer to be used for send communications.
void write(const char *data, std::size_t size)
SendBuffer(size_t size=0, bool doubleBuffer=false)
std::ostream & operator<<(std::ostream &, const std::vector< T > &)
--- layout: doxygen_footer ---