OSstream.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) 2011-2014 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  // Private Member Functions
63 
64  //- Disallow default bitwise assignment
65  void operator=(const OSstream&);
66 
67 
68 public:
69 
70  // Constructors
71 
72  //- Set stream status
73  OSstream
74  (
75  ostream& os,
76  const string& name,
80  );
81 
82 
83  // Member functions
84 
85  // Enquiry
86 
87  //- Return the name of the stream
88  // Useful for Fstream to return the filename
89  virtual const fileName& name() const
90  {
91  return name_;
92  }
93 
94  //- Return non-const access to the name of the stream
95  // Useful to alter the stream name
96  virtual fileName& name()
97  {
98  return name_;
99  }
100 
101  //- Return flags of output stream
102  virtual ios_base::fmtflags flags() const;
103 
104 
105  // Write functions
106 
107  //- Write next token to stream
108  virtual Ostream& write(const token&);
109 
110  //- Write character
111  virtual Ostream& write(const char);
112 
113  //- Write character string
114  virtual Ostream& write(const char*);
115 
116  //- Write word
117  virtual Ostream& write(const word&);
118 
119  //- Write string
120  // In the rare case that the string contains a final trailing
121  // backslash, it will be dropped to the appearance of an escaped
122  // double-quote.
123  virtual Ostream& write(const string&);
124 
125  //- Write std::string surrounded by quotes.
126  // Optional write without quotes.
127  virtual Ostream& writeQuoted
128  (
129  const std::string&,
130  const bool quoted=true
131  );
132 
133  //- Write int32_t
134  virtual Ostream& write(const int32_t);
135 
136  //- Write int64_t
137  virtual Ostream& write(const int64_t);
138 
139  //- Write floatScalar
140  virtual Ostream& write(const floatScalar);
141 
142  //- Write doubleScalar
143  virtual Ostream& write(const doubleScalar);
144 
145  //- Write binary block
146  virtual Ostream& write(const char*, std::streamsize);
147 
148  //- Add indentation characters
149  virtual void indent();
150 
151 
152  // Stream state functions
153 
154  //- Set flags of output stream
155  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
156 
157  //- Flush stream
158  virtual void flush();
159 
160  //- Add newline and flush stream
161  virtual void endl();
162 
163  //- Get width of output field
164  virtual int width() const;
165 
166  //- Set width of output field (and return old width)
167  virtual int width(const int);
168 
169  //- Get precision of output field
170  virtual int precision() const;
171 
172  //- Set precision of output field (and return old precision)
173  virtual int precision(const int);
174 
175 
176  // STL stream
177 
178  //- Access to underlying std::ostream
179  virtual ostream& stdStream()
180  {
181  return os_;
182  }
183 
184  //- Const access to underlying std::ostream
185  virtual const ostream& stdStream() const
186  {
187  return os_;
188  }
189 
190 
191  // Print
192 
193  //- Print description of IOstream to Ostream
194  virtual void print(Ostream&) const;
195 };
196 
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace Foam
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
204 #include "OSstreamI.H"
205 
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 
208 #endif
209 
210 // ************************************************************************* //
Generic output stream.
Definition: OSstream.H:51
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
A class for handling file names.
Definition: fileName.H:69
A token holds items read from Istream.
Definition: token.H:69
virtual void endl()
Add newline and flush stream.
Definition: OSstream.C:252
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:237
OSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
Definition: OSstreamI.H:31
virtual int precision() const
Get precision of output field.
Definition: OSstream.C:285
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: SstreamsPrint.C:43
A class for handling words, derived from string.
Definition: word.H:59
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:88
virtual void flush()
Flush stream.
Definition: OSstream.C:246
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:49
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:49
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
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
virtual ostream & stdStream()
Access to underlying std::ostream.
Definition: OSstream.H:178
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
virtual ios_base::fmtflags flags() const
Return flags of output stream.
Definition: OSstream.C:259
Version number type.
Definition: IOstream.H:96
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
virtual int width() const
Get width of output field.
Definition: OSstream.C:273
Namespace for OpenFOAM.