FreeFOAM The Cross-Platform CFD Toolkit
OPstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::OPstream
26 
27 Description
28  Output inter-processor communications stream.
29 
30 SourceFiles
31  OPstream.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 // intentionally outside include guards!
36 #include <OpenFOAM/Pstream.H>
37 
38 #ifndef OPstream_H
39 #define OPstream_H
40 
41 #include <OpenFOAM/Ostream.H>
42 #include "OPstreamImpl.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class OPstream Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class OPstream
54 :
55  public Pstream,
56  public Ostream
57 {
58  // Private data
59 
60  static autoPtr<OPstreamImpl> impl_;
61 
62  // Private member functions
63 
64  //- Write a T to the transfer buffer
65  template<class T>
66  inline void writeToBuffer(const T&);
67 
68  //- Write a char to the transfer buffer
69  inline void writeToBuffer(const char&);
70 
71  //- Write data to the transfer buffer
72  inline void writeToBuffer(const void* data, size_t count, size_t align);
73 
74  //- Fetches the PstreamImpl instance if necessary
75  static autoPtr<OPstreamImpl>& impl()
76  {
77  if(!impl_.valid())
78  {
79  impl_ = OPstreamImpl::New();
80  }
81  return impl_;
82  }
83 
84 protected:
85 
86  // Protected data
87 
88  int toProcNo_;
89 
90 
91 
92 public:
93 
94  // Constructors
95 
96  //- Construct given process index to send to and optional buffer size,
97  // write format and IO version
98  OPstream
99  (
100  const commsTypes commsType,
101  const int toProcNo,
102  const label bufSize = 0,
105  );
106 
107 
108  // Destructor
109 
110  ~OPstream();
111 
112 
113  // Member functions
114 
115  // Inquiry
116 
117  //- Return flags of output stream
118  ios_base::fmtflags flags() const
119  {
120  return ios_base::fmtflags(0);
121  }
122 
123 
124  // Write functions
125 
126  //- Write given buffer to given processor
127  static bool write
128  (
129  const commsTypes commsType,
130  const int toProcNo,
131  const char* buf,
132  const std::streamsize bufSize
133  )
134  {
135  return impl()->write(commsType, toProcNo, buf, bufSize);
136  }
137 
138  //- Non-blocking writes: wait until all have finished.
139  static void waitRequests()
140  {
141  impl()->waitRequests();
142  }
143 
144  //- Non-blocking writes: has request i finished?
145  static bool finishedRequest(const label i)
146  {
147  return impl()->finishedRequest(i);
148  }
149 
150  //- Write next token to stream
151  Ostream& write(const token&);
152 
153  //- Write character
154  Ostream& write(const char);
155 
156  //- Write character string
157  Ostream& write(const char*);
158 
159  //- Write word
160  Ostream& write(const word&);
161 
162  //- Write string
163  Ostream& write(const string&);
164 
165  //- Write std::string surrounded by quotes.
166  // Optional write without quotes.
168  (
169  const std::string&,
170  const bool quoted=true
171  );
172 
173  //- Write label
174  Ostream& write(const label);
175 
176  //- Write floatScalar
177  Ostream& write(const floatScalar);
178 
179  //- Write doubleScalar
180  Ostream& write(const doubleScalar);
181 
182  //- Write binary block
183  Ostream& write(const char*, std::streamsize);
184 
185  //- Add indentation characters
186  void indent()
187  {}
188 
189 
190  // Stream state functions
191 
192  //- Flush stream
193  void flush()
194  {}
195 
196  //- Add newline and flush stream
197  void endl()
198  {}
199 
200  //- Get width of output field
201  int width() const
202  {
203  return 0;
204  }
205 
206  //- Set width of output field (and return old width)
207  int width(const int)
208  {
209  return 0;
210  }
211 
212  //- Get precision of output field
213  int precision() const
214  {
215  return 0;
216  }
217 
218  //- Set precision of output field (and return old precision)
219  int precision(const int)
220  {
221  return 0;
222  }
223 
224 
225  // Edit
226 
227  //- Set flags of stream
228  ios_base::fmtflags flags(const ios_base::fmtflags)
229  {
230  return ios_base::fmtflags(0);
231  }
232 
233 
234  // Print
235 
236  //- Print description of IOstream to Ostream
237  void print(Ostream&) const;
238 };
239 
240 
241 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
242 
243 } // End namespace Foam
244 
245 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
246 
247 #endif
248 
249 // ************************ vim: set sw=4 sts=4 et: ************************ //