All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 character
102  virtual Ostream& write(const char);
103 
104  //- Write character string
105  virtual Ostream& write(const char*);
106 
107  //- Write word
108  virtual Ostream& write(const word&);
109 
110  //- Write string with double quotes
111  virtual Ostream& write(const string&);
112 
113  //- Write verbatimString with #{ }#
114  virtual Ostream& write(const verbatimString&);
115 
116  //- Write std::string with optional double quotes.
117  virtual Ostream& writeQuoted
118  (
119  const std::string&,
120  const bool quoted=true
121  );
122 
123  //- Write int32_t
124  virtual Ostream& write(const int32_t);
125 
126  //- Write int64_t
127  virtual Ostream& write(const int64_t);
128 
129  //- Write floatScalar
130  virtual Ostream& write(const floatScalar);
131 
132  //- Write doubleScalar
133  virtual Ostream& write(const doubleScalar);
134 
135  //- Write longDoubleScalar
136  virtual Ostream& write(const longDoubleScalar);
137 
138  //- Write binary block
139  virtual Ostream& write(const char*, std::streamsize);
140 
141  //- Add indentation characters
142  virtual void indent();
143 
144 
145  // Stream state functions
146 
147  //- Set flags of output stream
148  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
149 
150  //- Flush stream
151  virtual void flush();
152 
153  //- Add newline and flush stream
154  virtual void endl();
155 
156  //- Get width of output field
157  virtual int width() const;
158 
159  //- Set width of output field (and return old width)
160  virtual int width(const int);
161 
162  //- Get precision of output field
163  virtual int precision() const;
164 
165  //- Set precision of output field (and return old precision)
166  virtual int precision(const int);
167 
168 
169  // STL stream
170 
171  //- Access to underlying std::ostream
172  virtual ostream& stdStream()
173  {
174  return os_;
175  }
176 
177  //- Const access to underlying std::ostream
178  virtual const ostream& stdStream() const
179  {
180  return os_;
181  }
182 
183 
184  // Print
185 
186  //- Print description of IOstream to Ostream
187  virtual void print(Ostream&) const;
188 
189 
190  // Member Operators
191 
192  //- Disallow default bitwise assignment
193  void operator=(const OSstream&) = delete;
194 };
195 
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 } // End namespace Foam
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #include "OSstreamI.H"
204 
205 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
206 
207 #endif
208 
209 // ************************************************************************* //
A class for handling verbatimStrings, derived from string.
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:220
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:246
virtual void endl()
Add newline and flush stream.
Definition: OSstream.C:213
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string with optional double quotes.
Definition: OSstream.C:78
virtual void indent()
Add indentation characters.
Definition: OSstream.C:198
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
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:207
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:374
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:54
virtual Ostream & write(const char)
Write character.
Definition: OSstream.C:32
long double longDoubleScalar
Lang double precision floating point scalar type.
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:413
virtual ostream & stdStream()
Access to underlying std::ostream.
Definition: OSstream.H:171
virtual int width() const
Get width of output field.
Definition: OSstream.C:234
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
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.