1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 A 2 Tuple. Differs from Tuple in that the two elements can be different
32 \*---------------------------------------------------------------------------*/
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 // Forward declaration of friend functions and operators
47 template<class Type1, class Type2>
50 template<class Type1, class Type2>
51 Istream& operator>>(Istream&, Tuple<Type1, Type2>&);
53 template<class Type1, class Type2>
54 Ostream& operator<<(Ostream&, const Tuple<Type1, Type2>&);
56 /*---------------------------------------------------------------------------*\
57 Class Tuple Declaration
58 \*---------------------------------------------------------------------------*/
60 template<class Type1, class Type2>
73 //- Null constructor for lists
77 //- Construct from components
78 inline Tuple(const Type1& first, const Type2& second)
84 //- Construct from Istream
85 inline Tuple(Istream& is)
87 // Read beginning of pair
90 is >> first_ >> second_;
95 // Check state of Istream
96 is.check("Tuple::Tuple(Istream&)");
103 inline Type1 first() const
109 inline Type1& first()
115 inline Type2 second() const
121 inline Type2& second()
126 //- Return reverse pair
127 inline Tuple<Type1, Type2> reverseTuple() const
129 return Tuple<Type1, Type2>(second_, first_);
135 inline friend bool operator==
137 const Tuple<Type1, Type2>& a,
138 const Tuple<Type1, Type2>& b
143 (a.first_ == b.first_) && (a.second_ == b.second_)
147 inline friend bool operator!=
149 const Tuple<Type1, Type2>& a,
150 const Tuple<Type1, Type2>& b
157 // IOstream Operators
159 friend Istream& operator>> <Type1, Type2>
162 Tuple<Type1, Type2>& p
164 friend Ostream& operator<< <Type1, Type2>
167 const Tuple<Type1, Type2>& p
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 template<class Type1, class Type2>
175 Istream& operator>>(Istream& is, Tuple<Type1, Type2>& p)
177 // Read beginning of Tuple<Type, Type>
178 is.readBegin("Tuple<Type, Type>");
180 is >> p.first_ >> p.second_;
182 // Read end of Tuple<Type, Type>
183 is.readEnd("Tuple<Type, Type>");
185 // Check state of Ostream
186 is.check("Istream& operator>>(Istream&, Tuple<Type, Type>&)");
191 template<class Type1, class Type2>
192 Ostream& operator<<(Ostream& os, const Tuple<Type1, Type2>& p)
194 os << token::BEGIN_LIST
195 << p.first_ << token::SPACE
199 // Check state of Ostream
200 os.check("Ostream& operator<<(Ostream&, const Tuple<Type, Type>&)");
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 } // End namespace Foam
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
214 // ************************************************************************* //