prefixOSstream.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-2020 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::prefixOSstream
26 
27 Description
28  Version of OSstream which prints a prefix on each line.
29 
30  This is useful for running in parallel as it allows the processor number
31  to be automatically prepended to each message line.
32 
33 SourceFiles
34  prefixOSstream.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef prefixOSstream_H
39 #define prefixOSstream_H
40 
41 #include "OSstream.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Class prefixOSstream Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 class prefixOSstream
53 :
54  public OSstream
55 {
56  // Private Data
57 
58  bool printPrefix_;
59  string prefix_;
60 
61 
62  // Private Member Functions
63 
64  inline void checkWritePrefix();
65 
66 
67 public:
68 
69  // Constructors
70 
71  //- Set stream status
73  (
74  ostream& os,
75  const string& name,
79  );
80 
81 
82  // Member Functions
83 
84  // Enquiry
85 
86  //- Return the prefix of the stream
87  const string& prefix() const
88  {
89  return prefix_;
90  }
91 
92  //- Return non-const access to the prefix of the stream
93  string& prefix()
94  {
95  return prefix_;
96  }
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
111  virtual Ostream& write(const string&);
112 
113  //- Write verbatimString
114  virtual Ostream& write(const verbatimString&);
115 
116  //- Write std::string surrounded by quotes.
117  // Optional write without quotes.
118  virtual Ostream& writeQuoted
119  (
120  const std::string&,
121  const bool quoted=true
122  );
123 
124  //- Write int32_t
125  virtual Ostream& write(const int32_t);
126 
127  //- Write int64_t
128  virtual Ostream& write(const int64_t);
129 
130  //- Write floatScalar
131  virtual Ostream& write(const floatScalar);
132 
133  //- Write doubleScalar
134  virtual Ostream& write(const doubleScalar);
135 
136  //- Write longDoubleScalar
137  virtual Ostream& write(const longDoubleScalar);
138 
139  //- Write binary block
140  virtual Ostream& write(const char*, std::streamsize);
141 
142  //- Add indentation characters
143  virtual void indent();
144 
145 
146  // Print
147 
148  //- Print description of IOstream to Ostream
149  virtual void print(Ostream&) const;
150 };
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace Foam
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #endif
160 
161 // ************************************************************************* //
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
prefixOSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
versionNumber version() const
Return the stream version.
Definition: IOstream.H:396
const string & prefix() const
Return the prefix of the stream.
Version of OSstream which prints a prefix on each line.
A class for handling words, derived from string.
Definition: word.H:59
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 void indent()
Add indentation characters.
long double longDoubleScalar
Lang double precision floating point scalar type.
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:413
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:203
Version number type.
Definition: IOstream.H:96
virtual Ostream & write(const char)
Write character.
Namespace for OpenFOAM.