UOPstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2014 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 binary block
172  Ostream& write(const char*, std::streamsize);
173 
174  //- Add indentation characters
175  void indent()
176  {}
177 
178 
179  // Stream state functions
180 
181  //- Flush stream
182  void flush()
183  {}
184 
185  //- Add newline and flush stream
186  void endl()
187  {}
188 
189  //- Get width of output field
190  int width() const
191  {
192  return 0;
193  }
194 
195  //- Set width of output field (and return old width)
196  int width(const int)
197  {
198  return 0;
199  }
200 
201  //- Get precision of output field
202  int precision() const
203  {
204  return 0;
205  }
206 
207  //- Set precision of output field (and return old precision)
208  int precision(const int)
209  {
210  return 0;
211  }
212 
213 
214  // Edit
215 
216  //- Set flags of stream
217  ios_base::fmtflags flags(const ios_base::fmtflags)
218  {
219  return ios_base::fmtflags(0);
220  }
221 
222 
223  // Print
224 
225  //- Print description of IOstream to Ostream
226  void print(Ostream&) const;
227 };
228 
229 
230 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
231 
232 } // End namespace Foam
233 
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
235 
236 #endif
237 
238 // ************************************************************************* //
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
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
int precision() const
Get precision of output field.
Definition: UOPstream.H:201
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: UOPstream.C:299
commsTypes
Types of communications.
Definition: UPstream.H:64
A token holds items read from Istream.
Definition: token.H:69
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: UOPstream.H:116
static int & msgType()
Message tag of standard messages.
Definition: UPstream.H:464
static label worldComm
Default communicator (all processors)
Definition: UPstream.H:274
Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: UOPstream.C:230
int width() const
Get width of output field.
Definition: UOPstream.H:189
void endl()
Add newline and flush stream.
Definition: UOPstream.H:185
A class for handling words, derived from string.
Definition: word.H:59
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:49
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:49
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: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:181
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:310
commsTypes commsType() const
Get the communications type of the stream.
Definition: UPstream.H:471
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
Inter-processor communications stream.
Definition: UPstream.H:58
void indent()
Add indentation characters.
Definition: UOPstream.H:174
Namespace for OpenFOAM.