BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/Flattening_iterator.h
Go to the documentation of this file.
00001 // Copyright (c) 2001-2007 Max-Planck-Institute Saarbruecken (Germany).
00002 // All rights reserved.
00003 //
00004 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License as
00006 // published by the Free Software Foundation; version 2.1 of the License.
00007 // See the file LICENSE.LGPL distributed with CGAL.
00008 //
00009 // Licensees holding a valid commercial license may use this file in
00010 // accordance with the commercial license agreement provided with the software.
00011 //
00012 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014 //
00015 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/STL_Extension/include/CGAL/Flattening_iterator.h $
00016 // $Id: Flattening_iterator.h 37883 2007-04-03 16:07:32Z ameyer $
00017 //
00018 // Author(s)     : Arno Eigenwillig <arno@mpi-inf.mpg.de>
00019 
00020 #ifndef CGAL_FLATTENING_ITERATOR_H
00021 #define CGAL_FLATTENING_ITERATOR_H 1
00022 
00023 #include <CGAL/basic.h>
00024 #include <CGAL/Nested_iterator.h>
00025 
00026 #include <iterator>
00027 #include <functional>
00028 
00029 // LiS2CGAL check whether Nested_iterator in CGAL works in STL_extensions
00030 
00031 CGAL_BEGIN_NAMESPACE
00032 
00058 template <int level_, class InputIterator>
00059 class Recursive_const_flattening;
00060 
00061 template <class InputIterator>
00062 class Recursive_const_flattening<0, InputIterator> {
00063 public:
00064     typedef Recursive_const_flattening Self;
00065     static const int level = 0;
00066     typedef InputIterator  Input_iterator;
00067 
00068     typedef Input_iterator Recursive_flattening_iterator;
00069 
00070     struct Flatten {
00071         typedef Recursive_flattening_iterator result_type;
00072         typedef Input_iterator argument_type;
00073 
00074         Recursive_flattening_iterator
00075         operator () (Input_iterator /*end*/, Input_iterator it) {
00076             return it;
00077         }
00078     };
00079 };
00080 
00081 template <class InputIterator>
00082 class Recursive_const_flattening<1, InputIterator> {
00083 public:
00084     typedef Recursive_const_flattening Self;
00085     static const int level = 1;
00086     typedef InputIterator Input_iterator;
00087 
00088 private:
00089     struct Nested_iterator_traits
00090     {
00091       typedef Input_iterator Base_iterator;
00092       typedef typename std::iterator_traits<Input_iterator>::value_type::const_iterator
00093               Iterator;
00094 
00095       Iterator begin(Input_iterator it) const { return it->begin(); }
00096       Iterator end  (Input_iterator it) const { return it->end();   }
00097     };
00098 
00099 public:
00100 
00101     typedef CGAL::Nested_iterator< Input_iterator, Nested_iterator_traits >
00102             Recursive_flattening_iterator;
00103 
00104     struct Flatten {
00105         typedef Recursive_flattening_iterator result_type;
00106         typedef Input_iterator                argument_type;
00107 
00108         Recursive_flattening_iterator
00109         operator () (Input_iterator end, Input_iterator it) {
00110             return Recursive_flattening_iterator(end,it);
00111         }
00112     };
00113 };
00114 
00140 template< int level_, class InputIterator >
00141 class Recursive_const_flattening {
00142 public:
00144     typedef Recursive_const_flattening Self;
00146     static const int level = level_;
00148     typedef InputIterator Input_iterator;
00149 
00150     typedef Recursive_const_flattening<
00151             level-1,
00152             typename std::iterator_traits<Input_iterator>::value_type::const_iterator
00153         > Nested_self;
00154 
00155 private:
00156     struct Nested_iterator_traits
00157     {
00158       typedef Input_iterator
00159               Base_iterator;
00160       typedef typename Nested_self::Recursive_flattening_iterator
00161               Iterator;
00162 
00163       Iterator begin(Input_iterator it) const { return typename Nested_self::Flatten()(it->end(),it->begin()); }
00164       Iterator end  (Input_iterator it) const { return typename Nested_self::Flatten()(it->end(),it->end());   }
00165     };
00166 
00167 public:
00168     typedef CGAL::Nested_iterator< Input_iterator, Nested_iterator_traits >
00169             Recursive_flattening_iterator;
00170 
00172     struct Flatten {
00174         typedef Recursive_flattening_iterator result_type;
00176         typedef Input_iterator                argument_type;
00177 
00179         Recursive_flattening_iterator
00180         operator () (Input_iterator end,Input_iterator it) {
00181             return Recursive_flattening_iterator(end,it);
00182         }
00183     };
00184 };
00185 
00186 #ifdef DOXYGEN_RUNNING
00187 
00193 template <int level_, class InputIterator>
00194 class Recursive_flattening { };
00195 #endif // DOXYGEN_RUNNING
00196 
00197 /*
00198  * Part 2: Helper functions
00199  */
00200 
00211 template <int level, class InputIterator> inline
00212 typename Recursive_const_flattening<level, InputIterator>
00213     ::Recursive_flattening_iterator
00214 recursive_const_flattener(InputIterator end,InputIterator it) {
00215     return typename Recursive_const_flattening<level, InputIterator>::Flatten()(end,it);
00216 }
00217 
00233 template <class InputIterator> inline
00234 typename Recursive_const_flattening<1, InputIterator>
00235     ::Recursive_flattening_iterator
00236 const_flattener(InputIterator end,InputIterator it) {
00237     return typename Recursive_const_flattening<1, InputIterator>::Flatten()(end,it);
00238 }
00239 
00240 #ifdef DOXYGEN_RUNNING
00241 
00247 template <int level, class InputIterator> inline
00248 typename Recursive_flattening<level, InputIterator>
00249     ::Recursive_flattening_iterator
00250 recursive_flattener(InputIterator it);
00251 
00258 template <class InputIterator> inline
00259 typename Recursive_flattening<1, InputIterator>
00260     ::Recursive_flattening_iterator
00261 flattener(InputIterator it);
00262 #endif // DOXYGEN_RUNNING
00263 
00264 
00265 CGAL_END_NAMESPACE
00266 
00267 #endif // LiS_FLATTENING_ITERATOR_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines