foamVtkFormatterTemplates.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-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 
27 #include "foamVtkPTraits.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<class Type, Foam::direction nComp, int nTuple>
33 (
34  const word& dataName,
35  uint64_t payLoad,
36  bool leaveOpen
37 )
38 {
41  xmlAttr("Name", dataName);
42 
43  if (nComp > 1)
44  {
46  }
47  if (nTuple > 0)
48  {
50  }
51  xmlAttr("format", name());
52 
53  if (formatter::npos != payLoad)
54  {
55  uint64_t off = offset(payLoad);
56  if (formatter::npos != off)
57  {
58  xmlAttr("offset", off);
59  }
60  }
61 
62  if (!leaveOpen)
63  {
64  closeTag();
65  }
66 
67  return *this;
68 }
69 
70 
71 template<class Type, Foam::direction nComp, int nTuple>
73 (
74  const word& dataName
75 )
76 {
77  openTag("PDataArray");
78  xmlAttr("type", vtkPTraits<Type>::typeName);
79 
80  if (dataName.size())
81  {
82  xmlAttr("Name", dataName);
83  }
84  if (nComp > 1)
85  {
86  xmlAttr(fileAttr::NUMBER_OF_COMPONENTS, int(nComp));
87  }
88  if (nTuple > 0)
89  {
90  xmlAttr(fileAttr::NUMBER_OF_TUPLES, nTuple);
91  }
92 
93  closeTag(true);
94 
95  return *this;
96 }
97 
98 
99 // ************************************************************************* //
Abstract class for a VTK output stream formatter.
formatter & closeTag(const bool isEmpty=false)
Finish an XML tag, optional as an empty container.
formatter & PDataArray(const word &dataName)
Insert a single "PDataArray" XML entry tag.
virtual uint64_t offset(const uint64_t numbytes)
Increase the append data offset by numbytes and sizeof(uint64_t).
formatter & beginDataArray(const word &dataName, uint64_t payLoad=npos, bool leaveOpen=false)
Begin "DataArray" XML section.
A class for handling words, derived from Foam::string.
Definition: word.H:63
static constexpr uint64_t npos
Out of range position or size.
Names for VTK primitive types.
virtual const char * name() const =0
Name for the XML output type or the legacy output type.
formatter & openTag(const word &tagName, Args &&... args)
Start an XML tag, optionally with attributes.
formatter & xmlAttr()
No-op write XML attribute (for templating code).