Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Saf/Collection/Pair.h
Go to the documentation of this file.
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_PAIR_H
00029 #define SAF_COLLECTION_PAIR_H
00030 
00031 #include "../Algo/Swap.h"
00032 #include "../Type/Traits.h"
00033 
00034 namespace Saf
00035 {
00036     namespace Collection
00037     {
00042         template <class T1, class T2> 
00043         class Pair
00044         {
00045         public:
00047             typedef T1 FirstMemberType;
00049             typedef T2 SecondMemberType;
00050 
00051         public:
00053             T1 m_first;
00055             T2 m_second;
00056 
00057         public:
00059             Pair()
00060             {}
00061 
00066             explicit Pair(const T1& v1)
00067                 : m_first(v1)
00068             {}
00069 
00071             Pair(const T1& v1, const T2& v2)
00072                 : m_first(v1), m_second(v2)
00073             {}
00074 
00076             Pair(const Pair<T1,T2>& p)
00077                 : m_first(p.m_first), m_second(p.m_second)
00078             {}
00079 
00081             Pair<T1,T2>& operator=(const Pair<T1,T2>& p)
00082             {
00083                 if (this != &p)
00084                 {
00085                     m_first = p.m_first;
00086                     m_second = p.m_second;
00087                 }
00088                 return *this;
00089             }
00090 
00092             void Swap(Pair<T1,T2>& p)
00093             {
00094                 if (this != &p)
00095                 {
00096                     Algo::Swap(m_first, p.m_first);
00097                     Algo::Swap(m_second, p.m_second);
00098                 }
00099             }
00100         };
00101     }
00102 
00104     namespace Algo
00105     {
00106         // Swap specialization for pair container.
00107         template <class T1, class T2>
00108         struct SwapFunc< Collection::Pair<T1,T2> >
00109         {
00110             void operator()(Collection::Pair<T1,T2>& x, Collection::Pair<T1,T2>& y)
00111             {
00112                 x.Swap(y);
00113             }
00114         };
00115     }
00116 
00117     namespace Type
00118     {
00119         // Traits specialization for pair container
00120         template <class T1, class T2>
00121         class Traits< Collection::Pair<T1,T2> >
00122         {
00123         public:
00124             static bool IsPod()
00125             {
00126                 return Traits<T1>::IsPod() && Traits<T2>::IsPod();
00127             }
00128         };
00129     }
00131 }
00132 
00133 #endif