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

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-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::OPstream
00027 
00028 Description
00029     Output inter-processor communications stream.
00030 
00031 SourceFiles
00032     OPstream.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #include "Pstream.H"
00037 
00038 #ifndef OPstream_H
00039 #define OPstream_H
00040 
00041 #include "Ostream.H"
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 namespace Foam
00046 {
00047 
00048 /*---------------------------------------------------------------------------*\
00049                           Class OPstream Declaration
00050 \*---------------------------------------------------------------------------*/
00051 
00052 class OPstream
00053 :
00054     public Pstream,
00055     public Ostream
00056 {
00057     // Private data
00058 
00059         int toProcNo_;
00060 
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 
00075 public:
00076 
00077     // Constructors
00078 
00079         //- Construct given process index to send to and optional buffer size,
00080         //  write format and IO version
00081         OPstream
00082         (
00083             const commsTypes commsType,
00084             const int toProcNo,
00085             const label bufSize = 0,
00086             streamFormat format=BINARY,
00087             versionNumber version=currentVersion
00088         );
00089 
00090 
00091     // Destructor
00092 
00093         ~OPstream();
00094 
00095 
00096     // Member functions
00097 
00098         // Inquiry
00099 
00100             //- Return flags of output stream
00101             ios_base::fmtflags flags() const
00102             {
00103                 return ios_base::fmtflags(0);
00104             }
00105 
00106 
00107         // Write functions
00108 
00109             //- Write given buffer to given processor
00110             static bool write
00111             (
00112                 const commsTypes commsType,
00113                 const int toProcNo,
00114                 const char* buf,
00115                 const std::streamsize bufSize
00116             );
00117 
00118             //- Non-blocking writes: wait until all have finished.
00119             static void waitRequests();
00120 
00121             //- Non-blocking writes: has request i finished?
00122             static bool finishedRequest(const label i);
00123 
00124             //- Write next token to stream
00125             Ostream& write(const token&);
00126 
00127             //- Write character
00128             Ostream& write(const char);
00129 
00130             //- Write character string
00131             Ostream& write(const char*);
00132 
00133             //- Write word
00134             Ostream& write(const word&);
00135 
00136             //- Write string
00137             Ostream& write(const string&);
00138 
00139             //- Write std::string surrounded by quotes.
00140             //  Optional write without quotes.
00141             Ostream& writeQuoted
00142             (
00143                 const std::string&,
00144                 const bool quoted=true
00145             );
00146 
00147             //- Write label
00148             Ostream& write(const label);
00149 
00150             //- Write floatScalar
00151             Ostream& write(const floatScalar);
00152 
00153             //- Write doubleScalar
00154             Ostream& write(const doubleScalar);
00155 
00156             //- Write binary block
00157             Ostream& write(const char*, std::streamsize);
00158 
00159             //- Add indentation characters
00160             void indent()
00161             {}
00162 
00163 
00164         // Stream state functions
00165 
00166             //- Flush stream
00167             void flush()
00168             {}
00169 
00170             //- Add newline and flush stream
00171             void endl()
00172             {}
00173 
00174             //- Get width of output field
00175             int width() const
00176             {
00177                 return 0;
00178             }
00179 
00180             //- Set width of output field (and return old width)
00181             int width(const int)
00182             {
00183                  return 0;
00184             }
00185 
00186             //- Get precision of output field
00187             int precision() const
00188             {
00189                  return 0;
00190             }
00191 
00192             //- Set precision of output field (and return old precision)
00193             int precision(const int)
00194             {
00195                  return 0;
00196             }
00197 
00198 
00199         // Edit
00200 
00201             //- Set flags of stream
00202             ios_base::fmtflags flags(const ios_base::fmtflags)
00203             {
00204                 return ios_base::fmtflags(0);
00205             }
00206 
00207 
00208         // Print
00209 
00210             //- Print description of IOstream to Ostream
00211             void print(Ostream&) const;
00212 };
00213 
00214 
00215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00216 
00217 } // End namespace Foam
00218 
00219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00220 
00221 #endif
00222 
00223 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd