OSstream.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
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::OSstream
26 
27 Description
28  Generic output stream.
29 
30 SourceFiles
31  OSstreamI.H
32  OSstream.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef OSstream_H
37 #define OSstream_H
38 
39 #include "Ostream.H"
40 #include "fileName.H"
41 #include <iostream>
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class OSstream Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class OSstream
53 :
54  public Ostream
55 {
56  // Private Data
57 
58  fileName name_;
59  ostream& os_;
60 
61 
62 public:
63 
64  // Constructors
65 
66  //- Set stream status
67  OSstream
68  (
69  ostream& os,
70  const string& name,
74  );
75 
76 
77  // Member Functions
78 
79  // Enquiry
80 
81  //- Return the name of the stream
82  // Useful for Fstream to return the filename
83  virtual const fileName& name() const
84  {
85  return name_;
86  }
87 
88  //- Return non-const access to the name of the stream
89  // Useful to alter the stream name
90  virtual fileName& name()
91  {
92  return name_;
93  }
94 
95  //- Return flags of output stream
96  virtual ios_base::fmtflags flags() const;
97 
98 
99  // Write functions
100 
101  //- Write next token to stream
102  virtual Ostream& write(const token&);
103 
104  //- Write character
105  virtual Ostream& write(const char);
106 
107  //- Write character string
108  virtual Ostream& write(const char*);
109 
110  //- Write word
111  virtual Ostream& write(const word&);
112 
113  //- Write string
114  // In the rare case that the string contains a final trailing
115  // backslash, it will be dropped to the appearance of an escaped
116  // double-quote.
117  virtual Ostream& write(const string&);
118 
119  //- Write std::string surrounded by quotes.
120  // Optional write without quotes.
121  virtual Ostream& writeQuoted
122  (
123  const std::string&,
124  const bool quoted=true
125  );
126 
127  //- Write int32_t
128  virtual Ostream& write(const int32_t);
129 
130  //- Write int64_t
131  virtual Ostream& write(const int64_t);
132 
133  //- Write floatScalar
134  virtual Ostream& write(const floatScalar);
135 
136  //- Write doubleScalar
137  virtual Ostream& write(const doubleScalar);
138 
139  //- Write longDoubleScalar
140  virtual Ostream& write(const longDoubleScalar);
141 
142  //- Write binary block
143  virtual Ostream& write(const char*, std::streamsize);
144 
145  //- Add indentation characters
146  virtual void indent();
147 
148 
149  // Stream state functions
150 
151  //- Set flags of output stream
152  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
153 
154  //- Flush stream
155  virtual void flush();
156 
157  //- Add newline and flush stream
158  virtual void endl();
159 
160  //- Get width of output field
161  virtual int width() const;
162 
163  //- Set width of output field (and return old width)
164  virtual int width(const int);
165 
166  //- Get precision of output field
167  virtual int precision() const;
168 
169  //- Set precision of output field (and return old precision)
170  virtual int precision(const int);
171 
172 
173  // STL stream
174 
175  //- Access to underlying std::ostream
176  virtual ostream& stdStream()
177  {
178  return os_;
179  }
180 
181  //- Const access to underlying std::ostream
182  virtual const ostream& stdStream() const
183  {
184  return os_;
185  }
186 
187 
188  // Print
189 
190  //- Print description of IOstream to Ostream
191  virtual void print(Ostream&) const;
192 
193 
194  // Member Operators
195 
196  //- Disallow default bitwise assignment
197  void operator=(const OSstream&) = delete;
198 };
199 
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 } // End namespace Foam
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #include "OSstreamI.H"
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 #endif
212 
213 // ************************************************************************* //
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:82
Generic output stream.
Definition: OSstream.H:51
A class for handling file names.
Definition: fileName.H:79
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: OSstream.C:267
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:293
A token holds items read from Istream.
Definition: token.H:69
virtual void endl()
Add newline and flush stream.
Definition: OSstream.C:260
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OSstream.C:125
virtual void indent()
Add indentation characters.
Definition: OSstream.C:245
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
OSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
Definition: OSstreamI.H:31
A class for handling words, derived from string.
Definition: word.H:59
virtual void flush()
Flush stream.
Definition: OSstream.C:254
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
virtual Ostream & write(const token &)
Write next token to stream.
Definition: OSstream.C:32
long double longDoubleScalar
Lang double precision floating point scalar type.
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
virtual ostream & stdStream()
Access to underlying std::ostream.
Definition: OSstream.H:175
virtual int width() const
Get width of output field.
Definition: OSstream.C:281
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:43
Version number type.
Definition: IOstream.H:96
void operator=(const OSstream &)=delete
Disallow default bitwise assignment.
Namespace for OpenFOAM.