00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef Tuple2_H
00037 #define Tuple2_H
00038
00039 #include "Istream.H"
00040
00041
00042
00043 namespace Foam
00044 {
00045
00046
00047
00048 template<class Type1, class Type2>
00049 class Tuple2;
00050
00051 template<class Type1, class Type2>
00052 inline bool operator==
00053 (
00054 const Tuple2<Type1, Type2>&,
00055 const Tuple2<Type1, Type2>&
00056 );
00057
00058 template<class Type1, class Type2>
00059 inline bool operator!=
00060 (
00061 const Tuple2<Type1, Type2>&,
00062 const Tuple2<Type1, Type2>&
00063 );
00064
00065 template<class Type1, class Type2>
00066 inline Istream& operator>>(Istream&, Tuple2<Type1, Type2>&);
00067
00068 template<class Type1, class Type2>
00069 inline Ostream& operator<<(Ostream&, const Tuple2<Type1, Type2>&);
00070
00071
00072
00073
00074
00075
00076 template<class Type1, class Type2>
00077 class Tuple2
00078 {
00079
00080
00081 Type1 f_;
00082 Type2 s_;
00083
00084
00085 public:
00086
00087
00088
00089
00090 inline Tuple2()
00091 {}
00092
00093
00094 inline Tuple2(const Type1& f, const Type2& s)
00095 :
00096 f_(f),
00097 s_(s)
00098 {}
00099
00100
00101 inline Tuple2(Istream& is)
00102 {
00103 is >> *this;
00104 }
00105
00106
00107
00108
00109
00110 inline const Type1& first() const
00111 {
00112 return f_;
00113 }
00114
00115
00116 inline Type1& first()
00117 {
00118 return f_;
00119 }
00120
00121
00122 inline const Type2& second() const
00123 {
00124 return s_;
00125 }
00126
00127
00128 inline Type2& second()
00129 {
00130 return s_;
00131 }
00132
00133
00134 inline Tuple2<Type2, Type1> reverseTuple2() const
00135 {
00136 return Tuple2<Type2, Type1>(second(), first());
00137 }
00138
00139
00140
00141
00142 friend bool operator== <Type1, Type2>
00143 (
00144 const Tuple2<Type1, Type2>& a,
00145 const Tuple2<Type1, Type2>& b
00146 );
00147
00148 friend bool operator!= <Type1, Type2>
00149 (
00150 const Tuple2<Type1, Type2>& a,
00151 const Tuple2<Type1, Type2>& b
00152 );
00153
00154
00155
00156
00157
00158 friend Istream& operator>> <Type1, Type2>
00159 (
00160 Istream& is,
00161 Tuple2<Type1, Type2>& t2
00162 );
00163
00164
00165 friend Ostream& operator<< <Type1, Type2>
00166 (
00167 Ostream& os,
00168 const Tuple2<Type1, Type2>& t2
00169 );
00170 };
00171
00172
00173 template<class Type1, class Type2>
00174 inline bool operator==
00175 (
00176 const Tuple2<Type1, Type2>& a,
00177 const Tuple2<Type1, Type2>& b
00178 )
00179 {
00180 return (a.first() == b.first() && a.second() == b.second());
00181 }
00182
00183
00184 template<class Type1, class Type2>
00185 inline bool operator!=
00186 (
00187 const Tuple2<Type1, Type2>& a,
00188 const Tuple2<Type1, Type2>& b
00189 )
00190 {
00191 return !(a == b);
00192 }
00193
00194
00195 template<class Type1, class Type2>
00196 inline Istream& operator>>(Istream& is, Tuple2<Type1, Type2>& t2)
00197 {
00198 is.readBegin("Tuple2");
00199 is >> t2.f_ >> t2.s_;
00200 is.readEnd("Tuple2");
00201
00202
00203 is.check("operator>>(Istream&, Tuple2<Type1, Type2>&)");
00204
00205 return is;
00206 }
00207
00208
00209 template<class Type1, class Type2>
00210 inline Ostream& operator<<(Ostream& os, const Tuple2<Type1, Type2>& t2)
00211 {
00212 os << token::BEGIN_LIST
00213 << t2.f_ << token::SPACE << t2.s_
00214 << token::END_LIST;
00215
00216 return os;
00217 }
00218
00219
00220
00221
00222 }
00223
00224
00225
00226 #endif
00227
00228