OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

IPstream.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::IPstream
00027 
00028 Description
00029     Input inter-processor communications stream.
00030 
00031 SourceFiles
00032     IPstream.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #include "Pstream.H"
00037 
00038 #ifndef IPstream_H
00039 #define IPstream_H
00040 
00041 #include "Istream.H"
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 /*---------------------------------------------------------------------------*\
00049                            Class IPstream Declaration
00050 \*---------------------------------------------------------------------------*/
00051 
00052 class IPstream
00053 :
00054     public Pstream,
00055     public Istream
00056 {
00057     // Private data
00058 
00059         int fromProcNo_;
00060         label messageSize_;
00061 
00062 
00063     // Private member functions
00064 
00065         //- Check the bufferPosition_ against messageSize_ for EOF
00066         inline void checkEof();
00067 
00068         //- Read a T from the transfer buffer
00069         template<class T>
00070         inline void readFromBuffer(T&);
00071 
00072         //- Read data from the transfer buffer
00073         inline void readFromBuffer(void* data, size_t count, size_t align);
00074 
00075 
00076 public:
00077 
00078     // Constructors
00079 
00080         //- Construct given process index to read from and optional buffer size,
00081         //  read format and IO version
00082         IPstream
00083         (
00084             const commsTypes commsType,
00085             const int fromProcNo,
00086             const label bufSize = 0,
00087             streamFormat format=BINARY,
00088             versionNumber version=currentVersion
00089         );
00090 
00091 
00092     // Destructor
00093 
00094         ~IPstream();
00095 
00096 
00097     // Member functions
00098 
00099         // Inquiry
00100 
00101             //- Return flags of output stream
00102             ios_base::fmtflags flags() const
00103             {
00104                 return ios_base::fmtflags(0);
00105             }
00106 
00107 
00108         // Read functions
00109 
00110             //- Read into given buffer from given processor and return the
00111             //  message size
00112             static label read
00113             (
00114                 const commsTypes commsType,
00115                 const int fromProcNo,
00116                 char* buf,
00117                 const std::streamsize bufSize
00118             );
00119 
00120             //- Non-blocking receives: wait until all have finished.
00121             static void waitRequests();
00122 
00123             //- Non-blocking receives: has request i finished?
00124             static bool finishedRequest(const label i);
00125 
00126             //- Return next token from stream
00127             Istream& read(token&);
00128 
00129             //- Read a character
00130             Istream& read(char&);
00131 
00132             //- Read a word
00133             Istream& read(word&);
00134 
00135             // Read a string (including enclosing double-quotes)
00136             Istream& read(string&);
00137 
00138             //- Read a label
00139             Istream& read(label&);
00140 
00141             //- Read a floatScalar
00142             Istream& read(floatScalar&);
00143 
00144             //- Read a doubleScalar
00145             Istream& read(doubleScalar&);
00146 
00147             //- Read binary block
00148             Istream& read(char*, std::streamsize);
00149 
00150             //- Rewind and return the stream so that it may be read again
00151             Istream& rewind();
00152 
00153 
00154         // Edit
00155 
00156             //- Set flags of stream
00157             ios_base::fmtflags flags(const ios_base::fmtflags)
00158             {
00159                 return ios_base::fmtflags(0);
00160             }
00161 
00162 
00163         // Print
00164 
00165             //- Print description of IOstream to Ostream
00166             void print(Ostream&) const;
00167 };
00168 
00169 
00170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00171 
00172 } // End namespace Foam
00173 
00174 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00175 
00176 #endif
00177 
00178 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd