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-2018 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 next token to stream
137  Ostream& write(const token&);
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 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  virtual Ostream& write(const int32_t);
161 
162  //- Write int64_t
163  Ostream& write(const int64_t);
164 
165  //- Write floatScalar
166  Ostream& write(const floatScalar);
167 
168  //- Write doubleScalar
169  Ostream& write(const doubleScalar);
170 
171  //- Write longDoubleScalar
173 
174  //- Write binary block
175  Ostream& write(const char*, std::streamsize);
176 
177  //- Add indentation characters
178  void indent()
179  {}
180 
181 
182  // Stream state functions
183 
184  //- Flush stream
185  void flush()
186  {}
187 
188  //- Add newline and flush stream
189  void endl()
190  {}
191 
192  //- Get width of output field
193  int width() const
194  {
195  return 0;
196  }
197 
198  //- Set width of output field (and return old width)
199  int width(const int)
200  {
201  return 0;
202  }
203 
204  //- Get precision of output field
205  int precision() const
206  {
207  return 0;
208  }
209 
210  //- Set precision of output field (and return old precision)
211  int precision(const int)
212  {
213  return 0;
214  }
215 
216 
217  // Edit
218 
219  //- Set flags of stream
220  ios_base::fmtflags flags(const ios_base::fmtflags)
221  {
222  return ios_base::fmtflags(0);
223  }
224 
225 
226  // Print
227 
228  //- Print description of IOstream to Ostream
229  void print(Ostream&) const;
230 };
231 
232 
233 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
234 
235 } // End namespace Foam
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 #endif
240 
241 // ************************************************************************* //
commsTypes commsType() const
Get the communications type of the stream.
Definition: UPstream.H:481
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
commsTypes
Types of communications.
Definition: UPstream.H:64
A token holds items read from Istream.
Definition: token.H:69
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:474
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:278
Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: UOPstream.C:230
int precision() const
Get precision of output field.
Definition: UOPstream.H:204
void endl()
Add newline and flush stream.
Definition: UOPstream.H:188
A class for handling words, derived from string.
Definition: word.H:59
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: UOPstream.H:116
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Output inter-processor communications stream operating on external buffer.
Definition: UOPstream.H:54
~UOPstream()
Destructor.
Definition: UOPstream.C:125
void flush()
Flush stream.
Definition: UOPstream.H:184
Database for solution data, solver performance and other reduced data.
Definition: data.H:52
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
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Helper class for allocating/freeing communicators.
Definition: UPstream.H:314
long double longDoubleScalar
Lang double precision floating point scalar type.
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
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
Version number type.
Definition: IOstream.H:96
int width() const
Get width of output field.
Definition: UOPstream.H:192
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: UOPstream.C:307
Inter-processor communications stream.
Definition: UPstream.H:58
void indent()
Add indentation characters.
Definition: UOPstream.H:177
Namespace for OpenFOAM.