foamGltfList.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) 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 \*---------------------------------------------------------------------------*/
27 
28 #include "foamGltfList.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class Type>
34 {
35  Type obj(name);
36  obj.id() = data_.size();
37  data_.append(obj);
38 
39  return data_.last();
40 }
41 
42 
43 template<class Type>
45 {
46  return data_;
47 }
48 
49 
50 template<class Type>
51 bool Foam::glTF::List<Type>::empty() const noexcept
52 {
53  return data_.empty();
54 }
55 
56 
57 template<class Type>
58 Foam::label Foam::glTF::List<Type>::size() const noexcept
59 {
60  return data_.size();
61 }
62 
63 
64 template<class Type>
66 (
67  Ostream& os,
68  const word& keyword,
69  bool firstEntry
70 )
71 {
72  if (empty())
73  {
74  return;
75  }
76 
77  if (!firstEntry)
78  {
79  os << "," << nl;
80  }
81 
82  os << indent << "\"" << keyword << "\" : [" << nl << incrIndent;
83 
85 
86  os << decrIndent << nl << indent << "]";
87 }
88 
89 
90 template<class Type>
92 {
93  forAll(data_, i)
94  {
95  os << indent << "{"
96  << nl << incrIndent
97  << data_[i]
98  << nl << decrIndent
99  << indent << "}";
100 
101  if (i != data_.size() - 1) os << "," << nl;
102  }
103 }
104 
105 
106 template<class Type>
107 Type& Foam::glTF::List<Type>::operator[](const label i)
108 {
109  return data_[i];
110 }
111 
112 
113 template<class Type>
114 Foam::Ostream& Foam::operator<<(Ostream& os, const glTF::List<Type>& lst)
115 {
116  lst.write(os);
117 
118  return os;
119 }
120 
121 
122 // ************************************************************************* //
Foam::glTF::List::size
label size() const noexcept
Definition: foamGltfList.C:51
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
foamGltfList.H
Foam::DynamicList< Type >
Foam::incrIndent
Ostream & incrIndent(Ostream &os)
Definition: Ostream.H:352
forAll
#define forAll(list, i)
Definition: stdFoam.H:349
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Definition: boundaryPatch.C:76
Foam::glTF::List::create
Type & create(const word &name)
Definition: foamGltfList.C:26
Foam::glTF::List::write
void write(Ostream &os, const word &keyword, bool firstEntry=false)
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Ostream::write
virtual bool write(const token &tok)=0
Foam::decrIndent
Ostream & decrIndent(Ostream &os)
Definition: Ostream.H:361
Foam::glTF::List::data
const DynamicList< Type > & data() const noexcept
Definition: foamGltfList.C:37
Foam::indent
Ostream & indent(Ostream &os)
Definition: Ostream.H:343
Foam::glTF::List
Container for glTF entities.
Definition: foamGltfList.H:47
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::glTF::List::empty
bool empty() const noexcept
Definition: foamGltfList.C:44
Foam::glTF::List::operator[]
Type & operator[](const label i)
Definition: foamGltfList.C:100
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Definition: foamVtkOutputTemplates.C:29
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52