OTstream.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) 2025-2026 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::OTstream
26 
27 Description
28  Output token stream.
29 
30 SourceFiles
31  OTstream.C
32 
33 See also
34  Foam::ITstream
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef OTstream_H
39 #define OTstream_H
40 
41 #include "Ostream.H"
42 #include "DynamicList.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class OTstream Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 class OTstream
54 :
55  public Ostream,
56  public DynamicList<token>
57 {
58  // Private Data
59 
60  //- Name of OTstream
61  fileName name_;
62 
63 
64 public:
65 
66  // Constructors
67 
68  //- Construct given name write format and IO version
69  OTstream
70  (
71  const string& name,
72  const streamFormat format = ASCII,
74  const bool global = false
75  );
76 
77 
78  //- Destructor
79  virtual ~OTstream();
80 
81 
82  // Member Functions
83 
84  // Inquiry
85 
86  //- Return the name of the stream
87  virtual const fileName& name() const
88  {
89  return name_;
90  }
91 
92  //- Return non-const access to the name of the stream
93  virtual fileName& name()
94  {
95  return name_;
96  }
97 
98  //- Return flags of output stream
99  ios_base::fmtflags flags() const
100  {
101  return ios_base::fmtflags(0);
102  }
103 
104 
105  // Write functions
106 
107  //- Write token
108  virtual Ostream& write(const token&);
109 
110  //- No need to write the compound token tag for an OTstream
111  virtual Ostream& writeCompoundTag(const word& typeName)
112  {
113  return *this;
114  }
115 
116  //- Write character
117  virtual Ostream& write(const char);
118 
119  //- Parse raw C-string and append tokens
120  virtual Ostream& write(const char*);
121 
122  //- Write word
123  virtual Ostream& write(const word&);
124 
125  //- Write string
126  virtual Ostream& write(const string&);
127 
128  //- Write keyType
129  virtual Ostream& write(const keyType&);
130 
131  //- Write verbatimString
132  virtual Ostream& write(const verbatimString&);
133 
134  //- Write std::string surrounded by quotes.
135  // Optional write without quotes.
136  virtual Ostream& writeQuoted
137  (
138  const std::string&,
139  const bool quoted=true
140  );
141 
142  //- Write int32_t
143  virtual Ostream& write(const int32_t);
144 
145  //- Write int64_t
146  virtual Ostream& write(const int64_t);
147 
148  //- Write uint32_t
149  virtual Ostream& write(const uint32_t);
150 
151  //- Write uint64_t
152  virtual Ostream& write(const uint64_t);
153 
154  //- Write floatScalar
155  virtual Ostream& write(const floatScalar);
156 
157  //- Write doubleScalar
158  virtual Ostream& write(const doubleScalar);
159 
160  //- Write longDoubleScalar
161  virtual Ostream& write(const longDoubleScalar);
162 
163  //- Write binary block
164  virtual Ostream& write(const char*, std::streamsize);
165 
166  //- Add indentation characters
167  virtual void indent()
168  {}
169 
170 
171  // Stream state functions
172 
173  //- Flush stream
174  virtual void flush()
175  {}
176 
177  //- Add newline and flush stream
178  virtual void endl()
179  {}
180 
181  //- Get width of output field
182  virtual int width() const
183  {
184  return 0;
185  }
186 
187  //- Set width of output field (and return old width)
188  virtual int width(const int)
189  {
190  return 0;
191  }
192 
193  //- Get precision of output field
194  virtual int precision() const
195  {
196  return 0;
197  }
198 
199  //- Set precision of output field (and return old precision)
200  virtual int precision(const int)
201  {
202  return 0;
203  }
204 
205 
206  // Edit
207 
208  //- Set flags of stream
209  ios_base::fmtflags flags(const ios_base::fmtflags)
210  {
211  return ios_base::fmtflags(0);
212  }
213 
214 
215  // Print
216 
217  //- Print description of IOstream to Ostream
218  void print(Ostream&) const;
219 };
220 
221 
222 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 
224 } // End namespace Foam
225 
226 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
227 
228 #endif
229 
230 // ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
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:377
bool global() const
Return global state.
Definition: IOstream.H:438
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
versionNumber version() const
Return the stream version.
Definition: IOstream.H:399
Output token stream.
Definition: OTstream.H:56
ios_base::fmtflags flags() const
Return flags of output stream.
Definition: OTstream.H:98
virtual void indent()
Add indentation characters.
Definition: OTstream.H:166
virtual void endl()
Add newline and flush stream.
Definition: OTstream.H:177
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OTstream.C:146
virtual const fileName & name() const
Return the name of the stream.
Definition: OTstream.H:86
virtual Ostream & write(const token &)
Write token.
Definition: OTstream.C:59
OTstream(const string &name, const streamFormat format=ASCII, const versionNumber version=currentVersion, const bool global=false)
Construct given name write format and IO version.
Definition: OTstream.C:36
virtual ~OTstream()
Destructor.
Definition: OTstream.C:53
virtual int width() const
Get width of output field.
Definition: OTstream.H:181
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: OTstream.C:219
virtual Ostream & writeCompoundTag(const word &typeName)
No need to write the compound token tag for an OTstream.
Definition: OTstream.H:110
virtual void flush()
Flush stream.
Definition: OTstream.H:173
virtual int precision() const
Get precision of output field.
Definition: OTstream.H:193
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A class for handling file names.
Definition: fileName.H:82
A class for handling keywords in dictionaries.
Definition: keyType.H:69
A token holds items read from Istream.
Definition: token.H:74
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling verbatimStrings, derived from string.
A class for handling words, derived from string.
Definition: word.H:63
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.