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 {
39  openTag(vtk::fileTag::DATA_ARRAY);
40  xmlAttr("type", vtkPTraits<Type>::typeName);
41  xmlAttr("Name", dataName);
42 
43  if (nComp > 1)
44  {
45  xmlAttr(fileAttr::NUMBER_OF_COMPONENTS, int(nComp));
46  }
47  if (nTuple > 0)
48  {
49  xmlAttr(fileAttr::NUMBER_OF_TUPLES, nTuple);
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 // ************************************************************************* //
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::vtkPTraits
Names for VTK primitive types.
Definition: foamVtkPTraits.H:52
Foam::vtk::formatter::beginDataArray
formatter & beginDataArray(const word &dataName, uint64_t payLoad=npos, bool leaveOpen=false)
Begin "DataArray" XML section.
Foam::vtk::formatter::PDataArray
formatter & PDataArray(const word &dataName)
Insert a single "PDataArray" XML entry tag.
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
foamVtkPTraits.H
Foam::vtk::formatter
Abstract class for a VTK output stream formatter.
Definition: foamVtkFormatter.H:68