FreeFOAM The Cross-Platform CFD Toolkit
OSstream.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) 1991-2010 OpenCFD Ltd.
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::OSstream
26 
27 Description
28  Generic output stream.
29 
30 SourceFiles
31  OSstreamI.H
32  OSstream.C
33  chkStream.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef OSstream_H
38 #define OSstream_H
39 
40 #include <OpenFOAM/Ostream.H>
41 #include <OpenFOAM/fileName.H>
42 #include <iostream>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class OSstream Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class OSstream
54 :
55  public Ostream
56 {
57  // Private data
58 
59  fileName name_;
60  ostream& os_;
61 
62 
63  // Private Member Functions
64 
65  //- Disallow default bitwise assignment
66  void operator=(const OSstream&);
67 
68 
69 protected:
70 
71  //- Return the stream reference
72  ostream& stream()
73  {
74  return os_;
75  }
76 
77  //- Return the const stream reference
78  const ostream& stream() const
79  {
80  return os_;
81  }
82 
83 
84 public:
85 
86  // Constructors
87 
88  //- Set stream status
89  OSstream
90  (
91  ostream& os,
92  const string& name,
94  versionNumber version=currentVersion,
96  );
97 
98 
99  // Member functions
100 
101  // Enquiry
102 
103  //- Return the name of the stream
104  // Useful for Fstream to return the filename
105  virtual const fileName& name() const
106  {
107  return name_;
108  }
109 
110  //- Return non-const access to the name of the stream
111  // Useful to alter the stream name
112  virtual fileName& name()
113  {
114  return name_;
115  }
116 
117  //- Return flags of output stream
118  virtual ios_base::fmtflags flags() const;
119 
120 
121  // Write functions
122 
123  //- Write next token to stream
124  virtual Ostream& write(const token&);
125 
126  //- Write character
127  virtual Ostream& write(const char);
128 
129  //- Write character string
130  virtual Ostream& write(const char*);
131 
132  //- Write word
133  virtual Ostream& write(const word&);
134 
135  //- Write string
136  // In the rare case that the string contains a final trailing
137  // backslash, it will be dropped to the appearance of an escaped
138  // double-quote.
139  virtual Ostream& write(const string&);
140 
141  //- Write std::string surrounded by quotes.
142  // Optional write without quotes.
143  virtual Ostream& writeQuoted
144  (
145  const std::string&,
146  const bool quoted=true
147  );
148 
149  //- Write label
150  virtual Ostream& write(const label);
151 
152  //- Write floatScalar
153  virtual Ostream& write(const floatScalar);
154 
155  //- Write doubleScalar
156  virtual Ostream& write(const doubleScalar);
157 
158  //- Write binary block
159  virtual Ostream& write(const char*, std::streamsize);
160 
161  //- Add indentation characters
162  virtual void indent();
163 
164 
165  // Stream state functions
166 
167  //- Set flags of output stream
168  virtual ios_base::fmtflags flags(const ios_base::fmtflags flags);
169 
170  //- Flush stream
171  virtual void flush();
172 
173  //- Add newline and flush stream
174  virtual void endl();
175 
176  //- Get width of output field
177  virtual int width() const;
178 
179  //- Set width of output field (and return old width)
180  virtual int width(const int);
181 
182  //- Get precision of output field
183  virtual int precision() const;
184 
185  //- Set precision of output field (and return old precision)
186  virtual int precision(const int);
187 
188 
189  // Print
190 
191  //- Print description of IOstream to Ostream
192  virtual void print(Ostream&) const;
193 };
194 
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 } // End namespace Foam
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #include <OpenFOAM/OSstreamI.H>
203 
204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205 
206 #endif
207 
208 // ************************ vim: set sw=4 sts=4 et: ************************ //