Tuple3.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2023 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::Tuple3
26 
27 Description
28  A 3-tuple for storing three objects of different types.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef Tuple3_H
33 #define Tuple3_H
34 
35 #include "Istream.H"
36 #include "Hash.H"
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // Forward declaration of friend functions and operators
44 
45 template<class Type1, class Type2, class Type3>
46 class Tuple3;
47 
48 template<class Type1, class Type2, class Type3>
49 inline Istream& operator>>(Istream&, Tuple3<Type1, Type2, Type3>&);
50 
51 template<class Type1, class Type2, class Type3>
52 inline Ostream& operator<<(Ostream&, const Tuple3<Type1, Type2, Type3>&);
53 
54 
55 /*---------------------------------------------------------------------------*\
56  Class Tuple3 Declaration
57 \*---------------------------------------------------------------------------*/
58 
59 template<class Type1, class Type2, class Type3>
60 class Tuple3
61 {
62  // Private Data
63 
64  Type1 f_;
65  Type2 s_;
66  Type3 t_;
67 
68 
69 public:
70 
71  //- Hashing function class
72  template
73  <
74  class HashT1=Hash<Type1>,
75  class HashT2=Hash<Type2>,
76  class HashT3=Hash<Type3>
77  >
78  class Hash
79  {
80  public:
81  Hash()
82  {}
83 
84  inline unsigned operator()
85  (
87  unsigned seed = 0
88  ) const;
89  };
90 
91 
92  // Static Data Members
93 
94  static const char* const typeName;
95 
96 
97  // Constructors
98 
99  //- Null constructor for lists
100  inline Tuple3()
101  {}
102 
103  //- Construct from components
104  inline Tuple3(const Type1& f, const Type2& s, const Type3& t)
105  :
106  f_(f),
107  s_(s),
108  t_(t)
109  {}
110 
111  //- Construct from Istream
112  inline Tuple3(Istream& is)
113  {
114  is >> *this;
115  }
116 
117 
118  // Member Functions
119 
120  //- Return first
121  inline const Type1& first() const
122  {
123  return f_;
124  }
125 
126  //- Return first
127  inline Type1& first()
128  {
129  return f_;
130  }
131 
132  //- Return second
133  inline const Type2& second() const
134  {
135  return s_;
136  }
137 
138  //- Return second
139  inline Type2& second()
140  {
141  return s_;
142  }
143 
144  //- Return third
145  inline const Type3& third() const
146  {
147  return t_;
148  }
149 
150  //- Return third
151  inline Type3& third()
152  {
153  return t_;
154  }
155 
156  // IOstream Operators
157 
158  //- Read Tuple3 from Istream, discarding contents of existing Tuple3.
159  friend Istream& operator>> <Type1, Type2, Type3>
160  (
161  Istream& is,
163  );
164 
165  // Write Tuple3 to Ostream.
166  friend Ostream& operator<< <Type1, Type2, Type3>
167  (
168  Ostream& os,
170  );
171 };
172 
173 
174 template<class Type1, class Type2, class Type3>
175 template<class HashT1, class HashT2, class HashT3>
176 inline unsigned
178 (
180  unsigned seed
181 ) const
182 {
183  // Hash incrementally
184  unsigned val = seed;
185  val = HashT1()(t.first(), val);
186  val = HashT2()(t.second(), val);
187  val = HashT3()(t.third(), val);
188  return val;
189 }
190 
191 
192 //- Return reverse of a tuple3
193 template<class Type1, class Type2, class Type3>
195 (
197 )
198 {
199  return Tuple3<Type3, Type2, Type1>(t.third(), t.second(), t.first());
200 }
201 
202 
203 template<class Type1, class Type2, class Type3>
204 inline bool operator==
205 (
208 )
209 {
210  return
211  (
212  a.first() == b.first()
213  && a.second() == b.second()
214  && a.third() == b.third()
215  );
216 }
217 
218 
219 template<class Type1, class Type2, class Type3>
220 inline bool operator!=
221 (
224 )
225 {
226  return !(a == b);
227 }
228 
229 
230 template<class Type1, class Type2, class Type3>
232 {
233  is.readBegin("Tuple3");
234  is >> t3.f_ >> t3.s_ >> t3.t_;
235  is.readEnd("Tuple3");
236 
237  // Check state of Istream
238  is.check("operator>>(Istream&, Tuple3<Type1, Type2, Type3>&)");
239 
240  return is;
241 }
242 
243 
244 template<class Type1, class Type2, class Type3>
246 {
247  os << token::BEGIN_LIST
248  << t2.f_ << token::SPACE << t2.s_ << token::SPACE << t2.t_
249  << token::END_LIST;
250 
251  return os;
252 }
253 
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 } // End namespace Foam
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 #endif
262 
263 // ************************************************************************* //
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Hashing function class.
Definition: Tuple3.H:78
A 3-tuple for storing three objects of different types.
Definition: Tuple3.H:60
static const char *const typeName
Definition: Tuple3.H:93
const Type3 & third() const
Return third.
Definition: Tuple3.H:144
const Type2 & second() const
Return second.
Definition: Tuple3.H:132
friend Ostream & operator(Ostream &os, const Tuple3< Type1, Type2, Type3 > &t3)
const Type1 & first() const
Return first.
Definition: Tuple3.H:120
Tuple3()
Null constructor for lists.
Definition: Tuple3.H:99
T & first()
Return the first element of the list.
Definition: UListI.H:114
@ BEGIN_LIST
Definition: token.H:106
@ END_LIST
Definition: token.H:107
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
volScalarField & b
Definition: createFields.H:27
Namespace for OpenFOAM.
void reverse(UList< T > &, const label n)
Definition: UListI.H:334
Istream & operator>>(Istream &, directionInfo &)
Ostream & operator<<(Ostream &, const ensightPart &)
labelList f(nPoints)