UOPstream.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-2025 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::UOPstream
26 
27 Description
28  Output inter-processor communications stream operating on external
29  buffer.
30 
31 SourceFiles
32  UOPstream.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #include "Pstream.H"
37 
38 #ifndef UOPstream_H
39 #define UOPstream_H
40 
41 #include "UPstream.H"
42 #include "Ostream.H"
43 #include "DynamicList.H"
44 #include "PstreamBuffers.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class UOPstream Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class UOPstream
56 :
57  public UPstream,
58  public Ostream
59 {
60  // Private Data
61 
62  int toProcNo_;
63 
64  DynamicList<char>& sendBuf_;
65 
66  const int tag_;
67 
68  const label comm_;
69 
70  const bool sendAtDestruct_;
71 
72 
73  // Private Member Functions
74 
75  //- Write a T to the transfer buffer
76  template<class T>
77  inline void writeToBuffer(const T&);
78 
79  //- Write a char to the transfer buffer
80  inline void writeToBuffer(const char&);
81 
82  //- Write data to the transfer buffer
83  inline void writeToBuffer(const void* data, size_t count, size_t align);
84 
85 
86 public:
87 
88  // Constructors
89 
90  //- Construct given process index to send to and optional buffer size,
91  // write format and IO version
92  UOPstream
93  (
94  const commsTypes commsType,
95  const int toProcNo,
96  DynamicList<char>& sendBuf,
97  const int tag = UPstream::msgType(),
98  const label comm = UPstream::worldComm,
99  const bool sendAtDestruct = true,
100  const streamFormat format = BINARY,
102  const bool global = false
103  );
104 
105  //- Construct given buffers
106  UOPstream(const int toProcNo, PstreamBuffers&);
107 
108 
109  //- Destructor
110  ~UOPstream();
111 
112 
113  // Member Functions
114 
115  // Inquiry
116 
117  //- Return flags of output stream
118  ios_base::fmtflags flags() const
119  {
120  return ios_base::fmtflags(0);
121  }
122 
123 
124  // Write functions
125 
126  using Ostream::write;
127 
128  //- Write given buffer to given processor
129  static bool write
130  (
131  const commsTypes commsType,
132  const int toProcNo,
133  const char* buf,
134  const std::streamsize bufSize,
135  const int tag = UPstream::msgType(),
136  const label communicator = 0
137  );
138 
139  //- Write character
140  Ostream& write(const char);
141 
142  //- Write character string
143  Ostream& write(const char*);
144 
145  //- Write word
146  Ostream& write(const word&);
147 
148  //- Write string
149  Ostream& write(const string&);
150 
151  //- Write keyType
152  Ostream& write(const keyType&);
153 
154  //- Write verbatimString
155  Ostream& write(const verbatimString&);
156 
157  //- Write std::string surrounded by quotes.
158  // Optional write without quotes.
160  (
161  const std::string&,
162  const bool quoted=true
163  );
164 
165  //- Write int32_t
166  Ostream& write(const int32_t);
167 
168  //- Write int64_t
169  Ostream& write(const int64_t);
170 
171  //- Write uint32_t
172  Ostream& write(const uint32_t);
173 
174  //- Write uint64_t
175  Ostream& write(const uint64_t);
176 
177  //- Write floatScalar
178  Ostream& write(const floatScalar);
179 
180  //- Write doubleScalar
181  Ostream& write(const doubleScalar);
182 
183  //- Write longDoubleScalar
185 
186  //- Write binary block
187  Ostream& write(const char*, std::streamsize);
188 
189  //- Add indentation characters
190  void indent()
191  {}
192 
193 
194  // Stream state functions
195 
196  //- Flush stream
197  void flush()
198  {}
199 
200  //- Add newline and flush stream
201  void endl()
202  {}
203 
204  //- Get width of output field
205  int width() const
206  {
207  return 0;
208  }
209 
210  //- Set width of output field (and return old width)
211  int width(const int)
212  {
213  return 0;
214  }
215 
216  //- Get precision of output field
217  int precision() const
218  {
219  return 0;
220  }
221 
222  //- Set precision of output field (and return old precision)
223  int precision(const int)
224  {
225  return 0;
226  }
227 
228 
229  // Edit
230 
231  //- Set flags of stream
232  ios_base::fmtflags flags(const ios_base::fmtflags)
233  {
234  return ios_base::fmtflags(0);
235  }
236 
237 
238  // Print
239 
240  //- Print description of IOstream to Ostream
241  void print(Ostream&) const;
242 };
243 
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 } // End namespace Foam
248 
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 
251 #endif
252 
253 // ************************************************************************* //
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 Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
virtual Ostream & write(const token &)
Write token.
Definition: Ostream.C:51
Buffers for inter-processor communications streams (UOPstream, UIPstream).
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:58
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: UOPstream.H:117
void endl()
Add newline and flush stream.
Definition: UOPstream.H:200
void indent()
Add indentation characters.
Definition: UOPstream.H:189
~UOPstream()
Destructor.
Definition: UOPstream.C:126
Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: UOPstream.C:228
UOPstream(const commsTypes commsType, const int toProcNo, DynamicList< char > &sendBuf, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, const bool sendAtDestruct=true, const streamFormat format=BINARY, const versionNumber version=currentVersion, const bool global=false)
Construct given process index to send to and optional buffer size,.
Definition: UOPstream.C:84
virtual Ostream & write(const token &)
Write token.
Definition: Ostream.C:51
int precision() const
Get precision of output field.
Definition: UOPstream.H:216
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: UOPstream.C:321
int width() const
Get width of output field.
Definition: UOPstream.H:204
void flush()
Flush stream.
Definition: UOPstream.H:196
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 class for handling keywords in dictionaries.
Definition: keyType.H:69
A class for handling verbatimStrings, derived from string.
A class for handling words, derived from string.
Definition: word.H:63
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(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)
long double longDoubleScalar
Lang double precision floating point scalar type.