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-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::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 int32_t
131  virtual Ostream& write(const uint32_t);
132 
133  //- Write int64_t
134  virtual Ostream& write(const uint64_t);
135 
136  //- Write floatScalar
137  virtual Ostream& write(const floatScalar);
138 
139  //- Write doubleScalar
140  virtual Ostream& write(const doubleScalar);
141 
142  //- Write longDoubleScalar
143  virtual Ostream& write(const longDoubleScalar);
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  // Print
153 
154  //- Print description of IOstream to Ostream
155  virtual void print(Ostream&) const;
156 };
157 
158 
159 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160 
161 } // End namespace Foam
162 
163 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
164 
165 #endif
166 
167 // ************************************************************************* //
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 const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:85
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Version of OSstream which prints a prefix on each line.
prefixOSstream(ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Set stream status.
virtual void indent()
Add indentation characters.
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
const string & prefix() const
Return the prefix of the stream.
virtual Ostream & write(const char)
Write character.
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.