1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
|
// Copyright (c) 2016 CNRS and LIRIS' Establishments (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/Generalized_map/include/CGAL/Generalized_map_iterators_base.h $
// $Id: include/CGAL/Generalized_map_iterators_base.h b26b07a1242 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s) : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
//
#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 <CGAL/Combinatorial_map_iterators_base.h>
// Other includes
#include <CGAL/Compact_container.h>
#include <queue>
#include <type_traits>
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<GMap,Ite,Ai> 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 combinatorial 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<Map,Ite,Ai> 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 <typename Map_,typename Ite,int Ai,
typename Ite_has_stack=typename Ite::Use_mark>
class GMap_extend_iterator: public Ite
{
public:
typedef GMap_extend_iterator<Map_,Ite,Ai, Ite_has_stack> Self;
typedef Ite Base;
typedef typename Base::Dart_descriptor Dart_descriptor;
typedef typename Base::Map Map;
typedef typename Base::size_type size_type;
typedef Tag_true Use_mark;
static_assert(Ai<=Map::dimension &&
std::is_same<Ite_has_stack,Tag_false>::value);
public:
/// Main constructor.
GMap_extend_iterator(Map& amap, Dart_descriptor adart, size_type amark):
Base(amap, adart),
mmark_number(amark),
minitial_dart(adart)
{
if ( adart!=amap.null_descriptor )
{
this->mmap->mark(adart, mmark_number);
if (!this->mmap->template is_free<Ai>(adart))
{
mto_treat.push(this->mmap->template alpha<Ai>(adart));
}
}
}
/// Rewind of the iterator to its beginning.
void rewind()
{
CGAL_assertion(mmark_number != Map::INVALID_MARK);
Base::operator= ( Base(*this->mmap,minitial_dart) );
mto_treat = std::queue<Dart_descriptor>();
this->mmap->mark(minitial_dart, mmark_number);
if (!this->mmap->template is_free<Ai>(minitial_dart))
{
mto_treat.push(this->mmap->template alpha<Ai>(minitial_dart));
}
}
/// Prefix ++ operator.
Self& operator++()
{
CGAL_assertion(mmark_number != Map::INVALID_MARK);
CGAL_assertion(this->cont());
do
{
Base::operator++();
}
while ( this->cont() &&
this->mmap->is_marked(*this, mmark_number) );
if ( !this->cont() )
{
while ( !mto_treat.empty() &&
this->mmap->is_marked(mto_treat.front(), mmark_number))
{
mto_treat.pop();
}
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) );
this->mmap->mark((*this), mmark_number);
if (!this->mmap->template is_free<Ai>(*this) &&
!this->mmap->is_marked(this->mmap->template alpha<Ai>(*this), mmark_number) )
{
mto_treat.push(this->mmap->template alpha<Ai>(*this));
}
}
}
else
{
this->mmap->mark((*this), mmark_number);
if (!this->mmap->template is_free<Ai>(*this) &&
!this->mmap->is_marked(this->mmap->alpha(*this, Ai), mmark_number) )
{
mto_treat.push(this->mmap->template alpha<Ai>(*this));
}
}
return *this;
}
/// Postfix ++ operator.
Self operator++(int)
{ Self res=*this; operator ++(); return res; }
protected:
/// Queue of darts to process.
std::queue<Dart_descriptor> mto_treat;
/// Index of the used mark.
size_type mmark_number;
/// Initial dart
Dart_descriptor minitial_dart;
};
//****************************************************************************
/* Class GMap_extend_iterator<Map,Ite,Ai> which extend a given iterator by
* adding Ai and by using a stack and a mark.
* Specialization when Ite has already a stack.
*/
template <typename Map_,typename Ite,int Ai>
class GMap_extend_iterator<Map_,Ite,Ai,Tag_true>: public Ite
{
public:
typedef GMap_extend_iterator<Map_,Ite,Ai,Tag_true> Self;
typedef Ite Base;
typedef typename Base::Dart_descriptor Dart_descriptor;
typedef typename Base::Map Map;
typedef Tag_true Use_mark;
typedef typename Map::size_type size_type;
/// Main constructor.
GMap_extend_iterator(Map& amap, Dart_descriptor adart, size_type amark):
Base(amap, adart, amark)
{
if (adart!=amap.null_descriptor)
{
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));
}
}
}
/// Rewind of the iterator to its beginning.
void rewind()
{
CGAL_assertion(this->mmark_number != Map::INVALID_MARK);
Base::rewind();
if ( !this->mmap->is_free(this->minitial_dart, Ai) )
{
this->mto_treat.push(this->mmap->alpha(this->minitial_dart, Ai));
}
}
/// 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));
}
}
return *this;
}
/// Postfix ++ operator.
Self operator++(int)
{ Self res=*this; operator ++(); return res; }
};
//****************************************************************************
//****************************************************************************
} // namespace CGAL
//******************************************************************************
#endif // CGAL_GENERALIZED_MAP_ITERATORS_BASE_HH
//******************************************************************************
|