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