OTstream.C
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 \*---------------------------------------------------------------------------*/
25 
26 #include "OTstream.H"
27 #include "int.H"
28 #include "tokenList.H"
29 #include "IStringStream.H"
30 
31 #include <cctype>
32 
33 // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //
34 
36 (
37  const string& name,
38  const streamFormat format,
39  const versionNumber version,
40  const bool global
41 )
42 :
43  Ostream(format, version, UNCOMPRESSED, global),
44  name_(name)
45 {
46  setOpened();
47  setGood();
48 }
49 
50 
51 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
52 
54 {}
55 
56 
57 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
58 
60 {
61  append(t);
62  return *this;
63 }
64 
65 
67 {
68  switch (c)
69  {
70  // Punctuation
72  case token::BEGIN_LIST :
73  case token::END_LIST :
74  case token::BEGIN_SQR :
75  case token::END_SQR :
76  case token::BEGIN_BLOCK :
77  case token::END_BLOCK :
78  case token::COLON :
79  case token::COMMA :
80  case token::ASSIGN :
81  case token::ADD :
82  case token::SUBTRACT :
83  case token::MULTIPLY :
84  case token::DIVIDE :
85  {
86  append(token(token::punctuationToken(c), lineNumber()));
87  return *this;
88  }
89 
90  default:
91  {
92  if (!isspace(c))
93  {
94  append(token(token::punctuationToken(c), lineNumber()));
95  }
96  }
97  }
98 
99  return *this;
100 }
101 
102 
104 {
105  IStringStream is(str);
106 
107  token t;
108  while (!is.eof() && !is.read(t).bad() && t.good())
109  {
110  append(t);
111  }
112 
113  return *this;
114 }
115 
116 
118 {
119  append(token(str, lineNumber()));
120  return *this;
121 }
122 
123 
125 {
126  append(token(str, lineNumber()));
127  return *this;
128 }
129 
130 
132 {
133  append(token(kt, lineNumber()));
134  return *this;
135 }
136 
137 
139 {
140  append(token(vs, lineNumber()));
141  return *this;
142 }
143 
144 
146 (
147  const std::string& str,
148  const bool quoted
149 )
150 {
151  if (quoted)
152  {
153  append(token(string(str), lineNumber()));
154  }
155  else
156  {
157  append(token(word(str), lineNumber()));
158  }
159  return *this;
160 }
161 
162 
164 {
165  append(token(val, lineNumber()));
166  return *this;
167 }
168 
169 
171 {
172  append(token(val, lineNumber()));
173  return *this;
174 }
175 
176 
178 {
179  append(token(val, lineNumber()));
180  return *this;
181 }
182 
183 
185 {
186  append(token(val, lineNumber()));
187  return *this;
188 }
189 
190 
192 {
193  append(token(val, lineNumber()));
194  return *this;
195 }
196 
197 
199 {
200  append(token(val, lineNumber()));
201  return *this;
202 }
203 
204 
206 {
207  append(token(val, lineNumber()));
208  return *this;
209 }
210 
211 
212 Foam::Ostream& Foam::OTstream::write(const char* data, std::streamsize count)
213 {
215  return *this;
216 }
217 
218 
220 {
221  os << "OTstream: " << name().c_str() << ' ';
222  IOstream::print(os);
223 }
224 
225 
226 // ************************************************************************* //
Version number type.
Definition: IOstream.H:97
void setGood()
Set stream to be good.
Definition: IOstream.H:255
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:87
bool bad() const
Return true if stream is corrupted.
Definition: IOstream.H:351
virtual void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: IOstream.C:142
void setOpened()
Set stream opened.
Definition: IOstream.H:237
virtual Istream & read(token &)
Return next token from stream.
Definition: ISstream.C:133
Input from memory buffer stream.
Definition: IStringStream.H:52
bool eof() const
Return true if end of input seen.
Definition: Istream.H:107
virtual Ostream & writeQuoted(const std::string &, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OTstream.C:146
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
void print(Ostream &) const
Print description of IOstream to Ostream.
Definition: OTstream.C:219
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A class for handling keywords in dictionaries.
Definition: keyType.H:69
A token holds items read from Istream.
Definition: token.H:74
punctuationToken
Standard punctuation tokens.
Definition: token.H:103
@ DIVIDE
Definition: token.H:127
@ BEGIN_BLOCK
Definition: token.H:114
@ BEGIN_SQR
Definition: token.H:112
@ END_BLOCK
Definition: token.H:115
@ ASSIGN
Definition: token.H:123
@ END_STATEMENT
Definition: token.H:109
@ BEGIN_LIST
Definition: token.H:110
@ SUBTRACT
Definition: token.H:125
@ END_LIST
Definition: token.H:111
@ END_SQR
Definition: token.H:113
@ MULTIPLY
Definition: token.H:126
bool good() const
Definition: tokenI.H:309
A class for handling verbatimStrings, derived from string.
A class for handling words, derived from string.
Definition: word.H:63
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:381
System integer.
const dimensionedScalar c
Speed of light in a vacuum.
double doubleScalar
Double precision floating point scalar type.
Definition: doubleScalar.H:52
float floatScalar
Float precision floating point scalar type.
Definition: floatScalar.H:52
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
bool isspace(char c)
Definition: char.H:53
label count(const ListType &l, typename ListType::const_reference x)
Count the number of occurrences of a value in a list.
long double longDoubleScalar
Lang double precision floating point scalar type.
word format(conversionProperties.lookup("format"))