Simple Application Framework
1
|
00001 /* 00002 This file is part of Simple Application Framework (Saf) library. 00003 Copyright (C) 2010 - 2012 Ondrej Danek <ondrej.danek@gmail.com> 00004 00005 This library is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published 00007 by the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 Saf is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Simple Application Framework library. If not, 00017 see <http://www.gnu.org/licenses/>. 00018 */ 00019 00028 #ifndef SAF_COLLECTION_TRIPLET_H 00029 #define SAF_COLLECTION_TRIPLET_H 00030 00031 #include "Pair.h" 00032 00033 namespace Saf 00034 { 00035 namespace Collection 00036 { 00041 template <class T1, class T2, class T3> 00042 class Triplet 00043 : public Pair<T1,T2> 00044 { 00045 public: 00047 typedef T3 ThirdMemberType; 00048 00049 public: 00051 T3 m_third; 00052 00053 public: 00055 Triplet() 00056 {} 00057 00062 explicit Triplet(const T1& v1) 00063 : m_first(v1) 00064 {} 00065 00070 Triplet(const T1& v1, const T2& v2) 00071 : m_first(v1), m_second(v2) 00072 {} 00073 00075 Triplet(const T1& v1, const T2& v2, const T3& v3) 00076 : Pair<T1,T2>(v1, v2), m_third(v3) 00077 {} 00078 00080 Triplet(const Triplet<T1,T2,T3>& t) 00081 : Pair<T1,T2>(t), m_third(t.m_third) 00082 {} 00083 00085 Triplet<T1,T2,T3>& operator=(const Triplet<T1,T2,T3>& t) 00086 { 00087 if (this != &t) 00088 { 00089 Pair<T1,T2>::operator=(t); 00090 m_third = t.m_third; 00091 } 00092 return *this; 00093 } 00094 00096 void Swap(Triplet<T1,T2,T3>& t) 00097 { 00098 if (this != &t) 00099 { 00100 Pair<T1,T2>::Swap(t); 00101 Algo::Swap(m_third, t.m_third); 00102 } 00103 } 00104 }; 00105 } 00106 00108 namespace Algo 00109 { 00110 // Swap specialization for triplet container. 00111 template <class T1, class T2, class T3> 00112 struct SwapFunc< Collection::Triplet<T1,T2,T3> > 00113 { 00114 void operator()(Collection::Triplet<T1,T2,T3>& x, Collection::Triplet<T1,T2,T3>& y) 00115 { 00116 x.Swap(y); 00117 } 00118 }; 00119 } 00120 00121 namespace Type 00122 { 00123 // Traits specialization for triplet container 00124 template <class T1, class T2, class T3> 00125 class Traits< Collection::Triplet<T1,T2,T3> > 00126 { 00127 public: 00128 static bool IsPod() 00129 { 00130 return Traits<T1>::IsPod() && Traits<T2>::IsPod() && Traits<T3>::IsPod(); 00131 } 00132 }; 00133 } 00135 } 00136 00137 #endif