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-2024 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 int32_t
133  virtual Ostream& write(const uint32_t);
134 
135  //- Write int64_t
136  virtual Ostream& write(const uint64_t);
137 
138  //- Write floatScalar
139  virtual Ostream& write(const floatScalar);
140 
141  //- Write doubleScalar
142  virtual Ostream& write(const doubleScalar);
143 
144  //- Write longDoubleScalar
145  virtual Ostream& write(const longDoubleScalar);
146 
147  //- Write binary block
148  virtual Ostream& write(const char*, std::streamsize);
149 
150  //- Add indentation characters
151  virtual void indent();
152 
153 
154  // Stream state functions
155 
156  //- Set flags of output stream
157  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
158 
159  //- Flush stream
160  virtual void flush();
161 
162  //- Add newline and flush stream
163  virtual void endl();
164 
165  //- Get width of output field
166  virtual int width() const;
167 
168  //- Set width of output field (and return old width)
169  virtual int width(const int);
170 
171  //- Get precision of output field
172  virtual int precision() const;
173 
174  //- Set precision of output field (and return old precision)
175  virtual int precision(const int);
176 
177 
178  // STL stream
179 
180  //- Access to underlying std::ostream
181  virtual ostream& stdStream()
182  {
183  return os_;
184  }
185 
186  //- Const access to underlying std::ostream
187  virtual const ostream& stdStream() const
188  {
189  return os_;
190  }
191 
192 
193  // Print
194 
195  //- Print description of IOstream to Ostream
196  virtual void print(Ostream&) const;
197 
198 
199  // Member Operators
200 
201  //- Disallow default bitwise assignment
202  void operator=(const OSstream&) = delete;
203 };
204 
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 } // End namespace Foam
209 
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
211 
212 #include "OSstreamI.H"
213 
214 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
215 
216 #endif
217 
218 // ************************************************************************* //
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:229
virtual void indent()
Add indentation characters.
Definition: OSstream.C:214
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:180
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:262
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:250
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: OSstream.C:236
virtual void flush()
Flush stream.
Definition: OSstream.C:223
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.