All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
106  );
107 
108  //- Construct given buffers
109  UIPstream(const int fromProcNo, PstreamBuffers&);
110 
111 
112  //- Destructor
113  ~UIPstream();
114 
115 
116  // Member Functions
117 
118  // Inquiry
119 
120  //- Return flags of output stream
121  ios_base::fmtflags flags() const
122  {
123  return ios_base::fmtflags(0);
124  }
125 
126 
127  // Read functions
128 
129  //- Read into given buffer from given processor and return the
130  // message size
131  static label read
132  (
133  const commsTypes commsType,
134  const int fromProcNo,
135  char* buf,
136  const std::streamsize bufSize,
137  const int tag = UPstream::msgType(),
138  const label communicator = 0
139  );
140 
141  //- Return next token from stream
142  Istream& read(token&);
143 
144  //- Read a character
145  Istream& read(char&);
146 
147  //- Read a word
148  Istream& read(word&);
149 
150  // Read a string (including enclosing double-quotes)
151  Istream& read(string&);
152 
153  //- Read an int32_t
154  Istream& read(int32_t&);
155 
156  //- Read an int64_t
157  Istream& read(int64_t&);
158 
159  //- Read a uint32_t
160  Istream& read(uint32_t&);
161 
162  //- Read a uint64_t
163  Istream& read(uint64_t&);
164 
165  //- Read a floatScalar
167 
168  //- Read a doubleScalar
170 
171  //- Read a longDoubleScalar
173 
174  //- Read binary block
175  Istream& read(char*, std::streamsize);
176 
177  //- Rewind and return the stream so that it may be read again
178  Istream& rewind();
179 
180 
181  // Edit
182 
183  //- Set flags of stream
184  ios_base::fmtflags flags(const ios_base::fmtflags)
185  {
186  return ios_base::fmtflags(0);
187  }
188 
189 
190  // Print
191 
192  //- Print description of IOstream to Ostream
193  void print(Ostream&) const;
194 };
195 
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 } // End namespace Foam
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #endif
204 
205 // ************************************************************************* //
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:374
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
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:120
Istream & rewind()
Rewind and return the stream so that it may be read again.
Definition: UIPstream.C:443
~UIPstream()
Destructor.
Definition: UIPstream.C:82
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:34
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:79
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: UIPstream.C:450
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
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.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
long double longDoubleScalar
Lang double precision floating point scalar type.