/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | foam-extend: Open Source CFD \\ / O peration | Version: 3.2 \\ / A nd | Web: http://www.foam-extend.org \\/ M anipulation | For copyright notice see file Copyright ------------------------------------------------------------------------------- License This file is part of foam-extend. foam-extend is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. foam-extend is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with foam-extend. If not, see . Class Foam::Tuple Description A 2 Tuple. Differs from Tuple in that the two elements can be different type. \*---------------------------------------------------------------------------*/ #ifndef Tuple_H #define Tuple_H #include "Istream.H" #include "Ostream.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { // Forward declaration of friend functions and operators template class Tuple; template Istream& operator>>(Istream&, Tuple&); template Ostream& operator<<(Ostream&, const Tuple&); /*---------------------------------------------------------------------------*\ Class Tuple Declaration \*---------------------------------------------------------------------------*/ template class Tuple { // Private data Type1 first_; Type2 second_; public: // Constructors //- Null constructor for lists inline Tuple() {} //- Construct from components inline Tuple(const Type1& first, const Type2& second) : first_(first), second_(second) {} //- Construct from Istream inline Tuple(Istream& is) { // Read beginning of pair is.readBegin("pair"); is >> first_ >> second_; // Read end of pair is.readEnd("pair"); // Check state of Istream is.check("Tuple::Tuple(Istream&)"); } // Member Functions //- Return first inline Type1 first() const { return first_; } //- Return first inline Type1& first() { return first_; } //- Return second inline Type2 second() const { return second_; } //- Return second inline Type2& second() { return second_; } //- Return reverse pair inline Tuple reverseTuple() const { return Tuple(second_, first_); } // Friend Operators inline friend bool operator== ( const Tuple& a, const Tuple& b ) { return ( (a.first_ == b.first_) && (a.second_ == b.second_) ); } inline friend bool operator!= ( const Tuple& a, const Tuple& b ) { return (!(a == b)); } // IOstream Operators friend Istream& operator>> ( Istream& is, Tuple& p ); friend Ostream& operator<< ( Ostream& os, const Tuple& p ); }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template Istream& operator>>(Istream& is, Tuple& p) { // Read beginning of Tuple is.readBegin("Tuple"); is >> p.first_ >> p.second_; // Read end of Tuple is.readEnd("Tuple"); // Check state of Ostream is.check("Istream& operator>>(Istream&, Tuple&)"); return is; } template Ostream& operator<<(Ostream& os, const Tuple& p) { os << token::BEGIN_LIST << p.first_ << token::SPACE << p.second_ << token::END_LIST; // Check state of Ostream os.check("Ostream& operator<<(Ostream&, const Tuple&)"); return os; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* //