unaligned access
[OpenFOAM-1.5.x.git] / src / OpenFOAM / db / IOstreams / Pstreams / IPstream.H
blobe609f97d9a7dc1847214dd722680021f3774d779
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 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
33     IPread.C
35 \*---------------------------------------------------------------------------*/
37 #include "Pstream.H"
39 #ifndef IPstream_H
40 #define IPstream_H
42 #include "Istream.H"
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 namespace Foam
49 /*---------------------------------------------------------------------------*\
50                            Class IPstream Declaration
51 \*---------------------------------------------------------------------------*/
53 class IPstream
55     public Pstream,
56     public Istream
58     // Private data
60         int fromProcNo_;
61         label messageSize_;
64     // Private member functions
66         //- Check the bufferPosition_ against messageSize_ for EOF
67         inline void checkEof();
69         //- Read a T from the transfer buffer
70         template<class T>
71         inline void readFromBuffer(T&);
73         //- Read data from the transfer buffer
74         inline void readFromBuffer(void* data, size_t count, size_t align);
77 public:
79     // Constructors
81         //- Construct given process index to read from and optional buffer size,
82         //  read format and IO version
83         IPstream
84         (
85             const commsTypes commsType,
86             const int fromProcNo,
87             const label bufSize = 0,
88             streamFormat format=BINARY,
89             versionNumber version=currentVersion
90         );
93     // Destructor
95         ~IPstream();
98     // Member functions
100         // Inquiry
102             //- Return flags of output stream
103             ios_base::fmtflags flags() const
104             {
105                 return ios_base::fmtflags(0);
106             }
109         // Read functions
111             //- Read into given buffer from given processor and return the
112             //  message size
113             static label read
114             (
115                 const commsTypes commsType,
116                 const int fromProcNo,
117                 char* buf,
118                 const std::streamsize bufSize
119             );
121             //- Non-blocking receives: wait until all have finished.
122             static void waitRequests();
124             //- Non-blocking receives: has request i finished?
125             static bool finishedRequest(const label i);
127             //- Return next token from stream
128             Istream& read(token&);
130             //- Read a character
131             Istream& read(char&);
133             //- Read a word
134             Istream& read(word&);
136             // Read a string (including enclosing double-quotes)
137             Istream& read(string&);
139             //- Read a label
140             Istream& read(label&);
142             //- Read a floatScalar
143             Istream& read(floatScalar&);
145             //- Read a doubleScalar
146             Istream& read(doubleScalar&);
148             //- Read binary block
149             Istream& read(char*, std::streamsize);
151             //- Rewind and return the stream so that it may be read again
152             Istream& rewind();
155         // Edit
157             //- Set flags of stream
158             ios_base::fmtflags flags(const ios_base::fmtflags)
159             {
160                 return ios_base::fmtflags(0);
161             }
164         // Print
166             //- Print description of IOstream to Ostream
167             void print(Ostream&) const;
171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 } // End namespace Foam
175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
177 #endif
179 // ************************************************************************* //