initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / db / IOstreams / Pstreams / IPstream.H
blob09db5931b8fad4a53e01857ab9419fac17931bd0
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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
25 Class
26     Foam::IPstream
28 Description
29     Input inter-processor communications stream.
31 SourceFiles
32     IPstream.C
34 \*---------------------------------------------------------------------------*/
36 #include "Pstream.H"
38 #ifndef IPstream_H
39 #define IPstream_H
41 #include "Istream.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 namespace Foam
48 /*---------------------------------------------------------------------------*\
49                            Class IPstream Declaration
50 \*---------------------------------------------------------------------------*/
52 class IPstream
54     public Pstream,
55     public Istream
57     // Private data
59         int fromProcNo_;
60         label messageSize_;
63     // Private member functions
65         //- Check the bufferPosition_ against messageSize_ for EOF
66         inline void checkEof();
68         //- Read a T from the transfer buffer
69         template<class T>
70         inline void readFromBuffer(T&);
72         //- Read data from the transfer buffer
73         inline void readFromBuffer(void* data, size_t count, size_t align);
76 public:
78     // Constructors
80         //- Construct given process index to read from and optional buffer size,
81         //  read format and IO version
82         IPstream
83         (
84             const commsTypes commsType,
85             const int fromProcNo,
86             const label bufSize = 0,
87             streamFormat format=BINARY,
88             versionNumber version=currentVersion
89         );
92     // Destructor
94         ~IPstream();
97     // Member functions
99         // Inquiry
101             //- Return flags of output stream
102             ios_base::fmtflags flags() const
103             {
104                 return ios_base::fmtflags(0);
105             }
108         // Read functions
110             //- Read into given buffer from given processor and return the
111             //  message size
112             static label read
113             (
114                 const commsTypes commsType,
115                 const int fromProcNo,
116                 char* buf,
117                 const std::streamsize bufSize
118             );
120             //- Non-blocking receives: wait until all have finished.
121             static void waitRequests();
123             //- Non-blocking receives: has request i finished?
124             static bool finishedRequest(const label i);
126             //- Return next token from stream
127             Istream& read(token&);
129             //- Read a character
130             Istream& read(char&);
132             //- Read a word
133             Istream& read(word&);
135             // Read a string (including enclosing double-quotes)
136             Istream& read(string&);
138             //- Read a label
139             Istream& read(label&);
141             //- Read a floatScalar
142             Istream& read(floatScalar&);
144             //- Read a doubleScalar
145             Istream& read(doubleScalar&);
147             //- Read binary block
148             Istream& read(char*, std::streamsize);
150             //- Rewind and return the stream so that it may be read again
151             Istream& rewind();
154         // Edit
156             //- Set flags of stream
157             ios_base::fmtflags flags(const ios_base::fmtflags)
158             {
159                 return ios_base::fmtflags(0);
160             }
163         // Print
165             //- Print description of IOstream to Ostream
166             void print(Ostream&) const;
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
172 } // End namespace Foam
174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
176 #endif
178 // ************************************************************************* //