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 Input inter-processor communications stream.
34 \*---------------------------------------------------------------------------*/
36 // intentionally outside include guards!
37 #include <OpenFOAM/Pstream.H>
42 #include <OpenFOAM/Istream.H>
43 #include "IPstreamImpl.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 /*---------------------------------------------------------------------------*\
51 Class IPstream Declaration
52 \*---------------------------------------------------------------------------*/
64 static autoPtr<IPstreamImpl> impl_;
67 // Private member functions
69 //- Check the bufferPosition_ against messageSize_ for EOF
70 inline void checkEof();
72 //- Read a T from the transfer buffer
74 inline void readFromBuffer(T&);
76 //- Read data from the transfer buffer
77 inline void readFromBuffer(void* data, size_t count, size_t align);
79 //- Fetches the IPstreamImpl instance if necessary
80 static autoPtr<IPstreamImpl>& impl()
84 impl_ = IPstreamImpl::New();
93 //- Construct given process index to read from and optional buffer size,
94 // read format and IO version
97 const commsTypes commsType,
99 const label bufSize = 0,
100 streamFormat format=BINARY,
101 versionNumber version=currentVersion
114 //- Return flags of output stream
115 ios_base::fmtflags flags() const
117 return ios_base::fmtflags(0);
123 //- Read into given buffer from given processor and return the
127 const commsTypes commsType,
128 const int fromProcNo,
130 const std::streamsize bufSize
133 return impl()->read(commsType, fromProcNo, buf, bufSize);
136 //- Non-blocking receives: wait until all have finished.
137 static void waitRequests()
139 impl()->waitRequests();
142 //- Non-blocking receives: has request i finished?
143 static bool finishedRequest(const label i)
145 return impl()->finishedRequest(i);
148 //- Return next token from stream
149 Istream& read(token&);
152 Istream& read(char&);
155 Istream& read(word&);
157 // Read a string (including enclosing double-quotes)
158 Istream& read(string&);
161 Istream& read(label&);
163 //- Read a floatScalar
164 Istream& read(floatScalar&);
166 //- Read a doubleScalar
167 Istream& read(doubleScalar&);
169 //- Read binary block
170 Istream& read(char*, std::streamsize);
172 //- Rewind and return the stream so that it may be read again
178 //- Set flags of stream
179 ios_base::fmtflags flags(const ios_base::fmtflags)
181 return ios_base::fmtflags(0);
187 //- Print description of IOstream to Ostream
188 void print(Ostream&) const;
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 } // End namespace Foam
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 // ************************ vim: set sw=4 sts=4 et: ************************ //