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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::prefixOSstream
28 
29 Description
30  Version of OSstream which prints a prefix on each line.
31 
32  This is useful for running in parallel as it allows the processor number
33  to be automatically prepended to each message line.
34 
35 SourceFiles
36  prefixOSstream.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef prefixOSstream_H
41 #define prefixOSstream_H
42 
43 #include "OSstream.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 /*---------------------------------------------------------------------------*\
51  Class prefixOSstream Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class prefixOSstream
55 :
56  public OSstream
57 {
58  // Private data
59 
60  bool printPrefix_;
61  string prefix_;
62 
63 
64  // Private Member Functions
65 
66  inline void checkWritePrefix();
67 
68 
69 public:
70 
71  // Constructors
72 
73  //- Construct and set stream status
75  (
76  std::ostream& os,
77  const string& name,
81  );
82 
83 
84  // Member functions
85 
86  // Enquiry
87 
88  //- Return the stream prefix
89  const string& prefix() const
90  {
91  return prefix_;
92  }
93 
94  //- Return non-const access to the stream prefix
95  string& prefix()
96  {
97  return prefix_;
98  }
99 
100 
101  // Write functions
102 
103  //- Write token to stream or otherwise handle it.
104  // \return false if the token type was not handled by this method
105  virtual bool write(const token& tok);
106 
107  //- Write character
108  virtual Ostream& write(const char c);
109 
110  //- Write character string
111  virtual Ostream& write(const char* str);
112 
113  //- Write word
114  virtual Ostream& write(const word& val);
115 
116  //- Write string
117  virtual Ostream& write(const string& val);
118 
119  //- Write std::string surrounded by quotes.
120  // Optional write without quotes.
121  virtual Ostream& writeQuoted
122  (
123  const std::string& val,
124  const bool quoted=true
125  );
126 
127  //- Write int32_t
128  virtual Ostream& write(const int32_t val);
129 
130  //- Write int64_t
131  virtual Ostream& write(const int64_t val);
132 
133  //- Write floatScalar
134  virtual Ostream& write(const floatScalar val);
135 
136  //- Write doubleScalar
137  virtual Ostream& write(const doubleScalar val);
138 
139  //- Write binary block
140  virtual Ostream& write(const char* buf, std::streamsize count);
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& os) const;
150 };
151 
152 
153 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
154 
155 } // End namespace Foam
156 
157 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
158 
159 #endif
160 
161 // ************************************************************************* //
Foam::IOstreamOption::UNCOMPRESSED
compression = false
Definition: IOstreamOption.H:73
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::doubleScalar
double doubleScalar
Floating-point double precision scalar type.
Definition: doubleScalar.H:52
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 description of IOstream to Ostream.
Definition: prefixOSstream.C:63
Foam::prefixOSstream::indent
virtual void indent()
Add indentation characters.
Definition: prefixOSstream.C:201
Foam::floatScalar
float floatScalar
Floating-point single precision scalar type.
Definition: floatScalar.H:52
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:273
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number.
Definition: IOstreamOption.H:193
Foam::prefixOSstream::prefixOSstream
prefixOSstream(std::ostream &os, const string &name, streamFormat format=ASCII, versionNumber version=currentVersion, compressionType compression=UNCOMPRESSED)
Construct and set stream status.
Definition: prefixOSstream.C:47
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:70
Foam::prefixOSstream
Version of OSstream which prints a prefix on each line.
Definition: prefixOSstream.H:53
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:79
Foam::prefixOSstream::prefix
string & prefix()
Return non-const access to the stream prefix.
Definition: prefixOSstream.H:94
Foam::OSstream::name
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:91
Foam::OSstream
Generic output stream.
Definition: OSstream.H:54
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:321
Foam::prefixOSstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &val, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: prefixOSstream.C:152
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:64
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::IOstreamOption::ASCII
"ascii"
Definition: IOstreamOption.H:66
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:71
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::IOstreamOption::compression
compressionType compression() const noexcept
Get the stream compression.
Definition: IOstreamOption.H:297
Foam::prefixOSstream::prefix
const string & prefix() const
Return the stream prefix.
Definition: prefixOSstream.H:88
OSstream.H