foamVtkAsciiFormatter.H
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 -------------------------------------------------------------------------------
10 License
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 Class
27  Foam::vtk::asciiFormatter
28 
29 Description
30  Inline ASCII output.
31  Adds spaces between entries and a newline every 9 items
32  (for consistency with what VTK itself outputs).
33 
34 SourceFiles
35  foamVtkAsciiFormatter.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef Foam_vtk_asciiFormatter_H
40 #define Foam_vtk_asciiFormatter_H
41 
42 #include "foamVtkFormatter.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 namespace vtk
49 {
50 
51 /*---------------------------------------------------------------------------*\
52  Class vtk::asciiFormatter Declaration
53 \*---------------------------------------------------------------------------*/
54 
55 class asciiFormatter
56 :
57  public formatter
58 {
59  // Private Data Members
60 
61  static const char* name_;
62  static const outputOptions opts_;
63 
64  //- Number of items per line
65  static constexpr unsigned short itemsPerLine_ = 9;
66 
67  //- Track the current output position
68  unsigned short pos_;
69 
70 
71  // Private Member Functions
72 
73  //- Advance to next position, adding space or newline as needed
74  inline void next();
75 
76  //- Finish an output line, adding newline as needed
77  inline void done();
78 
79 
80  //- No copy construct
81  asciiFormatter(const asciiFormatter&) = delete;
82 
83  //- No copy assignment
84  void operator=(const asciiFormatter&) = delete;
85 
86 
87 public:
88 
89  // Constructors
90 
91  //- Construct and attach to an output stream, use default precision
92  asciiFormatter(std::ostream& os);
93 
94  //- Construct and attach to an output stream, use specified precision
95  asciiFormatter(std::ostream& os, unsigned precision);
96 
97 
98  //- Destructor. Finishes the output line as required.
99  virtual ~asciiFormatter();
100 
101 
102  // Member Functions
103 
104  //- The output is INLINE_ASCII.
105  virtual const outputOptions& opts() const;
106 
107  //- Name for the XML output type ("ascii")
108  virtual const char* name() const;
109 
110  //- Name for the XML append encoding - unused.
111  // Currently identical to name(), but do not rely on this.
112  virtual const char* encoding() const;
113 
114 
115  //- Write leading size - this is a no-op for ascii output
116  // \return False - never used by this format
117  virtual bool writeSize(const uint64_t ignored);
118 
119  virtual void write(const uint8_t val);
120  virtual void write(const label val);
121  virtual void write(const float val);
122  virtual void write(const double val);
123 
124  //- Write a newline if needed to finish a line of output.
125  virtual void flush();
126 
127  //- The encoded length for ascii output is not applicable.
128  // \return 0
129  virtual std::size_t encodedLength(std::size_t ignored) const;
130 
131 };
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 } // End namespace vtk
136 } // End namespace Foam
137 
138 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
139 
140 #endif
141 
142 // ************************************************************************* //
Foam::vtk::outputOptions
Encapsulated combinations of output format options. This is primarily useful when defining the output...
Definition: foamVtkOutputOptions.H:59
foamVtkFormatter.H
Foam::vtk::asciiFormatter
Inline ASCII output. Adds spaces between entries and a newline every 9 items (for consistency with wh...
Definition: foamVtkAsciiFormatter.H:54
Foam::vtk::asciiFormatter::opts
virtual const outputOptions & opts() const
The output is INLINE_ASCII.
Definition: foamVtkAsciiFormatter.C:100
Foam::vtk::formatter::os
std::ostream & os()
Access to the underlying output stream.
Definition: foamVtkFormatterI.H:70
Foam::vtk::asciiFormatter::write
virtual void write(const uint8_t val)
Definition: foamVtkAsciiFormatter.C:124
Foam::vtk::asciiFormatter::~asciiFormatter
virtual ~asciiFormatter()
Destructor. Finishes the output line as required.
Definition: foamVtkAsciiFormatter.C:91
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::vtk::asciiFormatter::encodedLength
virtual std::size_t encodedLength(std::size_t ignored) const
The encoded length for ascii output is not applicable.
Definition: foamVtkAsciiFormatter.C:170
Foam::vtk::asciiFormatter::flush
virtual void flush()
Write a newline if needed to finish a line of output.
Definition: foamVtkAsciiFormatter.C:164
Foam::vtk::asciiFormatter::encoding
virtual const char * encoding() const
Name for the XML append encoding - unused.
Definition: foamVtkAsciiFormatter.C:112
Foam::vtk::asciiFormatter::name
virtual const char * name() const
Name for the XML output type ("ascii")
Definition: foamVtkAsciiFormatter.C:106
Foam::vtk::asciiFormatter::writeSize
virtual bool writeSize(const uint64_t ignored)
Write leading size - this is a no-op for ascii output.
Definition: foamVtkAsciiFormatter.C:118
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68