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 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 inline void Foam::labelledTri::assign(const labelUList& lst)
34 {
35  const label sz = lst.size();
36 
37  // checkSize
38  if (sz < 3 || sz > 4)
39  {
41  << "size " << sz << " != (3 or 4)"
42  << abort(FatalError);
43  }
44 
45  for (label i=0; i<3; ++i)
46  {
47  operator[](i) = lst[i];
48  }
49 
50  region_ = (sz > 3 ? lst[3] : 0);
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
57 :
58  triFace(),
59  region_(-1)
60 {}
61 
62 
64 (
65  const triFace& tri,
66  const label region
67 )
68 :
69  triFace(tri),
70  region_(region)
71 {}
72 
73 
75 (
76  const label a,
77  const label b,
78  const label c,
79  const label region
80 )
81 :
82  triFace(a, b, c),
83  region_(region)
84 {}
85 
86 
88 :
89  triFace(),
90  region_(0)
91 {
92  assign(lst);
93 }
94 
95 
96 inline Foam::labelledTri::labelledTri(std::initializer_list<label> initLst)
97 :
98  triFace(),
99  region_(0)
100 {
101  assign(labelList(initLst));
102 }
103 
104 
106 {
107  operator>>(is, *this);
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
113 inline Foam::label Foam::labelledTri::region() const
114 {
115  return region_;
116 }
117 
118 inline Foam::label& Foam::labelledTri::region()
119 {
120  return region_;
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
125 
127 {
128  if (is.format() == IOstream::ASCII)
129  {
130  is.readBegin("labelledTri");
131 
132  is >> static_cast<triFace&>(t) >> t.region_;
133 
134  is.readEnd("labelledTri");
135  }
136  else
137  {
138  Detail::readContiguous<labelledTri>
139  (
140  is,
141  reinterpret_cast<char*>(&t),
142  sizeof(labelledTri)
143  );
144  }
145 
146  is.check(FUNCTION_NAME);
147  return is;
148 }
149 
150 
152 {
153  if (os.format() == IOstream::ASCII)
154  {
155  os << token::BEGIN_LIST
156  << static_cast<const triFace&>(t) << token::SPACE << t.region_
157  << token::END_LIST;
158  }
159  else
160  {
161  os.write
162  (
163  reinterpret_cast<const char*>(&t),
164  sizeof(labelledTri)
165  );
166  }
167 
168  os.check(FUNCTION_NAME);
169  return os;
170 }
171 
172 
173 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
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:289
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:127
Foam::Istream::readBegin
bool readBegin(const char *funcName)
Begin read of data chunk, starts with '('.
Definition: Istream.C:109
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::region
label region() const
Return region label.
Definition: labelledTriI.H:113
Foam::labelledTri::labelledTri
labelledTri()
Default construct, with invalid point labels and region (-1).
Definition: labelledTriI.H:56
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:51
Foam::FatalError
error FatalError
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
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:392
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
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:117
Foam::UList< label >
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:57
Foam::token::END_LIST
End list [isseparator].
Definition: token.H:123
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::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
Foam::token::BEGIN_LIST
Begin list [isseparator].
Definition: token.H:122
triFace
face triFace(3)