All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tuple2.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) 2011-2019 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::Tuple2
26 
27 Description
28  A 2-tuple for storing two objects of different types.
29 
30 See also
31  Foam::Pair for storing two objects of identical types.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef Tuple2_H
36 #define Tuple2_H
37 
38 #include "Istream.H"
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 namespace Foam
43 {
44 
45 // Forward declaration of friend functions and operators
46 
47 template<class Type1, class Type2>
48 class Tuple2;
49 
50 template<class Type1, class Type2>
51 inline Istream& operator>>(Istream&, Tuple2<Type1, Type2>&);
52 
53 template<class Type1, class Type2>
54 inline Ostream& operator<<(Ostream&, const Tuple2<Type1, Type2>&);
55 
56 
57 /*---------------------------------------------------------------------------*\
58  class Tuple2 Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 template<class Type1, class Type2>
62 class Tuple2
63 {
64  // Private Data
65 
66  Type1 f_;
67  Type2 s_;
68 
69 
70 public:
71 
72  // Static Data Members
73 
74  static const char* const typeName;
75 
76 
77  // Constructors
78 
79  //- Null constructor for lists
80  inline Tuple2()
81  {}
82 
83  //- Construct from components
84  inline Tuple2(const Type1& f, const Type2& s)
85  :
86  f_(f),
87  s_(s)
88  {}
89 
90  //- Construct from Istream
91  inline Tuple2(Istream& is)
92  {
93  is >> *this;
94  }
95 
96 
97  // Member Functions
98 
99  //- Return first
100  inline const Type1& first() const
101  {
102  return f_;
103  }
104 
105  //- Return first
106  inline Type1& first()
107  {
108  return f_;
109  }
110 
111  //- Return second
112  inline const Type2& second() const
113  {
114  return s_;
115  }
116 
117  //- Return second
118  inline Type2& second()
119  {
120  return s_;
121  }
122 
123 
124  // IOstream Operators
125 
126  //- Read Tuple2 from Istream, discarding contents of existing Tuple2.
127  friend Istream& operator>> <Type1, Type2>
128  (
129  Istream& is,
131  );
132 
133  // Write Tuple2 to Ostream.
134  friend Ostream& operator<< <Type1, Type2>
135  (
136  Ostream& os,
137  const Tuple2<Type1, Type2>& t2
138  );
139 };
140 
141 
142 //- Return reverse of a tuple2
143 template<class Type1, class Type2>
145 {
146  return Tuple2<Type2, Type1>(t.second(), t.first());
147 }
148 
149 
150 template<class Type1, class Type2>
151 inline bool operator==
152 (
153  const Tuple2<Type1, Type2>& a,
154  const Tuple2<Type1, Type2>& b
155 )
156 {
157  return (a.first() == b.first() && a.second() == b.second());
158 }
159 
160 
161 template<class Type1, class Type2>
162 inline bool operator!=
163 (
164  const Tuple2<Type1, Type2>& a,
165  const Tuple2<Type1, Type2>& b
166 )
167 {
168  return !(a == b);
169 }
170 
171 
172 template<class Type1, class Type2>
174 {
175  is.readBegin("Tuple2");
176  is >> t2.f_ >> t2.s_;
177  is.readEnd("Tuple2");
178 
179  // Check state of Istream
180  is.check("operator>>(Istream&, Tuple2<Type1, Type2>&)");
181 
182  return is;
183 }
184 
185 
186 template<class Type1, class Type2>
187 inline Ostream& operator<<(Ostream& os, const Tuple2<Type1, Type2>& t2)
188 {
189  os << token::BEGIN_LIST
190  << t2.f_ << token::SPACE << t2.s_
191  << token::END_LIST;
192 
193  return os;
194 }
195 
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 } // End namespace Foam
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #endif
204 
205 // ************************************************************************* //
Istream & readBegin(const char *funcName)
Definition: Istream.C:86
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
A 2-tuple for storing two objects of different types.
Definition: HashTable.H:65
const Type1 & first() const
Return first.
Definition: Tuple2.H:99
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Istream & readEnd(const char *funcName)
Definition: Istream.C:103
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.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
friend Istream & operator>>(Istream &is, Tuple2< Type1, Type2 > &t2)
Read Tuple2 from Istream, discarding contents of existing Tuple2.
Definition: Tuple2.H:172
const dimensionedScalar & b
Wien displacement law constant: default SI units: [m K].
Definition: createFields.H:27
Istream & operator>>(Istream &, directionInfo &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void reverse(UList< T > &, const label n)
Definition: UListI.H:322
labelList f(nPoints)
Tuple2()
Null constructor for lists.
Definition: Tuple2.H:79
const Type2 & second() const
Return second.
Definition: Tuple2.H:111
static const char *const typeName
Definition: Tuple2.H:73
Namespace for OpenFOAM.