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-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::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  //- Write given buffer to given processor
127  static bool write
128  (
129  const commsTypes commsType,
130  const int toProcNo,
131  const char* buf,
132  const std::streamsize bufSize,
133  const int tag = UPstream::msgType(),
134  const label communicator = 0
135  );
136 
137  //- Write character
138  Ostream& write(const char);
139 
140  //- Write character string
141  Ostream& write(const char*);
142 
143  //- Write word
144  Ostream& write(const word&);
145 
146  //- Write string
147  Ostream& write(const string&);
148 
149  //- Write verbatimString
150  Ostream& write(const verbatimString&);
151 
152  //- Write std::string surrounded by quotes.
153  // Optional write without quotes.
155  (
156  const std::string&,
157  const bool quoted=true
158  );
159 
160  //- Write int32_t
161  Ostream& write(const int32_t);
162 
163  //- Write int64_t
164  Ostream& write(const int64_t);
165 
166  //- Write uint32_t
167  Ostream& write(const uint32_t);
168 
169  //- Write uint64_t
170  Ostream& write(const uint64_t);
171 
172  //- Write floatScalar
173  Ostream& write(const floatScalar);
174 
175  //- Write doubleScalar
176  Ostream& write(const doubleScalar);
177 
178  //- Write longDoubleScalar
180 
181  //- Write binary block
182  Ostream& write(const char*, std::streamsize);
183 
184  //- Add indentation characters
185  void indent()
186  {}
187 
188 
189  // Stream state functions
190 
191  //- Flush stream
192  void flush()
193  {}
194 
195  //- Add newline and flush stream
196  void endl()
197  {}
198 
199  //- Get width of output field
200  int width() const
201  {
202  return 0;
203  }
204 
205  //- Set width of output field (and return old width)
206  int width(const int)
207  {
208  return 0;
209  }
210 
211  //- Get precision of output field
212  int precision() const
213  {
214  return 0;
215  }
216 
217  //- Set precision of output field (and return old precision)
218  int precision(const int)
219  {
220  return 0;
221  }
222 
223 
224  // Edit
225 
226  //- Set flags of stream
227  ios_base::fmtflags flags(const ios_base::fmtflags)
228  {
229  return ios_base::fmtflags(0);
230  }
231 
232 
233  // Print
234 
235  //- Print description of IOstream to Ostream
236  void print(Ostream&) const;
237 };
238 
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 } // End namespace Foam
243 
244 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
245 
246 #endif
247 
248 // ************************************************************************* //
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
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:195
static bool write(const commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label communicator=0)
Write given buffer to given processor.
Definition: UOPwrite.C:34
void indent()
Add indentation characters.
Definition: UOPstream.H:184
~UOPstream()
Destructor.
Definition: UOPstream.C:126
Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: UOPstream.C:221
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
int precision() const
Get precision of output field.
Definition: UOPstream.H:211
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: UOPstream.C:314
int width() const
Get width of output field.
Definition: UOPstream.H:199
void flush()
Flush stream.
Definition: UOPstream.H:191
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 verbatimStrings, derived from string.
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.