// Copyright (c) 2014 CNRS and LIRIS' Establishments (France). // All rights reserved. // // This file is part of CGAL (www.cgal.org); you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 3 of the License, // or (at your option) any later version. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ // // Author(s) : Guillaume Damiand // #ifndef CGAL_GENERALIZED_MAP_ITERATORS_BASE_HH #define CGAL_GENERALIZED_MAP_ITERATORS_BASE_HH 1 // to get OperationState type, some OP, and CMap_dart_iterator #include // Other includes #include #include #include #include namespace CGAL { /** @file generalized_map_iterators_base.h * Basic classes that serve as tools for definition of iterators. * There is 1 class: * - GMap_extend_iterator to extend the given iterator by * adding the involution Ai. */ //**************************************************************************** /// Enum of all the possible operations used by the ++ operator. /// Extension of the enum for generalized maps. enum { OP_ALPHAI=OP_END+1, ///< Previous op was the first alpha. OP_ALPHAJ, ///< Previous op was the second alpha. OP_ALPHAK, ///< Previous op was the third alpha. OP_ALPHAIJ, ///< Previous op was the composition of two alpha. OP_ALPHAJI, ///< Previous op was the composition of two alpha. }; //**************************************************************************** /* Class GMap_extend_iterator which extend a given iterator by * adding Ai and by using a stack and a mark. * General case when Ite does not have already a stack. */ template class GMap_extend_iterator: public Ite { public: typedef GMap_extend_iterator Self; typedef Ite Base; typedef typename Base::Dart_handle Dart_handle; typedef typename Base::Map Map; typedef Tag_true Use_mark; CGAL_static_assertion( (Ai<=Map::dimension && boost::is_same::value) ); public: /// Main constructor. GMap_extend_iterator(Map& amap, Dart_handle adart, int amark): Base(amap, adart), mmark_number(amark), minitial_dart(adart) { if ( adart!=amap.null_handle ) { this->mmap->mark(adart, mmark_number); if (!this->mmap->template is_free(adart)) { mto_treat.push(this->mmap->template alpha(adart)); this->mmap->mark(this->mmap->template alpha(adart), mmark_number); } } } /// Rewind of the iterator to its beginning. void rewind() { CGAL_assertion(mmark_number != -1); Base::operator= ( Base(*this->mmap,minitial_dart) ); mto_treat = std::queue(); this->mmap->mark(minitial_dart, mmark_number); if (!this->mmap->template is_free(minitial_dart)) { mto_treat.push(this->mmap->template alpha(minitial_dart)); this->mmap->mark(this->mmap->template alpha(minitial_dart), mmark_number); } } /// Prefix ++ operator. Self& operator++() { CGAL_assertion(mmark_number != -1); CGAL_assertion(this->cont()); do { Base::operator++(); } while ( this->cont() && this->mmap->is_marked(*this, mmark_number) ); if ( !this->cont() ) { if ( !mto_treat.empty() ) { Base::operator= ( Base(*this->mmap,mto_treat.front()) ); mto_treat.pop(); this->mprev_op = OP_POP; CGAL_assertion( this->mmap->is_marked((*this), mmark_number) ); if (!this->mmap->is_free(*this, Ai) && !this->mmap->is_marked(this->mmap->alpha(*this, Ai), mmark_number) ) { mto_treat.push(this->mmap->alpha(*this, Ai)); this->mmap->mark(this->mmap->alpha(*this, Ai), mmark_number); } } } else { this->mmap->mark((*this), mmark_number); if (!this->mmap->is_free(*this, Ai) && !this->mmap->is_marked(this->mmap->alpha(*this, Ai), mmark_number) ) { mto_treat.push(this->mmap->alpha(*this, Ai)); this->mmap->mark(this->mmap->alpha(*this, Ai), mmark_number); } } return *this; } /// Postfix ++ operator. Self operator++(int) { Self res=*this; operator ++(); return res; } protected: /// Queue of darts to process. std::queue mto_treat; /// Index of the used mark. int mmark_number; /// Initial dart Dart_handle minitial_dart; }; //**************************************************************************** /* Class GMap_extend_iterator which extend a given iterator by * adding Ai and by using a stack and a mark. * Specialization when Ite has already a stack. */ template class GMap_extend_iterator: public Ite { public: typedef GMap_extend_iterator Self; typedef Ite Base; typedef typename Base::Dart_handle Dart_handle; typedef typename Base::Map Map; typedef Tag_true Use_mark; /// Main constructor. GMap_extend_iterator(Map& amap, Dart_handle adart, int amark): Base(amap, adart, amark) { if (adart!=amap.null_handle) { if (!this->mmap->is_free(adart, Ai) && !this->mmap->is_marked(this->mmap->alpha(amap, Ai), this->mmark_number)) { this->mto_treat.push(adart->alpha(Ai)); this->mmap->mark(this->mmap->alpha(this->minitial_dart, Ai), this->mmark_number); } } } /// Rewind of the iterator to its beginning. void rewind() { CGAL_assertion(this->mmark_number != -1); Base::rewind(); if ( !this->mmap->is_free(this->minitial_dart, Ai) ) { this->mto_treat.push(this->mmap->alpha(this->minitial_dart, Ai)); this->mmap->mark(this->mmap->alpha(this->minitial_dart, Ai), this->mmark_number); } } /// Prefix ++ operator. Self& operator++() { Base::operator++(); if ( this->cont() ) { CGAL_assertion( this->mmap->is_marked(*this, this->mmark_number) ); if (!this->mmap->is_free(*this, Ai) && !this->mmap->is_marked(this->mmap->alpha(*this, Ai), this->mmark_number)) { this->mto_treat.push(this->mmap->alpha(*this, Ai)); this->mmap->mark(this->mmap->alpha(*this, Ai), this->mmark_number); } } return *this; } /// Postfix ++ operator. Self operator++(int) { Self res=*this; operator ++(); return res; } }; //**************************************************************************** //**************************************************************************** } // namespace CGAL //****************************************************************************** #endif // CGAL_GENERALIZED_MAP_ITERATORS_BASE_HH //******************************************************************************