UIPstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  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  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::UIPstream
26 
27 Description
28  Input inter-processor communications stream operating on external
29  buffer.
30 
31 SourceFiles
32  UIPstream.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #include "Pstream.H"
37 
38 #ifndef UIPstream_H
39 #define UIPstream_H
40 
41 #include "UPstream.H"
42 #include "Istream.H"
43 #include "PstreamBuffers.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class UIPstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class UIPstream
55 :
56  public UPstream,
57  public Istream
58 {
59  // Private Data
60 
61  int fromProcNo_;
62 
63  DynamicList<char>& externalBuf_;
64 
65  label& externalBufPosition_;
66 
67  const int tag_;
68 
69  const label comm_;
70 
71  const bool clearAtEnd_;
72 
73  int messageSize_;
74 
75 
76  // Private Member Functions
77 
78  //- Check the bufferPosition against messageSize_ for EOF
79  inline void checkEof();
80 
81  //- Read a T from the transfer buffer
82  template<class T>
83  inline void readFromBuffer(T&);
84 
85  //- Read data from the transfer buffer
86  inline void readFromBuffer(void* data, size_t count, size_t align);
87 
88 
89 public:
90 
91  // Constructors
92 
93  //- Construct given process index to read from and optional buffer size,
94  // read format and IO version
95  UIPstream
96  (
97  const commsTypes commsType,
98  const int fromProcNo,
99  DynamicList<char>& externalBuf,
100  label& externalBufPosition,
101  const int tag = UPstream::msgType(),
102  const label comm = UPstream::worldComm,
103  const bool clearAtEnd = false, // destroy externalBuf if at end
104  const streamFormat format = BINARY,
106  const bool global = false
107  );
108 
109  //- Construct given buffers
110  UIPstream(const int fromProcNo, PstreamBuffers&);
111 
112 
113  //- Destructor
114  ~UIPstream();
115 
116 
117  // Member Functions
118 
119  // Inquiry
120 
121  //- Return flags of output stream
122  ios_base::fmtflags flags() const
123  {
124  return ios_base::fmtflags(0);
125  }
126 
127 
128  // Read functions
129 
130  //- Read into given buffer from given processor and return the
131  // message size
132  static label read
133  (
134  const commsTypes commsType,
135  const int fromProcNo,
136  char* buf,
137  const std::streamsize bufSize,
138  const int tag = UPstream::msgType(),
139  const label communicator = 0
140  );
141 
142  //- Return next token from stream
143  Istream& read(token&);
144 
145  //- Read a character
146  Istream& read(char&);
147 
148  //- Read a word
149  Istream& read(word&);
150 
151  // Read a string (including enclosing double-quotes)
152  Istream& read(string&);
153 
154  //- Read an int32_t
155  Istream& read(int32_t&);
156 
157  //- Read an int64_t
158  Istream& read(int64_t&);
159 
160  //- Read a uint32_t
161  Istream& read(uint32_t&);
162 
163  //- Read a uint64_t
164  Istream& read(uint64_t&);
165 
166  //- Read a floatScalar
168 
169  //- Read a doubleScalar
171 
172  //- Read a longDoubleScalar
174 
175  //- Read binary block
176  Istream& read(char*, std::streamsize);
177 
178  //- Rewind and return the stream so that it may be read again
179  Istream& rewind();
180 
181 
182  // Edit
183 
184  //- Set flags of stream
185  ios_base::fmtflags flags(const ios_base::fmtflags)
186  {
187  return ios_base::fmtflags(0);
188  }
189 
190 
191  // Print
192 
193  //- Print description of IOstream to Ostream
194  void print(Ostream&) const;
195 };
196 
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace Foam
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 #endif
205 
206 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
bool global() const
Return global state.
Definition: IOstream.H:438
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Input inter-processor communications stream operating on external buffer.
Definition: UIPstream.H:57
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: UIPstream.H:121
Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: UIPstream.C:443
~UIPstream()
Destructor.
Definition: UIPstream.C:82
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:80
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: UIPstream.C:455
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, const streamFormat format=BINARY, const versionNumber version=currentVersion, const bool global=false)
Construct given process index to read from and optional buffer size,.
Definition: UIPread.C:34
Inter-processor communications stream.
Definition: UPstream.H:59
commsTypes
Types of communications.
Definition: UPstream.H:65
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:278
commsTypes commsType() const
Get the communications type of the stream.
Definition: UPstream.H:483
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:476
A token holds items read from Istream.
Definition: token.H:73
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
void T(LagrangianPatchField< Type > &f, const LagrangianPatchField< Type > &f1)
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
long double longDoubleScalar
Lang double precision floating point scalar type.