Loading...
Searching...
No Matches
communications_buffers.tpp
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_TPP__
26#define __BITPIT_COMMUNICATIONS_BUFFERS_TPP__
27
28namespace bitpit {
29
37template<typename T>
38bitpit::SendBuffer & operator<<(bitpit::SendBuffer &buffer, const T &value)
39{
40 buffer.getFront() << value;
41
42 return buffer;
43}
44
52template<typename T>
53bitpit::RecvBuffer & operator>>(bitpit::RecvBuffer &buffer, T &value)
54{
55 buffer.getFront() >> value;
56
57 return buffer;
58}
59
63template<typename RawBufferType>
65{
66 // Create the buffers
67 m_buffers.emplace_back(size);
68 if (doubleBuffer) {
69 m_buffers.emplace_back(size);
70 }
71
72 // Assign the front and back buffers
73 m_front = &m_buffers[doubleBuffer ? 1 : 0];
74 m_back = &m_buffers[0];
82template<typename RawBufferType>
84{
85 return m_front->getSize();
86}
87
93template<typename RawBufferType>
95{
96 for (RawBufferType & buffer : m_buffers) {
97 buffer.setSize(size);
98 }
99}
100
107template<typename RawBufferType>
109{
110 return m_front->seekg(pos);
111}
112
118template<typename RawBufferType>
119std::ifstream::pos_type CommunicationBuffer<RawBufferType>::tellg() const
120{
121 return m_front->tellg();
122}
123
129template<typename RawBufferType>
131{
132 return (m_buffers.size() == 2);
133}
134
140template<typename RawBufferType>
142{
143 return *m_front;
144}
145
151template<typename RawBufferType>
153{
154 return *m_back;
155}
156
160template<typename RawBufferType>
162{
163 std::swap(m_front, m_back);
164}
165
169template<typename RawBufferType>
171{
172 return m_buffers;
173}
174
178template<typename RawBufferType>
179const std::vector<RawBufferType> & CommunicationBuffer<RawBufferType>::getBuffers() const
180{
181 return m_buffers;
182}
183
184}
185
186# endif
std::ifstream::pos_type tellg(void) const
CommunicationBuffer(size_t size=0, bool doubleBuffer=false)
std::vector< RawBufferType > & getBuffers()
Buffer to be used for receive communications.
Buffer to be used for send communications.
Logger & operator<<(Logger &logger, LoggerManipulator< T > &&m)
Definition logger.hpp:367
--- layout: doxygen_footer ---