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 Pair_H
00034 #define Pair_H
00035
00036 #include "FixedList.H"
00037 #include "Istream.H"
00038
00039
00040
00041 namespace Foam
00042 {
00043
00044
00045
00046
00047
00048 template<class Type>
00049 class Pair
00050 :
00051 public FixedList<Type, 2>
00052 {
00053
00054 public:
00055
00056
00057
00058
00059 inline Pair()
00060 {}
00061
00062
00063 inline Pair(const Type& f, const Type& s)
00064 {
00065 first() = f;
00066 second() = s;
00067 }
00068
00069
00070 inline Pair(Istream& is)
00071 :
00072 FixedList<Type, 2>(is)
00073 {}
00074
00075
00076
00077
00078
00079 inline const Type& first() const
00080 {
00081 return this->operator[](0);
00082 }
00083
00084
00085 inline Type& first()
00086 {
00087 return this->operator[](0);
00088 }
00089
00090
00091 inline const Type& second() const
00092 {
00093 return this->operator[](1);
00094 }
00095
00096
00097 inline Type& second()
00098 {
00099 return this->operator[](1);
00100 }
00101
00102
00103 inline Pair<Type> reversePair() const
00104 {
00105 return Pair<Type>(second(), first());
00106 }
00107
00108
00109 inline const Type& other(const Type& a) const
00110 {
00111 if (first() == second())
00112 {
00113 FatalErrorIn("Pair<Type>::other(const Type&) const")
00114 << "Call to other only valid for Pair with differing"
00115 << " elements:" << *this << abort(FatalError);
00116 }
00117 else if (first() == a)
00118 {
00119 return second();
00120 }
00121 else
00122 {
00123 if (second() != a)
00124 {
00125 FatalErrorIn("Pair<Type>::other(const Type&) const")
00126 << "Pair " << *this
00127 << " does not contain " << a << abort(FatalError);
00128 }
00129 return first();
00130 }
00131 }
00132
00133
00134
00135
00136 inline friend bool operator==(const Pair<Type>& a, const Pair<Type>& b)
00137 {
00138 return
00139 (
00140 (a.first() == b.first()) && (a.second() == b.second())
00141 );
00142 }
00143
00144 inline friend bool operator!=(const Pair<Type>& a, const Pair<Type>& b)
00145 {
00146 return (!(a == b));
00147 }
00148 };
00149
00150
00151
00152
00153 }
00154
00155
00156
00157 #endif
00158
00159
Copyright © 2000-2007 OpenCFD Ltd