1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 An ordered pair of two objects of type \<T\> with first() and second()
33 Foam::Tuple2 for storing two objects of dissimilar types.
35 \*---------------------------------------------------------------------------*/
40 #include "FixedList.H"
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 /*---------------------------------------------------------------------------*\
49 Class Pair Declaration
50 \*---------------------------------------------------------------------------*/
55 public FixedList<Type, 2>
66 //- Construct from components
67 inline Pair(const Type& f, const Type& s)
73 //- Construct from Istream
74 inline Pair(Istream& is)
76 FixedList<Type, 2>(is)
83 inline const Type& first() const
85 return this->operator[](0);
91 return this->operator[](0);
95 inline const Type& second() const
97 return this->operator[](1);
101 inline Type& second()
103 return this->operator[](1);
106 //- Return reverse pair
107 inline Pair<Type> reversePair() const
109 return Pair<Type>(second(), first());
113 inline const Type& other(const Type& a) const
115 if (first() == second())
117 FatalErrorIn("Pair<Type>::other(const Type&) const")
118 << "Call to other only valid for Pair with differing"
119 << " elements:" << *this << abort(FatalError);
121 else if (first() == a)
129 FatalErrorIn("Pair<Type>::other(const Type&) const")
131 << " does not contain " << a << abort(FatalError);
141 // - -1: same pair, but reversed order
142 static inline int compare(const Pair<Type>& a, const Pair<Type>& b)
144 if (a[0] == b[0] && a[1] == b[1])
148 else if (a[0] == b[1] && a[1] == b[0])
161 friend bool operator==(const Pair<Type>& a, const Pair<Type>& b)
165 (a.first() == b.first()) && (a.second() == b.second())
169 friend bool operator!=(const Pair<Type>& a, const Pair<Type>& b)
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 } // End namespace Foam
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
184 // ************************************************************************* //