prefixOSstream.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2014 OpenFOAM Foundation
9  Copyright (C) 2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::prefixOSstream
29 
30 Description
31  Version of OSstream which prints a prefix on each line.
32 
33  This is useful for running in parallel as it allows the processor number
34  to be automatically prepended to each message line.
35 
36 SourceFiles
37  prefixOSstream.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef prefixOSstream_H
42 #define prefixOSstream_H
43 
44 #include "OSstream.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class prefixOSstream Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class prefixOSstream
56 :
57  public OSstream
58 {
59  // Private Data
60 
61  bool printPrefix_;
62 
63  string prefix_;
64 
65 
66  // Private Member Functions
67 
68  inline void checkWritePrefix();
69 
70 
71 public:
72 
73  // Constructors
74 
75  //- Construct and set stream status
77  (
78  std::ostream& os,
79  const string& streamName,
80  IOstreamOption streamOpt = IOstreamOption()
81  );
82 
83  //- Construct and set stream status
85  (
86  std::ostream& os,
87  const string& streamName,
88  streamFormat fmt,
90  compressionType comp = compressionType::UNCOMPRESSED
91  )
92  :
93  prefixOSstream(os, streamName, IOstreamOption(fmt, comp, ver))
94  {}
95 
96 
97  // Member Functions
98 
99  // Enquiry
100 
101  //- Return the stream prefix
102  const string& prefix() const
103  {
104  return prefix_;
105  }
106 
107  //- Return non-const access to the stream prefix
108  string& prefix()
109  {
110  return prefix_;
111  }
112 
113 
114  // Write Functions
115 
116  //- Write token to stream or otherwise handle it.
117  // \return false if the token type was not handled by this method
118  virtual bool write(const token& tok);
119 
120  //- Write character
121  virtual Ostream& write(const char c);
122 
123  //- Write character string
124  virtual Ostream& write(const char* str);
125 
126  //- Write word
127  virtual Ostream& write(const word& val);
128 
129  //- Write string
130  virtual Ostream& write(const string& val);
131 
132  //- Write std::string surrounded by quotes.
133  // Optional write without quotes.
134  virtual Ostream& writeQuoted
135  (
136  const std::string& val,
137  const bool quoted=true
138  );
139 
140  //- Write int32_t
141  virtual Ostream& write(const int32_t val);
142 
143  //- Write int64_t
144  virtual Ostream& write(const int64_t val);
145 
146  //- Write floatScalar
147  virtual Ostream& write(const floatScalar val);
148 
149  //- Write doubleScalar
150  virtual Ostream& write(const doubleScalar val);
151 
152  //- Write binary block
153  virtual Ostream& write(const char* buf, std::streamsize count);
154 
155  //- Add indentation characters
156  virtual void indent();
157 
158 
159  // Print
160 
161  //- Print stream description to Ostream
162  virtual void print(Ostream& os) const;
163 };
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Foam
169 
170 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
171 
172 #endif
173 
174 // ************************************************************************* //
Foam::doubleScalar
double doubleScalar
A typedef for double.
Definition: scalarFwd.H:48
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::prefixOSstream::print
virtual void print(Ostream &os) const
Print stream description to Ostream.
Definition: prefixOSstream.C:62
Foam::IOstreamOption::IOstreamOption
constexpr IOstreamOption(streamFormat fmt=streamFormat::ASCII, compressionType comp=compressionType::UNCOMPRESSED) noexcept
Definition: IOstreamOption.H:196
Foam::prefixOSstream::indent
virtual void indent()
Add indentation characters.
Definition: prefixOSstream.C:168
Foam::floatScalar
float floatScalar
A typedef for float.
Definition: scalarFwd.H:45
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:168
Foam::token
A token holds an item read from Istream.
Definition: token.H:69
Foam::prefixOSstream::write
virtual bool write(const token &tok)
Write token to stream or otherwise handle it.
Definition: prefixOSstream.C:69
Foam::prefixOSstream::prefixOSstream
prefixOSstream(std::ostream &os, const string &streamName, IOstreamOption streamOpt=IOstreamOption())
Construct and set stream status.
Definition: prefixOSstream.C:48
Foam::prefixOSstream
Version of OSstream which prints a prefix on each line.
Definition: prefixOSstream.H:54
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::prefixOSstream::prefix
string & prefix()
Return non-const access to the stream prefix.
Definition: prefixOSstream.H:107
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::OSstream
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:54
Foam::prefixOSstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &val, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: prefixOSstream.C:119
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:74
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::IOstreamOption::compressionType
compressionType
Compression treatment (UNCOMPRESSED | COMPRESSED)
Definition: IOstreamOption.H:77
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::prefixOSstream::prefix
const string & prefix() const
Return the stream prefix.
Definition: prefixOSstream.H:101
OSstream.H