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

OPstream.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::OPstream
00026 
00027 Description
00028     Output inter-processor communications stream.
00029 
00030 SourceFiles
00031     OPstream.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 // intentionally outside include guards!
00036 #include <OpenFOAM/Pstream.H>
00037 
00038 #ifndef OPstream_H
00039 #define OPstream_H
00040 
00041 #include <OpenFOAM/Ostream.H>
00042 #include "OPstreamImpl.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 /*---------------------------------------------------------------------------*\
00050                           Class OPstream Declaration
00051 \*---------------------------------------------------------------------------*/
00052 
00053 class OPstream
00054 :
00055     public Pstream,
00056     public Ostream
00057 {
00058     // Private data
00059 
00060         static autoPtr<OPstreamImpl> impl_;
00061 
00062     // Private member functions
00063 
00064         //- Write a T to the transfer buffer
00065         template<class T>
00066         inline void writeToBuffer(const T&);
00067 
00068         //- Write a char to the transfer buffer
00069         inline void writeToBuffer(const char&);
00070 
00071         //- Write data to the transfer buffer
00072         inline void writeToBuffer(const void* data, size_t count, size_t align);
00073 
00074         //- Fetches the PstreamImpl instance if necessary
00075         static autoPtr<OPstreamImpl>& impl()
00076         {
00077             if(!impl_.valid())
00078             {
00079                 impl_ = OPstreamImpl::New();
00080             }
00081             return impl_;
00082         }
00083 
00084 protected:
00085 
00086     // Protected data
00087 
00088         int toProcNo_;
00089 
00090 
00091 
00092 public:
00093 
00094     // Constructors
00095 
00096         //- Construct given process index to send to and optional buffer size,
00097         //  write format and IO version
00098         OPstream
00099         (
00100             const commsTypes commsType,
00101             const int toProcNo,
00102             const label bufSize = 0,
00103             streamFormat format=BINARY,
00104             versionNumber version=currentVersion
00105         );
00106 
00107 
00108     // Destructor
00109 
00110         ~OPstream();
00111 
00112 
00113     // Member functions
00114 
00115         // Inquiry
00116 
00117             //- Return flags of output stream
00118             ios_base::fmtflags flags() const
00119             {
00120                 return ios_base::fmtflags(0);
00121             }
00122 
00123 
00124         // Write functions
00125 
00126             //- Write given buffer to given processor
00127             static bool write
00128             (
00129                 const commsTypes commsType,
00130                 const int toProcNo,
00131                 const char* buf,
00132                 const std::streamsize bufSize
00133             )
00134             {
00135                 return impl()->write(commsType, toProcNo, buf, bufSize);
00136             }
00137 
00138             //- Non-blocking writes: wait until all have finished.
00139             static void waitRequests()
00140             {
00141                 impl()->waitRequests();
00142             }
00143 
00144             //- Non-blocking writes: has request i finished?
00145             static bool finishedRequest(const label i)
00146             {
00147                 return impl()->finishedRequest(i);
00148             }
00149 
00150             //- Write next token to stream
00151             Ostream& write(const token&);
00152 
00153             //- Write character
00154             Ostream& write(const char);
00155 
00156             //- Write character string
00157             Ostream& write(const char*);
00158 
00159             //- Write word
00160             Ostream& write(const word&);
00161 
00162             //- Write string
00163             Ostream& write(const string&);
00164 
00165             //- Write std::string surrounded by quotes.
00166             //  Optional write without quotes.
00167             Ostream& writeQuoted
00168             (
00169                 const std::string&,
00170                 const bool quoted=true
00171             );
00172 
00173             //- Write label
00174             Ostream& write(const label);
00175 
00176             //- Write floatScalar
00177             Ostream& write(const floatScalar);
00178 
00179             //- Write doubleScalar
00180             Ostream& write(const doubleScalar);
00181 
00182             //- Write binary block
00183             Ostream& write(const char*, std::streamsize);
00184 
00185             //- Add indentation characters
00186             void indent()
00187             {}
00188 
00189 
00190         // Stream state functions
00191 
00192             //- Flush stream
00193             void flush()
00194             {}
00195 
00196             //- Add newline and flush stream
00197             void endl()
00198             {}
00199 
00200             //- Get width of output field
00201             int width() const
00202             {
00203                 return 0;
00204             }
00205 
00206             //- Set width of output field (and return old width)
00207             int width(const int)
00208             {
00209                  return 0;
00210             }
00211 
00212             //- Get precision of output field
00213             int precision() const
00214             {
00215                  return 0;
00216             }
00217 
00218             //- Set precision of output field (and return old precision)
00219             int precision(const int)
00220             {
00221                  return 0;
00222             }
00223 
00224 
00225         // Edit
00226 
00227             //- Set flags of stream
00228             ios_base::fmtflags flags(const ios_base::fmtflags)
00229             {
00230                 return ios_base::fmtflags(0);
00231             }
00232 
00233 
00234         // Print
00235 
00236             //- Print description of IOstream to Ostream
00237             void print(Ostream&) const;
00238 };
00239 
00240 
00241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00242 
00243 } // End namespace Foam
00244 
00245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00246 
00247 #endif
00248 
00249 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines