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-------------------------------------------------------------------------------
11License
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 {
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 padding = (entryIndentation_ - label(kw.size()));
69
70 // Account for quotes surrounding pattern
71 if (kw.isPattern())
72 {
73 padding -= 2;
74 }
75
76 // Write padding spaces (always at least one)
77 do
78 {
79 write(char(token::SPACE));
80 }
81 while (--padding > 0);
82
83 return *this;
84}
85
86
88{
89 indent(); writeQuoted(kw, kw.isPattern()); write('\n');
90 beginBlock();
91
92 return *this;
93}
94
95
97{
98 indent(); write(char(token::BEGIN_BLOCK)); write('\n');
99 incrIndent();
100
101 return *this;
102}
103
104
106{
107 decrIndent();
108 indent(); write(char(token::END_BLOCK)); write('\n');
109
110 return *this;
111}
112
113
115{
116 write(char(token::END_STATEMENT)); write('\n');
117
118 return *this;
119}
120
121
122// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
virtual Ostream & endBlock()
Write end block group.
Definition: Ostream.C:105
virtual Ostream & writeKeyword(const keyType &kw)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:57
virtual Ostream & beginBlock()
Write begin block group without a name.
Definition: Ostream.C:96
void decrIndent()
Decrement the indent level.
Definition: Ostream.C:37
unsigned short indentLevel_
Current indent level.
Definition: Ostream.H:74
virtual Ostream & endEntry()
Write end entry (';') followed by newline.
Definition: Ostream.C:114
virtual bool write()
Write the output fields.
A class for handling keywords in dictionaries.
Definition: keyType.H:71
bool isPattern() const noexcept
The keyType is treated as a pattern, not as literal string.
Definition: keyTypeI.H:104
@ BEGIN_BLOCK
Begin block [isseparator].
Definition: token.H:159
@ END_BLOCK
End block [isseparator].
Definition: token.H:160
@ END_STATEMENT
End entry [isseparator].
Definition: token.H:154
@ SPACE
Space [isspace].
Definition: token.H:125
os writeQuoted(("# "+outputName+"\n"), false)
Ostream & beginBlock(Ostream &os)
Write begin block group without a name.
Definition: Ostream.H:381
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:342
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
runTime write()