labelledTriI.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) 2011 OpenFOAM Foundation
9  Copyright (C) 2016-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "IOstreams.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class ListType>
34 inline void Foam::labelledTri::assignList(const ListType& list)
35 {
36  const label len = list.size();
37 
38  // checkSize
39  if (len < 3 || len > 4)
40  {
42  << "size " << len << " != (3 or 4)"
43  << abort(FatalError);
44  }
45 
46  auto iter = list.begin();
47 
48  for (label i=0; i<3; ++i)
49  {
50  this->operator[](i) = *iter;
51  ++iter;
52  }
53 
54  index_ = (len == 4) ? *iter : 0;
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
59 
61 :
62  triFace(),
63  index_(-1)
64 {}
65 
66 
68 (
69  const triFace& tri,
70  const label region
71 )
72 :
73  triFace(tri),
74  index_(region)
75 {}
76 
77 
79 (
80  const label a,
81  const label b,
82  const label c,
83  const label region
84 )
85 :
86  triFace(a, b, c),
87  index_(region)
88 {}
89 
90 
92 :
93  triFace(),
94  index_(0)
95 {
96  assignList(list);
97 }
98 
99 
100 inline Foam::labelledTri::labelledTri(std::initializer_list<label> list)
101 :
102  triFace(),
103  index_(0)
104 {
105  assignList(list);
106 }
107 
108 
110 {
111  operator>>(is, *this);
112 }
113 
114 
115 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
116 
118 {
119  if (is.format() == IOstream::ASCII)
120  {
121  is.readBegin("labelledTri");
122 
123  is >> static_cast<triFace&>(t) >> t.index();
124 
125  is.readEnd("labelledTri");
126  }
127  else
128  {
129  Detail::readContiguous<labelledTri>
130  (
131  is,
132  reinterpret_cast<char*>(&t),
133  sizeof(labelledTri)
134  );
135  }
136 
137  is.check(FUNCTION_NAME);
138  return is;
139 }
140 
141 
143 {
144  if (os.format() == IOstream::ASCII)
145  {
147  << static_cast<const triFace&>(t) << token::SPACE << t.index()
148  << token::END_LIST;
149  }
150  else
151  {
152  os.write
153  (
154  reinterpret_cast<const char*>(&t),
155  sizeof(labelledTri)
156  );
157  }
158 
160  return os;
161 }
162 
163 
164 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:286
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::Istream::readEnd
bool readEnd(const char *funcName)
End read of data chunk, ends with ')'.
Definition: Istream.C:129
Foam::OBJstream::write
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
Foam::Istream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:111
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::labelledTri::index
label index() const noexcept
Return the index (eg, the region)
Definition: labelledTri.H:112
Foam::labelledTri::labelledTri
labelledTri()
Default construct, with invalid point labels and region (-1).
Definition: labelledTriI.H:60
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
Foam::FatalError
error FatalError
os
OBJstream os(runTime.globalPath()/outputName)
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::FixedList< label, 3 >::operator[]
label & operator[](const label i)
Return element of FixedList.
Definition: FixedListI.H:412
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::triFace
A triangular face using a FixedList of labels corresponding to mesh vertices.
Definition: triFace.H:69
Foam::token::SPACE
Space [isspace].
Definition: token.H:125
Foam::UList< label >
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::labelledTri
A triFace with additional (region) index.
Definition: labelledTri.H:57
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:156
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
triFace
face triFace(3)