Merge branch 'upstream/OpenFOAM' into master
[freefoam.git] / src / OpenFOAM / db / IOstreams / Pstreams / OPstream.H
blobb31234331ab947b366ed524b690422affeb3a462
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::OPstream
28 Description
29     Output inter-processor communications stream.
31 SourceFiles
32     OPstream.C
34 \*---------------------------------------------------------------------------*/
36 // intentionally outside include guards!
37 #include <OpenFOAM/Pstream.H>
39 #ifndef OPstream_H
40 #define OPstream_H
42 #include <OpenFOAM/Ostream.H>
43 #include "OPstreamImpl.H"
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 namespace Foam
50 /*---------------------------------------------------------------------------*\
51                           Class OPstream Declaration
52 \*---------------------------------------------------------------------------*/
54 class OPstream
56     public Pstream,
57     public Ostream
59     // Private data
61         static autoPtr<OPstreamImpl> impl_;
63     // Private member functions
65         //- Write a T to the transfer buffer
66         template<class T>
67         inline void writeToBuffer(const T&);
69         //- Write a char to the transfer buffer
70         inline void writeToBuffer(const char&);
72         //- Write data to the transfer buffer
73         inline void writeToBuffer(const void* data, size_t count, size_t align);
75         //- Fetches the PstreamImpl instance if necessary
76         static autoPtr<OPstreamImpl>& impl()
77         {
78             if(!impl_.valid())
79             {
80                 impl_ = OPstreamImpl::New();
81             }
82             return impl_;
83         }
85 protected:
87     // Protected data
89         int toProcNo_;
93 public:
95     // Constructors
97         //- Construct given process index to send to and optional buffer size,
98         //  write format and IO version
99         OPstream
100         (
101             const commsTypes commsType,
102             const int toProcNo,
103             const label bufSize = 0,
104             streamFormat format=BINARY,
105             versionNumber version=currentVersion
106         );
109     // Destructor
111         ~OPstream();
114     // Member functions
116         // Inquiry
118             //- Return flags of output stream
119             ios_base::fmtflags flags() const
120             {
121                 return ios_base::fmtflags(0);
122             }
125         // Write functions
127             //- Write given buffer to given processor
128             static bool write
129             (
130                 const commsTypes commsType,
131                 const int toProcNo,
132                 const char* buf,
133                 const std::streamsize bufSize
134             )
135             {
136                 return impl()->write(commsType, toProcNo, buf, bufSize);
137             }
139             //- Non-blocking writes: wait until all have finished.
140             static void waitRequests()
141             {
142                 impl()->waitRequests();
143             }
145             //- Non-blocking writes: has request i finished?
146             static bool finishedRequest(const label i)
147             {
148                 return impl()->finishedRequest(i);
149             }
151             //- Write next token to stream
152             Ostream& write(const token&);
154             //- Write character
155             Ostream& write(const char);
157             //- Write character string
158             Ostream& write(const char*);
160             //- Write word
161             Ostream& write(const word&);
163             //- Write string
164             Ostream& write(const string&);
166             //- Write std::string surrounded by quotes.
167             //  Optional write without quotes.
168             Ostream& writeQuoted
169             (
170                 const std::string&,
171                 const bool quoted=true
172             );
174             //- Write label
175             Ostream& write(const label);
177             //- Write floatScalar
178             Ostream& write(const floatScalar);
180             //- Write doubleScalar
181             Ostream& write(const doubleScalar);
183             //- Write binary block
184             Ostream& write(const char*, std::streamsize);
186             //- Add indentation characters
187             void indent()
188             {}
191         // Stream state functions
193             //- Flush stream
194             void flush()
195             {}
197             //- Add newline and flush stream
198             void endl()
199             {}
201             //- Get width of output field
202             int width() const
203             {
204                 return 0;
205             }
207             //- Set width of output field (and return old width)
208             int width(const int)
209             {
210                  return 0;
211             }
213             //- Get precision of output field
214             int precision() const
215             {
216                  return 0;
217             }
219             //- Set precision of output field (and return old precision)
220             int precision(const int)
221             {
222                  return 0;
223             }
226         // Edit
228             //- Set flags of stream
229             ios_base::fmtflags flags(const ios_base::fmtflags)
230             {
231                 return ios_base::fmtflags(0);
232             }
235         // Print
237             //- Print description of IOstream to Ostream
238             void print(Ostream&) const;
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
244 } // End namespace Foam
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 #endif
250 // ************************ vim: set sw=4 sts=4 et: ************************ //