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-2022 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  //- Copy construct
77  OSstream(const OSstream&) = default;
78 
79 
80  // Member Functions
81 
82  // Enquiry
83 
84  //- Return the name of the stream
85  // Useful for Fstream to return the filename
86  virtual const fileName& name() const
87  {
88  return name_;
89  }
90 
91  //- Return non-const access to the name of the stream
92  // Useful to alter the stream name
93  virtual fileName& name()
94  {
95  return name_;
96  }
97 
98  //- Return flags of output stream
99  virtual ios_base::fmtflags flags() const;
100 
101 
102  // Write functions
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 with double quotes
114  virtual Ostream& write(const string&);
115 
116  //- Write verbatimString with #{ }#
117  virtual Ostream& write(const verbatimString&);
118 
119  //- Write std::string with optional double quotes.
120  virtual Ostream& writeQuoted
121  (
122  const std::string&,
123  const bool quoted=true
124  );
125 
126  //- Write int32_t
127  virtual Ostream& write(const int32_t);
128 
129  //- Write int64_t
130  virtual Ostream& write(const int64_t);
131 
132  //- Write floatScalar
133  virtual Ostream& write(const floatScalar);
134 
135  //- Write doubleScalar
136  virtual Ostream& write(const doubleScalar);
137 
138  //- Write longDoubleScalar
139  virtual Ostream& write(const longDoubleScalar);
140 
141  //- Write binary block
142  virtual Ostream& write(const char*, std::streamsize);
143 
144  //- Add indentation characters
145  virtual void indent();
146 
147 
148  // Stream state functions
149 
150  //- Set flags of output stream
151  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
152 
153  //- Flush stream
154  virtual void flush();
155 
156  //- Add newline and flush stream
157  virtual void endl();
158 
159  //- Get width of output field
160  virtual int width() const;
161 
162  //- Set width of output field (and return old width)
163  virtual int width(const int);
164 
165  //- Get precision of output field
166  virtual int precision() const;
167 
168  //- Set precision of output field (and return old precision)
169  virtual int precision(const int);
170 
171 
172  // STL stream
173 
174  //- Access to underlying std::ostream
175  virtual ostream& stdStream()
176  {
177  return os_;
178  }
179 
180  //- Const access to underlying std::ostream
181  virtual const ostream& stdStream() const
182  {
183  return os_;
184  }
185 
186 
187  // Print
188 
189  //- Print description of IOstream to Ostream
190  virtual void print(Ostream&) const;
191 
192 
193  // Member Operators
194 
195  //- Disallow default bitwise assignment
196  void operator=(const OSstream&) = delete;
197 };
198 
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 } // End namespace Foam
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #include "OSstreamI.H"
207 
208 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
209 
210 #endif
211 
212 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:413
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:194
Generic output stream.
Definition: OSstream.H:54
virtual void endl()
Add newline and flush stream.
Definition: OSstream.C:213
virtual void indent()
Add indentation characters.
Definition: OSstream.C:198
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string with optional double quotes.
Definition: OSstream.C:78
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:85
virtual ostream & stdStream()
Access to underlying std::ostream.
Definition: OSstream.H:174
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:246
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:43
OSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
Definition: OSstreamI.H:31
virtual Ostream & write(const char)
Write character.
Definition: OSstream.C:32
void operator=(const OSstream &)=delete
Disallow default bitwise assignment.
virtual int width() const
Get width of output field.
Definition: OSstream.C:234
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: OSstream.C:220
virtual void flush()
Flush stream.
Definition: OSstream.C:207
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A class for handling file names.
Definition: fileName.H:82
A class for handling verbatimStrings, derived from string.
A class for handling words, derived from string.
Definition: word.H:62
Namespace for OpenFOAM.
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
long double longDoubleScalar
Lang double precision floating point scalar type.