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-2018 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 6 items
32  (for consistency with what VTK itself outputs).
33 
34 SourceFiles
35  foamVtkAsciiFormatter.C
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef foamVtkAsciiFormatter_H
40 #define foamVtkAsciiFormatter_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  //- Track the current output position
65  unsigned short pos_;
66 
67 
68  // Private Member Functions
69 
70  //- Advance to next position, adding space or newline as needed
71  inline void next();
72 
73  //- Finish an output line, adding newline as needed
74  inline void done();
75 
76 
77  //- No copy construct
78  asciiFormatter(const asciiFormatter&) = delete;
79 
80  //- No copy assignment
81  void operator=(const asciiFormatter&) = delete;
82 
83 
84 public:
85 
86  // Constructors
87 
88  //- Construct and attach to an output stream, use default precision
89  asciiFormatter(std::ostream& os);
90 
91  //- Construct and attach to an output stream, use specified precision
92  asciiFormatter(std::ostream& os, unsigned precision);
93 
94 
95  //- Destructor. Finishes the output line as required.
96  virtual ~asciiFormatter();
97 
98 
99  // Member Functions
100 
101  //- The output is INLINE_ASCII.
102  virtual const outputOptions& opts() const;
103 
104  //- Name for the XML output type ("ascii")
105  virtual const char* name() const;
106 
107  //- Name for the XML append encoding - unused.
108  // Currently identical to name(), but do not rely on this.
109  virtual const char* encoding() const;
110 
111 
112  //- Write leading size - this is a no-op for ascii output
113  // \return False - never used by this format
114  virtual bool writeSize(const uint64_t ignored);
115 
116  virtual void write(const uint8_t val);
117  virtual void write(const label val);
118  virtual void write(const float val);
119  virtual void write(const double val);
120 
121  //- Write a newline if needed to finish a line of output.
122  virtual void flush();
123 
124  //- The encoded length for ascii output is not applicable.
125  // \return 0
126  virtual std::size_t encodedLength(std::size_t ignored) const;
127 
128 };
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 } // End namespace vtk
133 } // End namespace Foam
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 #endif
138 
139 // ************************************************************************* //
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 6 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