BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / IOstreams / Pstreams / UIPstream.H
blobdff96c4388c1c82dd11ab660aa6725fcea3033a2
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 Class
25     Foam::UIPstream
27 Description
28     Input inter-processor communications stream operating on external
29     buffer.
31 SourceFiles
32     UIPstream.C
34 \*---------------------------------------------------------------------------*/
36 #include "Pstream.H"
38 #ifndef UIPstream_H
39 #define UIPstream_H
41 #include "UPstream.H"
42 #include "Istream.H"
43 #include "PstreamBuffers.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 namespace Foam
50 /*---------------------------------------------------------------------------*\
51                            Class UIPstream Declaration
52 \*---------------------------------------------------------------------------*/
54 class UIPstream
56     public UPstream,
57     public Istream
59     // Private data
61         int fromProcNo_;
63         DynamicList<char>& externalBuf_;
65         label& externalBufPosition_;
67         const int tag_;
69         const bool clearAtEnd_;
71         label messageSize_;
74     // Private Member Functions
76         //- Check the bufferPosition against messageSize_ for EOF
77         inline void checkEof();
79         //- Read a T from the transfer buffer
80         template<class T>
81         inline void readFromBuffer(T&);
83         //- Read data from the transfer buffer
84         inline void readFromBuffer(void* data, size_t count, size_t align);
87 public:
89     // Constructors
91         //- Construct given process index to read from and optional buffer size,
92         //  read format and IO version
93         UIPstream
94         (
95             const commsTypes commsType,
96             const int fromProcNo,
97             DynamicList<char>& externalBuf,
98             label& externalBufPosition,
99             const int tag = UPstream::msgType(),
100             const bool clearAtEnd = false,   // destroy externalBuf if at end
101             streamFormat format=BINARY,
102             versionNumber version=currentVersion
103         );
105         //- Construct given buffers
106         UIPstream(const int fromProcNo, PstreamBuffers&);
109     //- Destructor
110     ~UIPstream();
113     // Member functions
115         // Inquiry
117             //- Return flags of output stream
118             ios_base::fmtflags flags() const
119             {
120                 return ios_base::fmtflags(0);
121             }
124         // Read functions
126             //- Read into given buffer from given processor and return the
127             //  message size
128             static label read
129             (
130                 const commsTypes commsType,
131                 const int fromProcNo,
132                 char* buf,
133                 const std::streamsize bufSize,
134                 const int tag = UPstream::msgType()
135             );
137             //- Return next token from stream
138             Istream& read(token&);
140             //- Read a character
141             Istream& read(char&);
143             //- Read a word
144             Istream& read(word&);
146             // Read a string (including enclosing double-quotes)
147             Istream& read(string&);
149             //- Read a label
150             Istream& read(label&);
152             //- Read a floatScalar
153             Istream& read(floatScalar&);
155             //- Read a doubleScalar
156             Istream& read(doubleScalar&);
158             //- Read binary block
159             Istream& read(char*, std::streamsize);
161             //- Rewind and return the stream so that it may be read again
162             Istream& rewind();
165         // Edit
167             //- Set flags of stream
168             ios_base::fmtflags flags(const ios_base::fmtflags)
169             {
170                 return ios_base::fmtflags(0);
171             }
174         // Print
176             //- Print description of IOstream to Ostream
177             void print(Ostream&) const;
181 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183 } // End namespace Foam
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
187 #endif
189 // ************************************************************************* //