1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Output inter-processor communications stream.
34 \*---------------------------------------------------------------------------*/
36 // intentionally outside include guards!
37 #include <OpenFOAM/Pstream.H>
42 #include <OpenFOAM/Ostream.H>
43 #include "OPstreamImpl.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 /*---------------------------------------------------------------------------*\
51 Class OPstream Declaration
52 \*---------------------------------------------------------------------------*/
61 static autoPtr<OPstreamImpl> impl_;
63 // Private member functions
65 //- Write a T to the transfer buffer
67 inline void writeToBuffer(const T&);
69 //- Write a char to the transfer buffer
70 inline void writeToBuffer(const char&);
72 //- Write data to the transfer buffer
73 inline void writeToBuffer(const void* data, size_t count, size_t align);
75 //- Fetches the PstreamImpl instance if necessary
76 static autoPtr<OPstreamImpl>& impl()
80 impl_ = OPstreamImpl::New();
97 //- Construct given process index to send to and optional buffer size,
98 // write format and IO version
101 const commsTypes commsType,
103 const label bufSize = 0,
104 streamFormat format=BINARY,
105 versionNumber version=currentVersion
118 //- Return flags of output stream
119 ios_base::fmtflags flags() const
121 return ios_base::fmtflags(0);
127 //- Write given buffer to given processor
130 const commsTypes commsType,
133 const std::streamsize bufSize
136 return impl()->write(commsType, toProcNo, buf, bufSize);
139 //- Non-blocking writes: wait until all have finished.
140 static void waitRequests()
142 impl()->waitRequests();
145 //- Non-blocking writes: has request i finished?
146 static bool finishedRequest(const label i)
148 return impl()->finishedRequest(i);
151 //- Write next token to stream
152 Ostream& write(const token&);
155 Ostream& write(const char);
157 //- Write character string
158 Ostream& write(const char*);
161 Ostream& write(const word&);
164 Ostream& write(const string&);
166 //- Write std::string surrounded by quotes.
167 // Optional write without quotes.
171 const bool quoted=true
175 Ostream& write(const label);
177 //- Write floatScalar
178 Ostream& write(const floatScalar);
180 //- Write doubleScalar
181 Ostream& write(const doubleScalar);
183 //- Write binary block
184 Ostream& write(const char*, std::streamsize);
186 //- Add indentation characters
191 // Stream state functions
197 //- Add newline and flush stream
201 //- Get width of output field
207 //- Set width of output field (and return old width)
213 //- Get precision of output field
214 int precision() const
219 //- Set precision of output field (and return old precision)
220 int precision(const int)
228 //- Set flags of stream
229 ios_base::fmtflags flags(const ios_base::fmtflags)
231 return ios_base::fmtflags(0);
237 //- Print description of IOstream to Ostream
238 void print(Ostream&) const;
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 } // End namespace Foam
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
250 // ************************ vim: set sw=4 sts=4 et: ************************ //