00001 /***************************************************************************** 00002 * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch) 00003 ***************************************************************************** 00004 * Project : Zeus Base Library 00005 * Module : Pair 00006 * Package : Zeus.ZeusBase.System 00007 * Author : Benjamin Hadorn 00008 * Date : 27.12.2011 00009 * System : Zeus-Framework 00010 ***************************************************************************** 00011 * Licence: * 00012 * This library is free software; you can redistribute it and/or modify * 00013 * it under the terms of the GNU Lesser General Public License as * 00014 * published by the Free Software Foundation; either version * 00015 * 2.1 of the License, or (at your option) any later version. * 00016 * * 00017 * This library is distributed in the hope that it will be useful, * 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00020 * GNU Lesser General Public License for more details. * 00021 * * 00022 * You should have received a copy of the GNU Lesser General Public * 00023 * License along with this library; if not, write to the Free Software * 00024 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA * 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 * Changes: 00029 * 27.12.2011 bha: created zeus 2.0 00030 *****************************************************************************/ 00031 00032 #ifndef PairHPP 00033 #define PairHPP 00034 00035 #include <zeusbase/System/Interfaces/IPair.hpp> 00036 #include <zeusbase/System/ZObject.h> 00037 00038 BEGIN_NAMESPACE_Zeus 00039 00040 /***************************************************************************/ 00044 /***************************************************************************/ 00045 template <class T1, class T2> class TPair 00046 : public TZObject, 00047 public IPair<T1, T2> 00048 { 00049 public: 00050 /************************************************************************/ 00053 /************************************************************************/ 00054 inline TPair() 00055 /* COMPILER PROBLEM*/ 00056 /*#ifdef A_COMPILER_TYPE 00057 : m_tValue1(getDefaultEmpty()), 00058 m_tValue2(getDefaultEmpty()) 00059 #else 00060 : m_tValue1(T()), 00061 m_tValue2(T()) 00062 #endif 00063 */ 00064 : m_tValue1(T1()), 00065 m_tValue2(T2()) 00066 { 00067 // DO NOT USE MEMSET. This causes memory leaks on complex objects 00068 //memset(&m_tEmpty, 0, sizeof(T)); 00069 } 00070 00071 /************************************************************************/ 00074 /************************************************************************/ 00075 inline TPair(const T1& rValue1, const T2& rValue2) 00076 : m_tValue1(rValue1), 00077 m_tValue2(rValue2) 00078 {} 00079 00080 /************************************************************************/ 00083 /************************************************************************/ 00084 inline TPair(const TPair<T1, T2>& rValue) 00085 : m_tValue1((T1&)rValue.getFirstConst()), 00086 m_tValue2((T2&)rValue.getSecondConst()) 00087 {} 00088 00089 /************************************************************************/ 00092 /************************************************************************/ 00093 inline TPair(const IPair<T1, T2>& rValue) 00094 : m_tValue1((T1&)rValue.getFirstConst()), 00095 m_tValue2((T2&)rValue.getSecondConst()) 00096 {} 00097 00098 /************************************************************************/ 00101 /************************************************************************/ 00102 inline virtual ~TPair() 00103 { 00104 } 00105 00106 /***********************************************************************/ 00109 /***********************************************************************/ 00110 inline virtual void MQUALIFIER assign(const IPair<T1, T2>& rPair) 00111 { 00112 m_tValue1 = rPair.getFirstConst(); 00113 m_tValue2 = rPair.getSecondConst(); 00114 } 00115 00116 /***********************************************************************/ 00119 /***********************************************************************/ 00120 inline virtual bool MQUALIFIER equals(const IPair<T1, T2>& rPair) const 00121 { 00122 return (m_tValue1 == rPair.getFirstConst() && 00123 m_tValue2 == rPair.getSecondConst()); 00124 } 00125 00126 /***********************************************************************/ 00129 /***********************************************************************/ 00130 inline virtual bool MQUALIFIER equalsFirst(const T1& rInPar) const 00131 { 00132 return (m_tValue1 == rInPar); 00133 } 00134 00135 /***********************************************************************/ 00138 /***********************************************************************/ 00139 inline virtual bool MQUALIFIER equalsSecond(const T2& rInPar) const 00140 { 00141 return (m_tValue2 == rInPar); 00142 } 00143 00144 /***********************************************************************/ 00147 /***********************************************************************/ 00148 inline virtual T1& MQUALIFIER getFirst() 00149 { 00150 return m_tValue1; 00151 } 00152 00153 /***********************************************************************/ 00156 /***********************************************************************/ 00157 inline virtual const T1& MQUALIFIER getFirstConst() const 00158 { 00159 return m_tValue1; 00160 } 00161 00162 /***********************************************************************/ 00165 /***********************************************************************/ 00166 inline virtual T2& MQUALIFIER getSecond() 00167 { 00168 return m_tValue2; 00169 } 00170 00171 /***********************************************************************/ 00174 /***********************************************************************/ 00175 inline virtual const T2& MQUALIFIER getSecondConst() const 00176 { 00177 return m_tValue2; 00178 } 00179 00180 /***********************************************************************/ 00183 /***********************************************************************/ 00184 inline virtual void MQUALIFIER setFirst(const T1& rInPar) 00185 { 00186 m_tValue1 = rInPar; 00187 } 00188 00189 /***********************************************************************/ 00192 /***********************************************************************/ 00193 inline virtual void MQUALIFIER setSecond(const T2& rInPar) 00194 { 00195 m_tValue2 = rInPar; 00196 } 00197 00198 /***********************************************************************/ 00201 /***********************************************************************/ 00202 inline virtual void MQUALIFIER setPair(const T1& rInPar1, const T2& rInPar2) 00203 { 00204 m_tValue1 = rInPar1; 00205 m_tValue2 = rInPar2; 00206 } 00207 00208 /***********************************************************************/ 00211 /***********************************************************************/ 00212 inline bool operator==(const TPair<T1, T2>& rInPar) const 00213 { 00214 return this->equals(rInPar); 00215 } 00216 00217 /***********************************************************************/ 00220 /***********************************************************************/ 00221 inline bool operator==(const IPair<T1, T2>& rInPar) const 00222 { 00223 return this->equals(rInPar); 00224 } 00225 00226 /***********************************************************************/ 00229 /***********************************************************************/ 00230 inline bool operator!=(const TPair<T1, T2>& rInPar) const 00231 { 00232 return !this->equals(rInPar); 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 TPair& operator=(const TPair<T1, T2>& rInPar) 00248 { 00249 this->assign(rInPar); 00250 return *this; 00251 } 00252 00253 /***********************************************************************/ 00256 /***********************************************************************/ 00257 inline TPair& operator=(const IPair<T1, T2>& rInPar) 00258 { 00259 this->assign(rInPar); 00260 return *this; 00261 } 00262 00263 /***********************************************************************/ 00266 /***********************************************************************/ 00267 inline bool operator < (const TPair<T1, T2>& rInPar) const 00268 { 00269 return (m_tValue1 < rInPar.m_tValue1 || 00270 (m_tValue1 == rInPar.m_tValue1 && m_tValue2 < rInPar.m_tValue2)); 00271 } 00272 00273 private: 00275 T1 m_tValue1; 00277 T2 m_tValue2; 00278 }; 00279 00280 END_NAMESPACE_Zeus 00281 00282 #endif