Ostream.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2016-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "word.H"
30 #include "Ostream.H"
31 #include "token.H"
32 #include "keyType.H"
33 #include "IOstreams.H"
34 
35 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
36 
38 {
39  if (!indentLevel_)
40  {
41  std::cerr
42  << "Ostream::decrIndent() : attempt to decrement 0 indent level\n";
43  }
44  else
45  {
46  --indentLevel_;
47  }
48 }
49 
50 
52 {
53  return writeQuoted(kw, kw.isPattern());
54 }
55 
56 
58 {
59  indent();
60  writeQuoted(kw, kw.isPattern());
61 
62  if (indentSize_ <= 1)
63  {
64  write(char(token::SPACE));
65  return *this;
66  }
67 
68  label nSpaces = entryIndentation_ - label(kw.size());
69 
70  // Account for quotes surrounding pattern
71  if (kw.isPattern())
72  {
73  nSpaces -= 2;
74  }
75 
76  // Could also increment by indentSize_ ...
77  if (nSpaces < 1)
78  {
79  nSpaces = 1;
80  }
81 
82  while (nSpaces--)
83  {
85  }
86 
87  return *this;
88 }
89 
90 
91 Foam::Ostream& Foam::Ostream::beginBlock(const keyType& kw)
92 {
93  indent(); writeQuoted(kw, kw.isPattern()); write('\n');
94  beginBlock();
95 
96  return *this;
97 }
98 
99 
101 {
103  incrIndent();
104 
105  return *this;
106 }
107 
108 
110 {
112  indent(); write(char(token::END_BLOCK)); write('\n');
113 
114  return *this;
115 }
116 
117 
119 {
120  write(char(token::END_STATEMENT)); write('\n');
121 
122  return *this;
123 }
124 
125 
126 // ************************************************************************* //
token.H
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::keyType::isPattern
bool isPattern() const noexcept
Definition: keyTypeI.H:97
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Definition: Ostream.H:352
writeQuoted
os writeQuoted(("# "+outputName+"\n"), false)
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:66
Foam::Ostream::beginBlock
virtual Ostream & beginBlock()
Definition: Ostream.C:93
Foam::Ostream::endEntry
virtual Ostream & endEntry()
Definition: Ostream.C:111
Foam::token::END_STATEMENT
@ END_STATEMENT
End entry [isseparator].
Definition: token.H:150
Foam::Ostream::decrIndent
void decrIndent()
Definition: Ostream.C:30
Foam::token::END_BLOCK
@ END_BLOCK
End block [isseparator].
Definition: token.H:156
Foam::Ostream::endBlock
virtual Ostream & endBlock()
Definition: Ostream.C:102
Foam::beginBlock
Ostream & beginBlock(Ostream &os)
Definition: Ostream.H:393
Foam::Ostream::write
virtual bool write(const token &tok)=0
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Definition: Ostream.H:361
Foam::Ostream::writeKeyword
virtual Ostream & writeKeyword(const keyType &kw)
Definition: Ostream.C:50
Foam::indent
Ostream & indent(Ostream &os)
Definition: Ostream.H:343
Foam::token::BEGIN_BLOCK
@ BEGIN_BLOCK
Begin block [isseparator].
Definition: token.H:155
Foam::Ostream::indentLevel_
unsigned short indentLevel_
Definition: Ostream.H:67
Ostream.H
Foam::token::SPACE
@ SPACE
Space [isspace].
Definition: token.H:121
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Definition: foamVtkOutputTemplates.C:29
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
word.H
keyType.H