All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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,
102  );
103 
104  //- Construct given buffers
105  UOPstream(const int toProcNo, PstreamBuffers&);
106 
107 
108  //- Destructor
109  ~UOPstream();
110 
111 
112  // Member Functions
113 
114  // Inquiry
115 
116  //- Return flags of output stream
117  ios_base::fmtflags flags() const
118  {
119  return ios_base::fmtflags(0);
120  }
121 
122 
123  // Write functions
124 
125  //- Write given buffer to given processor
126  static bool write
127  (
128  const commsTypes commsType,
129  const int toProcNo,
130  const char* buf,
131  const std::streamsize bufSize,
132  const int tag = UPstream::msgType(),
133  const label communicator = 0
134  );
135 
136  //- Write character
137  Ostream& write(const char);
138 
139  //- Write character string
140  Ostream& write(const char*);
141 
142  //- Write word
143  Ostream& write(const word&);
144 
145  //- Write string
146  Ostream& write(const string&);
147 
148  //- Write verbatimString
149  Ostream& write(const verbatimString&);
150 
151  //- Write std::string surrounded by quotes.
152  // Optional write without quotes.
154  (
155  const std::string&,
156  const bool quoted=true
157  );
158 
159  //- Write int32_t
160  Ostream& write(const int32_t);
161 
162  //- Write int64_t
163  Ostream& write(const int64_t);
164 
165  //- Write uint32_t
166  Ostream& write(const uint32_t);
167 
168  //- Write uint64_t
169  Ostream& write(const uint64_t);
170 
171  //- Write floatScalar
172  Ostream& write(const floatScalar);
173 
174  //- Write doubleScalar
175  Ostream& write(const doubleScalar);
176 
177  //- Write longDoubleScalar
179 
180  //- Write binary block
181  Ostream& write(const char*, std::streamsize);
182 
183  //- Add indentation characters
184  void indent()
185  {}
186 
187 
188  // Stream state functions
189 
190  //- Flush stream
191  void flush()
192  {}
193 
194  //- Add newline and flush stream
195  void endl()
196  {}
197 
198  //- Get width of output field
199  int width() const
200  {
201  return 0;
202  }
203 
204  //- Set width of output field (and return old width)
205  int width(const int)
206  {
207  return 0;
208  }
209 
210  //- Get precision of output field
211  int precision() const
212  {
213  return 0;
214  }
215 
216  //- Set precision of output field (and return old precision)
217  int precision(const int)
218  {
219  return 0;
220  }
221 
222 
223  // Edit
224 
225  //- Set flags of stream
226  ios_base::fmtflags flags(const ios_base::fmtflags)
227  {
228  return ios_base::fmtflags(0);
229  }
230 
231 
232  // Print
233 
234  //- Print description of IOstream to Ostream
235  void print(Ostream&) const;
236 };
237 
238 
239 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
240 
241 } // End namespace Foam
242 
243 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 
245 #endif
246 
247 // ************************************************************************* //
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 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:116
void endl()
Add newline and flush stream.
Definition: UOPstream.H:194
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:183
~UOPstream()
Destructor.
Definition: UOPstream.C:125
Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: UOPstream.C:220
UOPstream(const commsTypes commsType, const int toProcNo, DynamicList< char > &sendBuf, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, const bool sendAtDestruct=true, streamFormat format=BINARY, versionNumber version=currentVersion)
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:210
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: UOPstream.C:313
int width() const
Get width of output field.
Definition: UOPstream.H:198
void flush()
Flush stream.
Definition: UOPstream.H:190
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
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.