Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / db / IOstreams / Pstreams / IPstream.H
blob46fcd4c1d02176ca325654950cc4f55b18768f9c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::IPstream
27 Description
28     Input inter-processor communications stream.
30 SourceFiles
31     IPstream.C
33 \*---------------------------------------------------------------------------*/
35 #include "Pstream.H"
37 #ifndef IPstream_H
38 #define IPstream_H
40 #include "Istream.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 /*---------------------------------------------------------------------------*\
48                            Class IPstream Declaration
49 \*---------------------------------------------------------------------------*/
51 class IPstream
53     public Pstream,
54     public Istream
56     // Private data
58         //- ID of sending processor
59         int fromProcNo_;
61         //- Message size
62         label messageSize_;
65     // Private member functions
67         //- Check the bufferPosition_ against messageSize_ for EOF
68         inline void checkEof();
70         //- Read a T from the transfer buffer
71         template<class T>
72         inline void readFromBuffer(T&);
74         //- Read data from the transfer buffer
75         inline void readFromBuffer(void* data, size_t count, size_t align);
78 public:
80     // Constructors
82         //- Construct given process index to read from, optional buffer size,
83         //  read format and IO version
84         IPstream
85         (
86             const commsTypes commsType,
87             const int fromProcNo,
88             const label bufSize = 0,
89             streamFormat format = BINARY,
90             versionNumber version = currentVersion
91         );
94     // Destructor
96         ~IPstream();
99     // Member functions
101         // Inquiry
103             //- Return flags of output stream
104             ios_base::fmtflags flags() const
105             {
106                 return ios_base::fmtflags(0);
107             }
110         // Read functions
112             //- Read into given buffer from given processor and return the
113             //  message size
114             static label read
115             (
116                 const commsTypes commsType,
117                 const int fromProcNo,
118                 char* buf,
119                 const std::streamsize bufSize
120             );
122             //- Non-blocking receives: wait until all have finished.
123             static void waitRequests();
125             //- Non-blocking receives: has request i finished?
126             static bool finishedRequest(const label i);
128             //- Return next token from stream
129             Istream& read(token&);
131             //- Read a character
132             Istream& read(char&);
134             //- Read a word
135             Istream& read(word&);
137             // Read a string (including enclosing double-quotes)
138             Istream& read(string&);
140             //- Read a label
141             Istream& read(label&);
143             //- Read a floatScalar
144             Istream& read(floatScalar&);
146             //- Read a doubleScalar
147             Istream& read(doubleScalar&);
149             //- Read a longDoubleScalar
150             Istream& read(longDoubleScalar&);
152             //- Read binary block
153             Istream& read(char*, std::streamsize);
155             //- Rewind and return the stream so that it may be read again
156             Istream& rewind();
159         // Edit
161             //- Set flags of stream
162             ios_base::fmtflags flags(const ios_base::fmtflags)
163             {
164                 return ios_base::fmtflags(0);
165             }
168         // Print
170             //- Print description of IOstream to Ostream
171             void print(Ostream&) const;
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 } // End namespace Foam
179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
181 #endif
183 // ************************************************************************* //