00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Benjamin Hadorn (bhadorn@swissinfo.org) * 00003 *************************************************************************** 00004 * Projekt : Zeus 00005 * Module : Pair 00006 * Package : System 00007 * Author : Benjamin Hadorn 00008 * Datum : $Date: 5.10.09 22:25 $ 00009 * Ablage : $File$ 00010 * System : Cell Computing Model 00011 *************************************************************************** 00012 * Licence: * 00013 * This library is free software; you can redistribute it and/or modify * 00014 * it under the terms of the GNU Lesser General Public License as * 00015 * published by the Free Software Foundation; either version * 00016 * 2.1 of the License, or (at your option) any later version. * 00017 * * 00018 * This library is distributed in the hope that it will be useful, * 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00021 * GNU Lesser General Public License for more details. * 00022 * * 00023 * You should have received a copy of the GNU Lesser General Public * 00024 * License along with this library; if not, write to the Free Software * 00025 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00026 ***************************************************************************/ 00027 00028 /*************************************************************************** 00029 Changes : 00030 $Log: /Development_F/StuderWIN/dev/Zeus/src/zeusbase/System/Pair.hpp $ 00031 ** 00032 ** 5 5.10.09 22:25 Bha 00033 ** improving speed using inline methods 00034 ** 00035 ** 4 7.01.08 9:02 Bha 00036 ** compare operator for maps implemented 00037 ** 00038 ** 3 3.09.07 7:03 bha 00039 ** New Framework using auto pointer and improved lists 00040 ** 00041 ** 2 5.07.07 13:15 bha 00042 ** implementation of opertators 00043 ** 00044 ** 1 2.07.07 7:18 bha 00045 ** Pair class for value pairs created 00046 ***************************************************************************/ 00047 00048 00049 #ifndef PairHPP 00050 #define PairHPP 00051 00052 #include <zeusbase/System/Interfaces/IPair.hpp> 00053 #include <zeusbase/System/ZObject.h> 00054 00055 BEGIN_NAMESPACE_Zeus 00056 00057 /***************************************************************************/ 00061 /***************************************************************************/ 00062 template <class T1, class T2> class TPair 00063 : public TZObject, 00064 public IPair<T1, T2> 00065 { 00066 public: 00067 /************************************************************************/ 00070 /************************************************************************/ 00071 inline TPair() 00072 /* COMPILER PROBLEM*/ 00073 /*#ifdef A_COMPILER_TYPE 00074 : m_tValue1(getDefaultEmpty()), 00075 m_tValue2(getDefaultEmpty()) 00076 #else 00077 : m_tValue1(T()), 00078 m_tValue2(T()) 00079 #endif 00080 */ 00081 : m_tValue1(T1()), 00082 m_tValue2(T2()) 00083 { 00084 // DO NOT USE MEMSET. This causes memory leaks on complex objects 00085 //memset(&m_tEmpty, 0, sizeof(T)); 00086 } 00087 00088 /************************************************************************/ 00091 /************************************************************************/ 00092 inline TPair(const T1& rValue1, const T2& rValue2) 00093 : m_tValue1(rValue1), 00094 m_tValue2(rValue2) 00095 {} 00096 00097 /************************************************************************/ 00100 /************************************************************************/ 00101 inline TPair(const TPair<T1, T2>& rValue) 00102 : m_tValue1((T1&)rValue.getFirstConst()), 00103 m_tValue2((T2&)rValue.getSecondConst()) 00104 {} 00105 00106 /************************************************************************/ 00109 /************************************************************************/ 00110 inline TPair(const IPair<T1, T2>& rValue) 00111 : m_tValue1((T1&)rValue.getFirstConst()), 00112 m_tValue2((T2&)rValue.getSecondConst()) 00113 {} 00114 00115 /************************************************************************/ 00118 /************************************************************************/ 00119 inline virtual ~TPair() 00120 { 00121 } 00122 00123 /***********************************************************************/ 00126 /***********************************************************************/ 00127 inline virtual void MQUALIFIER assign(const IPair<T1, T2>& rPair) 00128 { 00129 m_tValue1 = rPair.getFirstConst(); 00130 m_tValue2 = rPair.getSecondConst(); 00131 } 00132 00133 /***********************************************************************/ 00136 /***********************************************************************/ 00137 inline virtual bool MQUALIFIER equals(const IPair<T1, T2>& rPair) const 00138 { 00139 return (m_tValue1 == rPair.getFirstConst() && 00140 m_tValue2 == rPair.getSecondConst()); 00141 } 00142 00143 /***********************************************************************/ 00146 /***********************************************************************/ 00147 inline virtual bool MQUALIFIER equalsFirst(const T1& rInPar) const 00148 { 00149 return (m_tValue1 == rInPar); 00150 } 00151 00152 /***********************************************************************/ 00155 /***********************************************************************/ 00156 inline virtual bool MQUALIFIER equalsSecond(const T2& rInPar) const 00157 { 00158 return (m_tValue2 == rInPar); 00159 } 00160 00161 /***********************************************************************/ 00164 /***********************************************************************/ 00165 inline virtual T1& MQUALIFIER getFirst() 00166 { 00167 return m_tValue1; 00168 } 00169 00170 /***********************************************************************/ 00173 /***********************************************************************/ 00174 inline virtual const T1& MQUALIFIER getFirstConst() const 00175 { 00176 return m_tValue1; 00177 } 00178 00179 /***********************************************************************/ 00182 /***********************************************************************/ 00183 inline virtual T2& MQUALIFIER getSecond() 00184 { 00185 return m_tValue2; 00186 } 00187 00188 /***********************************************************************/ 00191 /***********************************************************************/ 00192 inline virtual const T2& MQUALIFIER getSecondConst() const 00193 { 00194 return m_tValue2; 00195 } 00196 00197 /***********************************************************************/ 00200 /***********************************************************************/ 00201 inline virtual void MQUALIFIER setFirst(const T1& rInPar) 00202 { 00203 m_tValue1 = rInPar; 00204 } 00205 00206 /***********************************************************************/ 00209 /***********************************************************************/ 00210 inline virtual void MQUALIFIER setSecond(const T2& rInPar) 00211 { 00212 m_tValue2 = rInPar; 00213 } 00214 00215 /***********************************************************************/ 00218 /***********************************************************************/ 00219 inline virtual void MQUALIFIER setPair(const T1& rInPar1, const T2& rInPar2) 00220 { 00221 m_tValue1 = rInPar1; 00222 m_tValue2 = rInPar2; 00223 } 00224 00225 /***********************************************************************/ 00228 /***********************************************************************/ 00229 inline bool operator==(const TPair<T1, T2>& rInPar) const 00230 { 00231 return this->equals(rInPar); 00232 } 00233 00234 /***********************************************************************/ 00237 /***********************************************************************/ 00238 inline bool operator==(const IPair<T1, T2>& rInPar) const 00239 { 00240 return this->equals(rInPar); 00241 } 00242 00243 /***********************************************************************/ 00246 /***********************************************************************/ 00247 inline bool operator!=(const TPair<T1, T2>& rInPar) const 00248 { 00249 return !this->equals(rInPar); 00250 } 00251 /***********************************************************************/ 00254 /***********************************************************************/ 00255 inline bool operator!=(const IPair<T1, T2>& rInPar) const 00256 { 00257 return !this->equals(rInPar); 00258 } 00259 00260 /***********************************************************************/ 00263 /***********************************************************************/ 00264 inline TPair& operator=(const TPair<T1, T2>& rInPar) 00265 { 00266 this->assign(rInPar); 00267 return *this; 00268 } 00269 00270 /***********************************************************************/ 00273 /***********************************************************************/ 00274 inline TPair& operator=(const IPair<T1, T2>& rInPar) 00275 { 00276 this->assign(rInPar); 00277 return *this; 00278 } 00279 00280 /***********************************************************************/ 00283 /***********************************************************************/ 00284 inline bool operator < (const TPair<T1, T2>& rInPar) const 00285 { 00286 return (m_tValue1 < rInPar.m_tValue1 || 00287 (m_tValue1 == rInPar.m_tValue1 && m_tValue2 < rInPar.m_tValue2)); 00288 } 00289 00290 private: 00292 T1 m_tValue1; 00294 T2 m_tValue2; 00295 }; 00296 00297 END_NAMESPACE_Zeus 00298 00299 #endif