FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::IPstream
00026 
00027 Description
00028     Input inter-processor communications stream.
00029 
00030 SourceFiles
00031     IPstream.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 // intentionally outside include guards!
00036 #include <OpenFOAM/Pstream.H>
00037 
00038 #ifndef IPstream_H
00039 #define IPstream_H
00040 
00041 #include <OpenFOAM/Istream.H>
00042 #include "IPstreamImpl.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 /*---------------------------------------------------------------------------*\
00050                            Class IPstream Declaration
00051 \*---------------------------------------------------------------------------*/
00052 
00053 class IPstream
00054 :
00055     public Pstream,
00056     public Istream
00057 {
00058     // Private data
00059 
00060         int fromProcNo_;
00061         label messageSize_;
00062 
00063         static autoPtr<IPstreamImpl> impl_;
00064 
00065 
00066     // Private member functions
00067 
00068         //- Check the bufferPosition_ against messageSize_ for EOF
00069         inline void checkEof();
00070 
00071         //- Read a T from the transfer buffer
00072         template<class T>
00073         inline void readFromBuffer(T&);
00074 
00075         //- Read data from the transfer buffer
00076         inline void readFromBuffer(void* data, size_t count, size_t align);
00077 
00078         //- Fetches the IPstreamImpl instance if necessary
00079         static autoPtr<IPstreamImpl>& impl()
00080         {
00081             if(!impl_.valid())
00082             {
00083                 impl_ = IPstreamImpl::New();
00084             }
00085             return impl_;
00086         }
00087 
00088 public:
00089 
00090     // Constructors
00091 
00092         //- Construct given process index to read from and optional buffer size,
00093         //  read format and IO version
00094         IPstream
00095         (
00096             const commsTypes commsType,
00097             const int fromProcNo,
00098             const label bufSize = 0,
00099             streamFormat format=BINARY,
00100             versionNumber version=currentVersion
00101         );
00102 
00103 
00104     // Destructor
00105 
00106         ~IPstream();
00107 
00108 
00109     // Member functions
00110 
00111         // Inquiry
00112 
00113             //- Return flags of output stream
00114             ios_base::fmtflags flags() const
00115             {
00116                 return ios_base::fmtflags(0);
00117             }
00118 
00119 
00120         // Read functions
00121 
00122             //- Read into given buffer from given processor and return the
00123             //  message size
00124             static label read
00125             (
00126                 const commsTypes commsType,
00127                 const int fromProcNo,
00128                 char* buf,
00129                 const std::streamsize bufSize
00130             )
00131             {
00132                 return impl()->read(commsType, fromProcNo, buf, bufSize);
00133             }
00134 
00135             //- Non-blocking receives: wait until all have finished.
00136             static void waitRequests()
00137             {
00138                 impl()->waitRequests();
00139             }
00140 
00141             //- Non-blocking receives: has request i finished?
00142             static bool finishedRequest(const label i)
00143             {
00144                 return impl()->finishedRequest(i);
00145             }
00146 
00147             //- Return next token from stream
00148             Istream& read(token&);
00149 
00150             //- Read a character
00151             Istream& read(char&);
00152 
00153             //- Read a word
00154             Istream& read(word&);
00155 
00156             // Read a string (including enclosing double-quotes)
00157             Istream& read(string&);
00158 
00159             //- Read a label
00160             Istream& read(label&);
00161 
00162             //- Read a floatScalar
00163             Istream& read(floatScalar&);
00164 
00165             //- Read a doubleScalar
00166             Istream& read(doubleScalar&);
00167 
00168             //- Read binary block
00169             Istream& read(char*, std::streamsize);
00170 
00171             //- Rewind and return the stream so that it may be read again
00172             Istream& rewind();
00173 
00174 
00175         // Edit
00176 
00177             //- Set flags of stream
00178             ios_base::fmtflags flags(const ios_base::fmtflags)
00179             {
00180                 return ios_base::fmtflags(0);
00181             }
00182 
00183 
00184         // Print
00185 
00186             //- Print description of IOstream to Ostream
00187             void print(Ostream&) const;
00188 };
00189 
00190 
00191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00192 
00193 } // End namespace Foam
00194 
00195 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00196 
00197 #endif
00198 
00199 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines