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 #ifndef Tuple2_H
00034 #define Tuple2_H
00035
00036 #include "Istream.H"
00037
00038
00039
00040 namespace Foam
00041 {
00042
00043
00044
00045 template<class Type1, class Type2>
00046 class Tuple2;
00047
00048 template<class Type1, class Type2>
00049 Istream& operator>>(Istream&, Tuple2<Type1, Type2>&);
00050
00051 template<class Type1, class Type2>
00052 Ostream& operator<<(Ostream&, const Tuple2<Type1, Type2>&);
00053
00054
00055
00056
00057
00058
00059 template<class Type1, class Type2>
00060 class Tuple2
00061 {
00062
00063
00064 Type1 f_;
00065 Type2 s_;
00066
00067
00068 public:
00069
00070
00071
00072
00073 inline Tuple2()
00074 {}
00075
00076
00077 inline Tuple2(const Type1& f, const Type2& s)
00078 :
00079 f_(f),
00080 s_(s)
00081 {}
00082
00083
00084 inline Tuple2(Istream& is)
00085 {
00086 operator>>(is, *this);
00087 }
00088
00089
00090
00091
00092
00093 inline const Type1& first() const
00094 {
00095 return f_;
00096 }
00097
00098
00099 inline Type1& first()
00100 {
00101 return f_;
00102 }
00103
00104
00105 inline const Type2& second() const
00106 {
00107 return s_;
00108 }
00109
00110
00111 inline Type2& second()
00112 {
00113 return s_;
00114 }
00115
00116
00117 inline Tuple2<Type2, Type1> reverseTuple2() const
00118 {
00119 return Tuple2<Type2, Type1>(second(), first());
00120 }
00121
00122
00123
00124
00125 inline friend bool operator==
00126 (
00127 const Tuple2<Type1, Type2>& a,
00128 const Tuple2<Type1, Type2>& b
00129 )
00130 {
00131 return
00132 (
00133 (a.first() == b.first()) && (a.second() == b.second())
00134 );
00135 }
00136
00137 inline friend bool operator!=
00138 (
00139 const Tuple2<Type1, Type2>& a,
00140 const Tuple2<Type1, Type2>& b
00141 )
00142 {
00143 return (!(a == b));
00144 }
00145
00146
00147
00148
00149
00150 friend Istream& operator>> <Type1, Type2>
00151 (
00152 Istream& is,
00153 Tuple2<Type1, Type2>& t2
00154 );
00155
00156
00157 friend Ostream& operator<< <Type1, Type2>
00158 (
00159 Ostream& os,
00160 const Tuple2<Type1, Type2>& t2
00161 );
00162 };
00163
00164
00165 template<class Type1, class Type2>
00166 inline Istream& operator>>(Istream& is, Tuple2<Type1, Type2>& t2)
00167 {
00168 is.readBegin("Tuple2");
00169 is >> t2.f_ >> t2.s_;
00170 is.readEnd("Tuple2");
00171
00172
00173 is.check("operator>>(Istream&, Tuple2<Type1, Type2>&)");
00174
00175 return is;
00176 }
00177
00178
00179 template<class Type1, class Type2>
00180 inline Ostream& operator<<(Ostream& os, const Tuple2<Type1, Type2>& t2)
00181 {
00182 os << token::BEGIN_LIST
00183 << t2.f_ << token::SPACE << t2.s_
00184 << token::END_LIST;
00185
00186 return os;
00187 }
00188
00189
00190
00191
00192 }
00193
00194
00195
00196 #endif
00197
00198
Copyright © 2000-2007 OpenCFD Ltd