foamVtkAsciiFormatter.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) 2016-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
30#include <limits>
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34const char* Foam::vtk::asciiFormatter::name_ = "ascii";
35
37Foam::vtk::asciiFormatter::opts_(formatType::INLINE_ASCII);
38
39
40// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41
42inline void Foam::vtk::asciiFormatter::next()
43{
44 if (pos_ >= itemsPerLine_)
45 {
46 os()<< '\n';
47 pos_ = 0;
48 }
49 else if (pos_)
50 {
51 os()<< ' ';
52 }
53 ++pos_;
54}
55
56
57inline void Foam::vtk::asciiFormatter::done()
58{
59 if (pos_)
60 {
61 os()<< '\n';
62 }
63 pos_ = 0;
64}
65
66
67// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
68
70:
71 vtk::formatter(os),
72 pos_(0)
73{}
74
75
77(
78 std::ostream& os,
79 unsigned prec
80)
81:
82 vtk::formatter(os),
83 pos_(0)
84{
85 os.precision(prec);
86}
87
88
89// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
90
92{
93 done();
94}
95
96
97// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
98
101{
102 return opts_;
103}
104
105
107{
108 return name_;
109}
110
111
113{
114 return name_;
115}
116
117
119{
120 return false;
121}
122
123
124void Foam::vtk::asciiFormatter::write(const uint8_t val)
125{
126 next();
127 os()<< int(val);
128}
129
130
132{
133 next();
134 os()<< val;
135}
136
137
139{
140 next();
141 os()<< val;
142}
143
144
146{
147 // Limit range of double to float conversion
148 if (val >= std::numeric_limits<float>::max())
149 {
150 write(std::numeric_limits<float>::max());
151 }
152 else if (val <= std::numeric_limits<float>::lowest())
153 {
154 write(std::numeric_limits<float>::lowest());
155 }
156 else
157 {
158 float copy(val);
159 write(copy);
160 }
161}
162
163
165{
166 done();
167}
168
169
170std::size_t Foam::vtk::asciiFormatter::encodedLength(std::size_t) const
171{
172 return 0;
173}
174
175
176// ************************************************************************* //
virtual bool write()
Write the output fields.
Inline ASCII output. Adds spaces between entries and a newline every 9 items (for consistency with wh...
virtual ~asciiFormatter()
Destructor. Finishes the output line as required.
virtual const vtk::outputOptions & opts() const
The output is INLINE_ASCII.
virtual const char * name() const
Name for the XML output type ("ascii")
virtual bool writeSize(const uint64_t ignored)
Write leading size - this is a no-op for ascii output.
virtual std::size_t encodedLength(std::size_t ignored) const
The encoded length for ascii output is not applicable.
virtual void flush()
Write a newline if needed to finish a line of output.
virtual const char * encoding() const
Name for the XML append encoding - unused.
Abstract class for a VTK output stream formatter.
std::ostream & os() noexcept
Access to the underlying output stream.
Encapsulated combinations of output format options. This is primarily useful when defining the output...
OBJstream os(runTime.globalPath()/outputName)
runTime write()