Ostream.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) 2011-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 "Ostream.H"
27 #include "token.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
32 {
33  if (indentLevel_ == 0)
34  {
35  cerr<< "Ostream::decrIndent() : attempt to decrement 0 indent level"
36  << std::endl;
37  }
38  else
39  {
40  indentLevel_--;
41  }
42 }
43 
44 
46 {
47  return Foam::writeKeyword(*this, kw);
48 }
49 
50 
52 {
53  switch (t.type())
54  {
55  case token::UNDEFINED:
56  write("UNDEFINED");
57  WarningInFunction << "Undefined token" << Foam::endl;
58  break;
59 
60  case token::PUNCTUATION:
61  // Cast to char required to work around a bug in gcc versions < 10
62  write(static_cast<char>(t.pToken()));
63  // write(t.pToken());
64  break;
65 
66  case token::WORD:
67  write(t.wordToken());
68  break;
69 
72  break;
73 
74  case token::VARIABLE:
75  write(t.variableToken());
76  break;
77 
78  case token::STRING:
79  write(t.stringToken());
80  break;
81 
84  break;
85 
86  case token::INTEGER_32:
87  write(t.integer32Token());
88  break;
89 
90  case token::INTEGER_64:
91  write(t.integer64Token());
92  break;
93 
96  break;
97 
100  break;
101 
102  case token::FLOAT_SCALAR:
103  write(t.floatScalarToken());
104  break;
105 
108  break;
109 
112  break;
113 
114  case token::COMPOUND:
115  *this << t.compoundToken();
116  break;
117 
118  case token::ERROR:
119  write("ERROR");
120  WarningInFunction << "Error token" << Foam::endl;
121  break;
122 
123  default:
124  write("UNKNOWN");
125  SeriousErrorInFunction << "Unknown token" << Foam::endl;
126  }
127 
128  // Check state of stream
129  check("Ostream& Ostream::write(const token&)");
130 
131  return *this;
132 }
133 
134 
136 {
138  {
139  write(typeName);
140  // Cast to char required to work around a bug in gcc versions < 10
141  write(static_cast<char>(token::SPACE));
142  // write(token::SPACE);
143  }
144 
145  return *this;
146 }
147 
148 
149 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:45
virtual Ostream & write(const token &)
Write token.
Definition: Ostream.C:51
virtual Ostream & writeCompoundTag(const word &typeName)
Write the compound token tag if the name is a compound token.
Definition: Ostream.C:135
void decrIndent()
Decrememt the indent level.
Definition: Ostream.C:31
unsigned short indentLevel_
Current indent level.
Definition: Ostream.H:67
A class for handling keywords in dictionaries.
Definition: keyType.H:69
static bool isCompound(const word &name)
Return true if name is a compound type.
Definition: token.C:118
A token holds items read from Istream.
Definition: token.H:74
longDoubleScalar longDoubleScalarToken() const
Definition: tokenI.H:746
const variable & variableToken() const
Definition: tokenI.H:383
@ ERROR
Definition: token.H:98
@ VARIABLE
Definition: token.H:86
@ WORD
Definition: token.H:84
@ UNSIGNED_INTEGER_32
Definition: token.H:91
@ UNDEFINED
Definition: token.H:81
@ COMPOUND
Definition: token.H:96
@ FLOAT_SCALAR
Definition: token.H:93
@ INTEGER_64
Definition: token.H:90
@ DOUBLE_SCALAR
Definition: token.H:94
@ LONG_DOUBLE_SCALAR
Definition: token.H:95
@ VERBATIMSTRING
Definition: token.H:88
@ FUNCTIONNAME
Definition: token.H:85
@ UNSIGNED_INTEGER_64
Definition: token.H:92
@ INTEGER_32
Definition: token.H:89
@ STRING
Definition: token.H:87
@ PUNCTUATION
Definition: token.H:83
int32_t integer32Token() const
Definition: tokenI.H:485
const functionName & functionNameToken() const
Definition: tokenI.H:365
floatScalar floatScalarToken() const
Definition: tokenI.H:708
const string & stringToken() const
Definition: tokenI.H:401
punctuationToken pToken() const
Definition: tokenI.H:329
uint32_t unsignedInteger32Token() const
Definition: tokenI.H:556
int64_t integer64Token() const
Definition: tokenI.H:519
tokenType type() const
Definition: tokenI.H:299
const compound & compoundToken() const
Definition: tokenI.H:833
uint64_t unsignedInteger64Token() const
Definition: tokenI.H:590
doubleScalar doubleScalarToken() const
Definition: tokenI.H:727
const word & wordToken() const
Definition: tokenI.H:347
const verbatimString & verbatimStringToken() const
Definition: tokenI.H:419
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
#define WarningInFunction
Report a warning using Foam::Warning.
#define SeriousErrorInFunction
Report an error message using Foam::SeriousError.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
Definition: keyType.C:155