OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     OPstream
00027 
00028 Description
00029     Output inter-processor communications stream.
00030 
00031 SourceFiles
00032     OPstreamI.H
00033     OPwrite.C
00034 
00035 \*---------------------------------------------------------------------------*/
00036 
00037 #include "Pstream.H"
00038 
00039 #ifndef OPstream_H
00040 #define OPstream_H
00041 
00042 #include "Ostream.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         int toProcNo_;
00061         bool bufferedTransfer_;
00062 
00063 
00064     // Private member functions
00065 
00066         //- Write a T to the transfer buffer
00067         template<class T>
00068         inline void writeToBuffer(const T&);
00069 
00070         //- Write a char to the transfer buffer
00071         inline void writeToBuffer(const char&);
00072 
00073         //- Write data to the transfer buffer
00074         inline void writeToBuffer(const void* data, size_t count);
00075 
00076 
00077 public:
00078 
00079     // Constructors
00080 
00081         //- Construct given process index to send to and optional buffer size,
00082         //  write format and IO version
00083         OPstream
00084         (
00085             const int toProcNo,
00086             const label bufSize = 0,
00087             const bool bufferedTransfer = true,
00088             streamFormat format=BINARY,
00089             versionNumber version=currentVersion
00090         );
00091 
00092 
00093     // Destructor
00094 
00095         ~OPstream();
00096 
00097 
00098     // Member functions
00099 
00100         // Inquiry
00101 
00102             //- Return flags of output stream
00103             ios_base::fmtflags flags() const
00104             {
00105                 return ios_base::fmtflags(0);
00106             }
00107 
00108 
00109         // Write functions
00110 
00111             //- Write given buffer to given processor
00112             static bool write
00113             (
00114                 const int toProcNo,
00115                 const char* buf,
00116                 const std::streamsize bufSize,
00117                 const bool bufferedTransfer = true
00118             );
00119 
00120             //- Write next token to stream
00121             Ostream& write(const token&);
00122 
00123             //- Write character
00124             Ostream& write(const char);
00125 
00126             //- Write character string
00127             Ostream& write(const char*);
00128 
00129             //- Write word
00130             Ostream& write(const word&);
00131 
00132             //- Write string
00133             Ostream& write(const string&);
00134 
00135             //- Write label
00136             Ostream& write(const label);
00137 
00138             //- Write floatScalar
00139             Ostream& write(const floatScalar);
00140 
00141             //- Write doubleScalar
00142             Ostream& write(const doubleScalar);
00143 
00144             //- Write binary block
00145             Ostream& write(const char*, std::streamsize);
00146 
00147             //- Add indentation characters
00148             void indent()
00149             {}
00150 
00151 
00152         // Stream state functions
00153 
00154             //- Flush stream
00155             void flush()
00156             {}
00157 
00158             //- Add '\n' and flush stream
00159             void endl()
00160             {}
00161 
00162             //- Get width of output field
00163             int width() const
00164             {
00165                 return 0;
00166             }
00167 
00168             //- Set width of output field (and return old width)
00169             int width(const int)
00170             {
00171                  return 0;
00172             }
00173 
00174             //- Get precision of output field
00175             int precision() const
00176             {
00177                  return 0;
00178             }
00179 
00180             //- Set precision of output field (and return old precision)
00181             int precision(const int)
00182             {
00183                  return 0;
00184             }
00185 
00186             //- Get the data transfer option of the stream
00187             bool bufferedTransfer() const
00188             {
00189                 return bufferedTransfer_;
00190             }
00191 
00192             //- Set the buffering option of the stream
00193             bool bufferedTransfer(const bool bfrdTransfer)
00194             {
00195                 bool oldBufferedTransfer = bufferedTransfer_;
00196                 bufferedTransfer_ = bfrdTransfer;
00197                 return oldBufferedTransfer;
00198             }
00199 
00200 
00201         // Edit
00202 
00203             //- Set flags of stream
00204             ios_base::fmtflags flags(const ios_base::fmtflags)
00205             {
00206                 return ios_base::fmtflags(0);
00207             }
00208 
00209 
00210         // Print
00211 
00212             //- Print description of IOstream to Ostream
00213             void print(Ostream&) const;
00214 };
00215 
00216 
00217 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00218 
00219 } // End namespace Foam
00220 
00221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00222 
00223 // include inline implementaions
00224 #   include "OPstreamI.H"
00225 
00226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00227 
00228 #endif
00229 
00230 // ************************************************************************* //
For further information go to www.openfoam.org