Tuple2.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 | Copyright (C) 2011-2013 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 SeeAlso
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>
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  // Constructors
73 
74  //- Null constructor for lists
75  inline Tuple2()
76  {}
77 
78  //- Construct from components
79  inline Tuple2(const Type1& f, const Type2& s)
80  :
81  f_(f),
82  s_(s)
83  {}
84 
85  //- Construct from Istream
86  inline Tuple2(Istream& is)
87  {
88  is >> *this;
89  }
90 
91 
92  // Member Functions
93 
94  //- Return first
95  inline const Type1& first() const
96  {
97  return f_;
98  }
99 
100  //- Return first
101  inline Type1& first()
102  {
103  return f_;
104  }
105 
106  //- Return second
107  inline const Type2& second() const
108  {
109  return s_;
110  }
111 
112  //- Return second
113  inline Type2& second()
114  {
115  return s_;
116  }
117 
118 
119  // IOstream operators
120 
121  //- Read Tuple2 from Istream, discarding contents of existing Tuple2.
122  friend Istream& operator>> <Type1, Type2>
123  (
124  Istream& is,
126  );
127 
128  // Write Tuple2 to Ostream.
129  friend Ostream& operator<< <Type1, Type2>
130  (
131  Ostream& os,
132  const Tuple2<Type1, Type2>& t2
133  );
134 };
135 
136 
137 //- Return reverse of a tuple2
138 template<class Type1, class Type2>
140 {
141  return Tuple2<Type2, Type1>(t.second(), t.first());
142 }
143 
144 
145 template<class Type1, class Type2>
146 inline bool operator==
147 (
148  const Tuple2<Type1, Type2>& a,
149  const Tuple2<Type1, Type2>& b
150 )
151 {
152  return (a.first() == b.first() && a.second() == b.second());
153 }
154 
155 
156 template<class Type1, class Type2>
157 inline bool operator!=
158 (
159  const Tuple2<Type1, Type2>& a,
160  const Tuple2<Type1, Type2>& b
161 )
162 {
163  return !(a == b);
164 }
165 
166 
167 template<class Type1, class Type2>
169 {
170  is.readBegin("Tuple2");
171  is >> t2.f_ >> t2.s_;
172  is.readEnd("Tuple2");
173 
174  // Check state of Istream
175  is.check("operator>>(Istream&, Tuple2<Type1, Type2>&)");
176 
177  return is;
178 }
179 
180 
181 template<class Type1, class Type2>
182 inline Ostream& operator<<(Ostream& os, const Tuple2<Type1, Type2>& t2)
183 {
184  os << token::BEGIN_LIST
185  << t2.f_ << token::SPACE << t2.s_
186  << token::END_LIST;
187 
188  return os;
189 }
190 
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 } // End namespace Foam
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 #endif
199 
200 // ************************************************************************* //
const Type2 & second() const
Return second.
Definition: Tuple2.H:106
A 2-tuple for storing two objects of different types.
Definition: Tuple2.H:47
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 ))
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
labelList f(nPoints)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const Type1 & first() const
Return first.
Definition: Tuple2.H:94
Namespace for OpenFOAM.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Tuple2()
Null constructor for lists.
Definition: Tuple2.H:74
Istream & readBegin(const char *funcName)
Definition: Istream.C:88
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void reverse(UList< T > &, const label n)
Definition: UListI.H:322
friend Istream & operator>>(Istream &is, Tuple2< Type1, Type2 > &t2)
Read Tuple2 from Istream, discarding contents of existing Tuple2.
Definition: Tuple2.H:167
Istream & readEnd(const char *funcName)
Definition: Istream.C:105