UIPstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2013 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::UIPstream
29 
30 Description
31  Input inter-processor communications stream operating on external
32  buffer.
33 
34 SourceFiles
35  UIPstream.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #include "Pstream.H"
40 
41 #ifndef UIPstream_H
42 #define UIPstream_H
43 
44 #include "UPstream.H"
45 #include "Istream.H"
46 #include "PstreamBuffers.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class UIPstream Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 class UIPstream
58 :
59  public UPstream,
60  public Istream
61 {
62  // Private Data
63 
64  int fromProcNo_;
65 
66  DynamicList<char>& externalBuf_;
67 
68  label& externalBufPosition_;
69 
70  const int tag_;
71 
72  const label comm_;
73 
74  const bool clearAtEnd_;
75 
76  int messageSize_;
77 
78 
79  // Private Member Functions
80 
81  //- Check the bufferPosition against messageSize_ for EOF
82  inline void checkEof();
83 
84  //- Prepare transfer buffer by adjusting alignment
85  inline void prepareBuffer(const size_t align);
86 
87  //- Read a T from the transfer buffer
88  template<class T>
89  inline void readFromBuffer(T& val);
90 
91  //- Read count bytes of data from the transfer buffer.
92  // Prior data alignment is done by prepareBuffer
93  inline void readFromBuffer(void* data, const size_t count);
94 
95  //- Read string length and its content.
96  inline Istream& readStringFromBuffer(std::string& str);
97 
98 
99 public:
100 
101  // Constructors
102 
103  //- Construct given process index to read from and optional buffer size,
104  // read format and IO version
105  UIPstream
106  (
107  const commsTypes commsType,
108  const int fromProcNo,
109  DynamicList<char>& externalBuf,
110  label& externalBufPosition,
111  const int tag = UPstream::msgType(),
112  const label comm = UPstream::worldComm,
113  const bool clearAtEnd = false, // destroy externalBuf if at end
116  );
117 
118  //- Construct given buffers
119  UIPstream(const int fromProcNo, PstreamBuffers&);
120 
121 
122  //- Destructor
123  ~UIPstream();
124 
125 
126  // Member Functions
127 
128  // Inquiry
129 
130  //- Return flags of output stream
131  ios_base::fmtflags flags() const
132  {
133  return ios_base::fmtflags(0);
134  }
135 
136 
137  // Read Functions
138 
139  //- Read into given buffer from given processor and return the
140  // message size
141  static label read
142  (
143  const commsTypes commsType,
144  const int fromProcNo,
145  char* buf,
146  const std::streamsize bufSize,
147  const int tag = UPstream::msgType(),
148  const label communicator = 0
149  );
150 
151  //- Return next token from stream
152  Istream& read(token& t);
153 
154  //- Read a character
155  Istream& read(char& c);
156 
157  //- Read a word
158  Istream& read(word& str);
159 
160  // Read a string
161  Istream& read(string& str);
162 
163  //- Read a label
164  Istream& read(label& val);
165 
166  //- Read a floatScalar
167  Istream& read(floatScalar& val);
168 
169  //- Read a doubleScalar
170  Istream& read(doubleScalar& val);
171 
172  //- Read binary block with 8-byte alignment.
173  Istream& read(char* data, std::streamsize count);
174 
175  //- Low-level raw binary read
176  Istream& readRaw(char* data, std::streamsize count);
177 
178  //- Start of low-level raw binary read
179  bool beginRawRead();
180 
181  //- End of low-level raw binary read
182  bool endRawRead()
183  {
184  return true;
185  }
186 
187  //- Rewind the stream so that it may be read again
188  void rewind();
189 
190 
191  // Edit
192 
193  //- Set flags of stream
194  ios_base::fmtflags flags(const ios_base::fmtflags)
195  {
196  return ios_base::fmtflags(0);
197  }
198 
199 
200  // Print
201 
202  //- Print stream description to Ostream
203  void print(Ostream& os) const;
204 };
205 
206 
207 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 
209 } // End namespace Foam
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
213 #endif
214 
215 // ************************************************************************* //
Foam::UIPstream::flags
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: UIPstream.H:130
Foam::doubleScalar
double doubleScalar
A typedef for double.
Definition: scalarFwd.H:48
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
UPstream.H
Foam::DynamicList< char >
Foam::floatScalar
float floatScalar
A typedef for float.
Definition: scalarFwd.H:45
Foam::PstreamBuffers
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Definition: PstreamBuffers.H:88
Foam::UIPstream::rewind
void rewind()
Rewind the stream so that it may be read again.
Definition: UIPstream.C:414
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:289
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:168
Foam::token
A token holds an item read from Istream.
Definition: token.H:69
Foam::UIPstream::read
static label read(const commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Read into given buffer from given processor and return the.
Definition: UIPread.C:81
Foam::UPstream
Inter-processor communications stream.
Definition: UPstream.H:61
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::UPstream::commsType
commsTypes commsType() const
Get the communications type of the stream.
Definition: UPstream.H:499
Foam::UIPstream::~UIPstream
~UIPstream()
Destructor.
Definition: UIPstream.C:139
Istream.H
Foam::UIPstream::print
void print(Ostream &os) const
Print stream description to Ostream.
Definition: UIPstream.C:420
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:341
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Pstream.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::UIPstream::readRaw
Istream & readRaw(char *data, std::streamsize count)
Low-level raw binary read.
Definition: UIPstream.C:387
Foam::IOstreamOption::BINARY
"binary"
Definition: IOstreamOption.H:73
Foam::UPstream::msgType
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:492
Foam::UPstream::commsTypes
commsTypes
Types of communications.
Definition: UPstream.H:66
Foam::UIPstream::endRawRead
bool endRawRead()
End of low-level raw binary read.
Definition: UIPstream.H:181
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
Foam::UPstream::worldComm
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:285
Foam::UIPstream::flags
ios_base::fmtflags flags(const ios_base::fmtflags)
Set flags of stream.
Definition: UIPstream.H:193
PstreamBuffers.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::UIPstream::UIPstream
UIPstream(const commsTypes commsType, const int fromProcNo, DynamicList< char > &externalBuf, label &externalBufPosition, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, const bool clearAtEnd=false, streamFormat format=BINARY, versionNumber version=currentVersion)
Construct given process index to read from and optional buffer size,.
Definition: UIPread.C:36
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::UIPstream
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:56
Foam::UIPstream::beginRawRead
bool beginRawRead()
Start of low-level raw binary read.
Definition: UIPstream.C:398
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:54