Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Saf/Collection/TreeSet.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_TREESET_H
00029 #define SAF_COLLECTION_TREESET_H
00030 
00031 #include "../Algo/Struct/RedBlackTree.h"
00032 #include "../Algo/Predicate.h"
00033 #include "../Algo/Basic.h"
00034 
00035 namespace Saf
00036 {
00037     namespace Collection
00038     {
00053         template <class ValType, class CompType = Algo::Predicate::Less<ValType> > 
00054         class TreeSet
00055             : public Algo::Struct::RedBlackTree<ValType,ValType,Algo::Identity<ValType>,CompType>
00056         {
00057         protected:            
00058             typedef Algo::Struct::RedBlackTree<ValType,ValType,Algo::Identity<ValType>,CompType> BaseType;
00059             typedef TreeSet<ValType,CompType> MyType;
00060 
00061         public:
00062             typedef typename BaseType::Iterator Iterator;
00063             typedef typename BaseType::ConstIterator ConstIterator;
00064 
00065         public:
00067             TreeSet()
00068                 : BaseType()
00069             {}
00070 
00072             TreeSet(const MyType& m) 
00073                 : BaseType(m)
00074             {}
00075 
00077             MyType& operator=(const MyType& m)
00078             {
00079                 BaseType::operator=(m);
00080                 return *this;
00081             }
00082 
00088             MyType& Swap(MyType& m)
00089             {
00090                 BaseType::Swap(m);
00091                 return *this;
00092             }
00093         };
00094     }
00095 
00097     namespace Algo
00098     {
00099         // Swap specialization for set container.
00100         template <class ValType, class CompType>
00101         struct SwapFunc< Collection::TreeSet<ValType,CompType> >
00102         {
00103             void operator()(Collection::TreeSet<ValType,CompType>& x, 
00104                 Collection::TreeSet<ValType,CompType>& y)
00105             {
00106                 x.Swap(y);
00107             }
00108         };
00109     }
00111 }
00112 
00113 #endif