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 | 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::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 next token to stream
102  virtual Ostream& write(const token&);
103 
104  //- Write character
105  virtual Ostream& write(const char);
106 
107  //- Write character string
108  virtual Ostream& write(const char*);
109 
110  //- Write word
111  virtual Ostream& write(const word&);
112 
113  //- Write string
114  virtual Ostream& write(const string&);
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 binary block
137  virtual Ostream& write(const char*, std::streamsize);
138 
139  //- Add indentation characters
140  virtual void indent();
141 
142 
143  // Print
144 
145  //- Print description of IOstream to Ostream
146  virtual void print(Ostream&) const;
147 };
148 
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 } // End namespace Foam
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 #endif
157 
158 // ************************************************************************* //
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:88
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.
A token holds items read from Istream.
Definition: token.H:69
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
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: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
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
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 void indent()
Add indentation characters.
compressionType compression() const
Return the stream compression.
Definition: IOstream.H:416
virtual Ostream & write(const token &)
Write next token to stream.
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:206
Version number type.
Definition: IOstream.H:96
Namespace for OpenFOAM.