diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 401e504427e..9daf76d3acf 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -2597,7 +2597,7 @@ namespace CGAL { if (is_marked(d, amark)) { for ( i = 0; i <= dimension; ++i) - { if (!d->is_free(i)) unlink_beta(d, i); } + { if (!is_free(d, i)) unlink_beta(d, i); } erase_dart(d); ++res; } } diff --git a/Generalized_map/include/CGAL/GMap_dart.h b/Generalized_map/include/CGAL/GMap_dart.h index 96f080c8edb..3d052adea16 100644 --- a/Generalized_map/include/CGAL/GMap_dart.h +++ b/Generalized_map/include/CGAL/GMap_dart.h @@ -57,7 +57,7 @@ struct GMap_dart template < unsigned int, class, class > friend class Generalized_map_storage_2; - template + template friend class Compact_container; template @@ -137,28 +137,28 @@ public: * @param amark the mark number. * @return the value for this number. */ - bool get_mark(int amark) const + bool get_mark(size_type amark) const { - CGAL_assertion(amark>=0 && (size_type)amark=0 && amark=0 && (size_type)amark=0 && amark=0 && (size_type)amark=0 && amark {}; + class Exception_no_more_available_mark {}; + public: /** Default Generalized_map constructor. * The map is empty. @@ -160,12 +164,14 @@ namespace CGAL { for ( size_type i = 0; i < NB_MARKS; ++i) { - this->mfree_marks_stack[i] = (int)i; + this->mfree_marks_stack[i] = i; this->mindex_marks[i] = i; this->mnb_marked_darts[i] = 0; this->mnb_times_reserved_marks[i] = 0; } + this->automatic_attributes_management = true; + CGAL_assertion(number_of_darts()==0); } @@ -274,7 +280,7 @@ namespace CGAL { // "Copy constructor" from a map having different type. template Generalized_map_base(const CMap2& amap, Converters& converters, - const Pointconverter& pointconverter) + const Pointconverter& pointconverter) { copy (amap, converters, pointconverter); } @@ -325,7 +331,7 @@ namespace CGAL { void clear() { mdarts.clear(); - for ( unsigned int i = 0; i < NB_MARKS; ++i) + for ( size_type i = 0; i < NB_MARKS; ++i) this->mnb_marked_darts[i] = 0; internal::Clear_all::run(mattribute_containers); @@ -338,6 +344,18 @@ namespace CGAL { bool is_empty() const { return mdarts.empty(); } + friend std::ostream& operator<< (std::ostream& os, const Self& amap) + { + save_generalized_map(amap, os); + return os; + } + + friend std::ifstream& operator>> (std::ifstream& is, Self& amap) + { + load_generalized_map(is, amap); + return is; + } + /** Create a new dart and add it to the map. * The marks of the darts are initialised with mmask_marks, i.e. the dart * is unmarked for all the marks. @@ -442,7 +460,7 @@ namespace CGAL { void erase_dart(Dart_handle adart) { // 1) We update the number of marked darts. - for ( unsigned int i = 0; i < mnb_used_marks; ++i) + for ( size_type i = 0; i < mnb_used_marks; ++i) { if (is_marked(adart, mused_marks_stack[i])) --mnb_marked_darts[mused_marks_stack[i]]; @@ -456,6 +474,10 @@ namespace CGAL { mdarts.erase(adart); } + /// @return true if dh points to a used dart (i.e. valid). + bool is_dart_used(Dart_const_handle dh) const + { return mdarts.is_used(dh); } + /// @return a Dart_range (range through all the darts of the map). Dart_range& darts() { return mdarts;} Dart_const_range& darts() const { return mdarts; } @@ -506,6 +528,16 @@ namespace CGAL { if (!is_free(dh, 0)) return alpha(dh, 0); return null_handle; } + Dart_handle other_extremity(Dart_handle dh) + { + if (!is_free(dh, 0)) return alpha(dh, 0); + return null_handle; + } + Dart_const_handle other_extremity(Dart_const_handle dh) const + { + if (!is_free(dh, 0)) return alpha(dh, 0); + return null_handle; + } // Set the handle on the i th attribute template @@ -710,27 +742,27 @@ namespace CGAL { /** Test if a given mark is reserved. * @return true iff the mark is reserved (ie in used). */ - bool is_reserved(int amark) const + bool is_reserved(size_type amark) const { - CGAL_assertion(amark>=0 && (size_type)amark unsigned int close() { - CGAL_assertion( 0<=i && i<=dimension ); + CGAL_assertion( i<=dimension ); unsigned int res = 0; Dart_handle d, d2; @@ -997,9 +1030,9 @@ namespace CGAL { { bool valid = true; unsigned int i = 0, j = 0; - std::vector marks(dimension+1); + std::vector marks(dimension+1); for ( i=0; i<=dimension; ++i) - marks[i] = -1; + marks[i] = INVALID_MARK; Helper::template Foreach_enabled_attributes >:: @@ -1011,7 +1044,7 @@ namespace CGAL { if ( !valid ) { // We continue the traversal to mark all the darts. for ( i=0; i<=dimension; ++i) - if (marks[i]!=-1) mark(it,marks[i]); + if (marks[i]!=INVALID_MARK) mark(it,marks[i]); } else { @@ -1044,7 +1077,7 @@ namespace CGAL { } } for ( i=0; i<=dimension; ++i) - if ( marks[i]!=-1 ) + if ( marks[i]!=INVALID_MARK ) { CGAL_assertion( is_whole_map_marked(marks[i]) ); free_mark(marks[i]); @@ -1053,6 +1086,33 @@ namespace CGAL { return valid; } + /// correct invalid attributes in the gmap + void correct_invalid_attributes() + { + std::vector marks(dimension+1); + for ( unsigned int i=0; i<=dimension; ++i) + marks[i] = INVALID_MARK; + + Helper::template + Foreach_enabled_attributes >:: + run(this,&marks); + + for ( typename Dart_range::iterator it(darts().begin()), + itend(darts().end()); it!=itend; ++it) + { + Helper::template Foreach_enabled_attributes + >:: + run(this,it,&marks); + } + + for ( unsigned int i=0; i<=dimension; ++i) + if ( marks[i]!=INVALID_MARK ) + { + CGAL_assertion( is_whole_map_marked(marks[i]) ); + free_mark(marks[i]); + } + } + /// @return the number of darts. size_type number_of_darts() const { return mdarts.size(); } @@ -1103,7 +1163,7 @@ namespace CGAL { CGAL_static_assertion( (boost::is_same::value) ); unsigned int nb = 0; - int amark = get_new_mark(); + size_type amark = get_new_mark(); for ( typename Dart_range::const_iterator it1(darts().begin()), itend(darts().end()); it1!=itend; ++it1) { @@ -1289,6 +1349,16 @@ namespace CGAL { (mattribute_containers).erase(h); } + /// @return true if ah points to a used i-attribute (i.e. valid). + template + bool is_attribute_used(typename Attribute_const_handle< i >::type ah) const + { + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "is_attribute_used but i-attributes are disabled"); + return CGAL::cpp11::get::value> + (mattribute_containers).is_used(ah); + } + /// @return the number of attributes. template size_type number_of_attributes() const @@ -1456,6 +1526,7 @@ namespace CGAL { * @param adart1 a first dart. * @param adart2 a second dart. * @param update_attributes a boolean to update the enabled attributes. + * (deprecated, now we use are_attributes_automatically_managed()) */ template void link_alpha(Dart_handle adart1, Dart_handle adart2, @@ -1538,8 +1609,7 @@ namespace CGAL { CGAL_assertion( i<=dimension ); CGAL_assertion( (is_sewable(adart1,adart2)) ); - int amark=get_new_mark(); - CGAL_assertion( amark!=-1 ); + size_type amark=get_new_mark(); CGAL::GMap_dart_iterator_basic_of_involution I1(*this, adart1, amark); @@ -1573,6 +1643,7 @@ namespace CGAL { * @param adart1 the first dart. * @param adart2 the second dart. * @param update_attributes a boolean to update the enabled attributes + * (deprecated, now we use are_attributes_automatically_managed()) * @pre is_sewable(adart1, adart2). */ template @@ -1636,6 +1707,7 @@ namespace CGAL { * are updated only if update_attributes==true. * @param adart first dart. * @param update_attributes a boolean to update the enabled attributes + * (deprecated, now we use are_attributes_automatically_managed()) * @pre !adart->is_free(i). */ template @@ -1654,20 +1726,20 @@ namespace CGAL { count_marked_cells(int amark, const std::vector& acells) const { std::vector res(dimension+2); - std::vector marks(dimension+2); + std::vector marks(dimension+2); // Initialization of the result for ( unsigned int i=0; i tounmark; + std::vector tounmark; for ( unsigned int i=0; i& acells) const { std::vector res; - int m = get_new_mark(); + size_type m = get_new_mark(); negate_mark(m); // We mark all the cells. res = count_marked_cells(m, acells); @@ -1770,10 +1842,10 @@ namespace CGAL { * @param amark the mark. * @return the mask associated to mark amark. */ - bool get_mask_mark(int amark) const + bool get_mask_mark(size_type amark) const { - CGAL_assertion(amark>=0 && (size_type)amark=0 && amarkis_free(i)) unlink_alpha(d, i); } + { if (!is_free(d, i)) unlink_beta(d, i); } erase_dart(d); ++res; } } @@ -1815,7 +1887,7 @@ namespace CGAL { , CGAL::GMap_dart_const_iterator_basic_of_orbit > Base; - Dart_of_orbit_basic_range(Self &amap, Dart_handle adart, int amark=-1): + Dart_of_orbit_basic_range(Self &amap, Dart_handle adart, size_type amark=INVALID_MARK): Base(amap, adart, amark) {} }; @@ -1830,7 +1902,7 @@ namespace CGAL { Base; Dart_of_orbit_basic_const_range(const Self &amap, Dart_const_handle - adart, int amark=-1): + adart, size_type amark=INVALID_MARK): Base(amap, adart, amark) {} }; @@ -1874,12 +1946,12 @@ namespace CGAL { //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit_basic(Dart_handle adart, - int amark=-1) + size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range - darts_of_orbit_basic(Dart_const_handle adart, int amark=-1) const + darts_of_orbit_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range(*this,adart,amark); } //************************************************************************** #else @@ -1900,7 +1972,7 @@ namespace CGAL { B6,B7,B8,B9> > Base; Dart_of_orbit_basic_range(Self &amap, Dart_handle adart, - int /*amark*/=-1): + size_type /*amark*/=INVALID_MARK): Base(amap, adart) {} }; @@ -1918,7 +1990,7 @@ namespace CGAL { > Base; Dart_of_orbit_basic_const_range(const Self &amap, - Dart_const_handle adart, int amark=-1): + Dart_const_handle adart, size_type amark=INVALID_MARK): Base(amap, adart, amark) {} }; @@ -2064,104 +2136,104 @@ namespace CGAL { //-------------------------------------------------------------------------- // Basic versions Dart_of_orbit_basic_range<> darts_of_orbit_basic(Dart_handle adart, - int amark=-1) + size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range<>(*this,adart,amark); } //-------------------------------------------------------------------------- Dart_of_orbit_basic_const_range<> darts_of_orbit_basic - (Dart_const_handle adart,int amark=-1) const + (Dart_const_handle adart,size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range<>(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit_basic(Dart_handle adart, - int amark=-1) + size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range darts_of_orbit_basic - (Dart_const_handle adart, int amark=-1) const + (Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit_basic(Dart_handle adart, - int amark=-1) + size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range darts_of_orbit_basic - (Dart_const_handle adart, int amark=-1) const + (Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit_basic(Dart_handle adart, - int amark=-1) + size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range darts_of_orbit_basic - (Dart_const_handle adart, int amark=-1) const + (Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit_basic - (Dart_handle adart, int amark=-1) + (Dart_handle adart, size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range - darts_of_orbit_basic(Dart_const_handle adart, int amark=-1) const + darts_of_orbit_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit_basic - (Dart_handle adart, int amark=-1) + (Dart_handle adart, size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range - darts_of_orbit_basic(Dart_const_handle adart, int amark=-1) const + darts_of_orbit_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range (*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit_basic - (Dart_handle adart, int amark=-1) + (Dart_handle adart, size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range - darts_of_orbit_basic(Dart_const_handle adart, int amark=-1) const + darts_of_orbit_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range (*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit_basic - (Dart_handle adart, int amark=-1) + (Dart_handle adart, size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range (*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range - darts_of_orbit_basic(Dart_const_handle adart, int amark=-1) const + darts_of_orbit_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range (*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_range darts_of_orbit - (Dart_handle adart, int amark=-1) + (Dart_handle adart, size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range (*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_orbit_basic_const_range - darts_of_orbit_basic(Dart_const_handle adart, int amark=-1) const + darts_of_orbit_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range (*this,adart,amark); } //-------------------------------------------------------------------------- @@ -2169,7 +2241,7 @@ namespace CGAL { unsigned int B5,unsigned int B6,unsigned int B7,unsigned int B8, unsigned int B9> Dart_of_orbit_basic_range - darts_of_orbit_basic(Dart_handle adart, int amark=-1) + darts_of_orbit_basic(Dart_handle adart, size_type amark=INVALID_MARK) { return Dart_of_orbit_basic_range (*this,adart,amark); } //-------------------------------------------------------------------------- @@ -2177,7 +2249,7 @@ namespace CGAL { unsigned int B5,unsigned int B6,unsigned int B7,unsigned int B8, unsigned int B9> Dart_of_orbit_basic_const_range - darts_of_orbit_basic(Dart_const_handle adart, int amark=-1) const + darts_of_orbit_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_orbit_basic_const_range (*this,adart,amark); } //************************************************************************** @@ -2193,7 +2265,7 @@ namespace CGAL { , CGAL::GMap_dart_const_iterator_basic_of_cell > Base; - Dart_of_cell_basic_range(Self &amap, Dart_handle adart, int amark=-1) : + Dart_of_cell_basic_range(Self &amap, Dart_handle adart, size_type amark=INVALID_MARK) : Base(amap, adart, amark) {} }; @@ -2207,7 +2279,7 @@ namespace CGAL { > Base; Dart_of_cell_basic_const_range(const Self &amap, Dart_const_handle adart, - int amark=-1) : + size_type amark=INVALID_MARK) : Base(amap, adart, amark) {} }; @@ -2243,22 +2315,22 @@ namespace CGAL { /// @return a range on all the darts of the given i-cell template Dart_of_cell_basic_range darts_of_cell_basic(Dart_handle adart, - int amark=-1) + size_type amark=INVALID_MARK) { return Dart_of_cell_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_cell_basic_const_range darts_of_cell_basic - (Dart_const_handle adart, int amark=-1) const + (Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_cell_basic_const_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_cell_basic_range - darts_of_cell_basic(Dart_handle adart, int amark=-1) + darts_of_cell_basic(Dart_handle adart, size_type amark=INVALID_MARK) { return darts_of_cell_basic(adart,amark); } //-------------------------------------------------------------------------- template Dart_of_cell_basic_const_range - darts_of_cell_basic(Dart_const_handle adart, int amark=-1) const + darts_of_cell_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return darts_of_cell_basic(adart,amark); } //-------------------------------------------------------------------------- template @@ -2289,7 +2361,7 @@ namespace CGAL { CGAL::GMap_dart_const_iterator_basic_of_involution > Base; Dart_of_involution_basic_range(Self &amap, Dart_handle adart, - int amark=-1): + size_type amark=INVALID_MARK): Base(amap, adart, amark) {} }; @@ -2305,30 +2377,30 @@ namespace CGAL { Dart_of_involution_basic_const_range(const Self &amap, Dart_const_handle adart, - int amark=-1) : + size_type amark=INVALID_MARK) : Base(amap, adart, amark) {} }; //************************************************************************** template Dart_of_involution_basic_range - darts_of_involution_basic(Dart_handle adart, int amark=-1) + darts_of_involution_basic(Dart_handle adart, size_type amark=INVALID_MARK) { return Dart_of_involution_basic_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_involution_basic_const_range - darts_of_involution_basic(Dart_const_handle adart, int amark=-1) const + darts_of_involution_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_involution_basic_const_range(*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_involution_basic_range - darts_of_involution_basic(Dart_handle adart, int amark=-1) + darts_of_involution_basic(Dart_handle adart, size_type amark=INVALID_MARK) { return Dart_of_involution_basic_range (*this,adart,amark); } //-------------------------------------------------------------------------- template Dart_of_involution_basic_const_range - darts_of_involution_basic(Dart_const_handle adart, int amark=-1) const + darts_of_involution_basic(Dart_const_handle adart, size_type amark=INVALID_MARK) const { return Dart_of_involution_basic_const_range (*this,adart,amark); } //************************************************************************** @@ -2391,7 +2463,7 @@ namespace CGAL { iterator end() { return iterator(mmap,mmap.null_handle); } const_iterator begin() const { return const_iterator(mmap); } const_iterator end() const { return const_iterator(mmap,mmap.null_handle); } - size_type size() + size_type size() const { return mmap.number_of_darts(); } bool empty() const { return mmap.is_empty(); } @@ -2463,10 +2535,10 @@ namespace CGAL { iterator end() { return iterator(mmap,mmap.null_handle); } const_iterator begin() const { return const_iterator(mmap); } const_iterator end() const { return const_iterator(mmap,mmap.null_handle); } - size_type size() + size_type size() const { if (msize==0) - for ( const_iterator it=begin(); it!=end(); ++it) + for ( const_iterator it=begin(), itend=end(); it!=itend; ++it) ++msize; return msize; } @@ -2474,7 +2546,7 @@ namespace CGAL { { return mmap.is_empty(); } private: Self & mmap; - size_type msize; + mutable size_type msize; }; //************************************************************************** // One_dart_per_cell_const_range @@ -2486,10 +2558,10 @@ namespace CGAL { {} const_iterator begin() const { return const_iterator(mmap); } const_iterator end() const { return const_iterator(mmap,mmap.null_handle); } - size_type size() + size_type size() const { if (msize==0) - for ( const_iterator it=begin(); it!=end(); ++it) + for ( const_iterator it=begin(), itend=end(); it!=itend; ++it) ++msize; return msize; } @@ -2497,7 +2569,7 @@ namespace CGAL { { return mmap.is_empty(); } private: const Self & mmap; - size_type msize; + mutable size_type msize; }; //************************************************************************** /// @return a range on the i-cells incindent to the given j-cell. @@ -2624,8 +2696,8 @@ namespace CGAL { std::deque< Dart_const_handle > toTreat1; std::deque< typename Map2::Dart_const_handle > toTreat2; - int m1 = get_new_mark(); - int m2 = map2.get_new_mark(); + size_type m1 = get_new_mark(); + size_type m2 = map2.get_new_mark(); toTreat1.push_back(dh1); toTreat2.push_back(dh2); @@ -2807,6 +2879,26 @@ namespace CGAL { return false; } + /** Test if the attributes of this map are automatically updated. + * @return true iff the boolean automatic_attributes_management is set to true. + */ + bool are_attributes_automatically_managed() const + { + return automatic_attributes_management; + } + + /** Sets the automatic_attributes_management boolean. + */ + void set_automatic_attributes_management(bool newval) + { + if (this->automatic_attributes_management == false && newval == true) + { + correct_invalid_attributes(); + } + + this->automatic_attributes_management = newval; + } + protected: /// Number of times each mark is reserved. 0 if the mark is free. mutable size_type mnb_times_reserved_marks[NB_MARKS]; @@ -2821,10 +2913,10 @@ namespace CGAL { mutable size_type mindex_marks[NB_MARKS]; /// "Stack" of free marks. - mutable int mfree_marks_stack[NB_MARKS]; + mutable size_type mfree_marks_stack[NB_MARKS]; /// "Stack" of used marks. - mutable int mused_marks_stack[NB_MARKS]; + mutable size_type mused_marks_stack[NB_MARKS]; /// Number of marked darts for each used marks. mutable size_type mnb_marked_darts[NB_MARKS]; @@ -2857,6 +2949,8 @@ namespace CGAL { typedef typename Base::Dart_handle Dart_handle; typedef typename Base::Dart_const_handle Dart_const_handle; typedef typename Base::Alloc Alloc; + typedef typename Base::Exception_no_more_available_mark + Exception_no_more_available_mark; Generalized_map() : Base() {} diff --git a/Generalized_map/include/CGAL/Generalized_map_iterators_base.h b/Generalized_map/include/CGAL/Generalized_map_iterators_base.h index 000600e3c8d..21f147003a7 100644 --- a/Generalized_map/include/CGAL/Generalized_map_iterators_base.h +++ b/Generalized_map/include/CGAL/Generalized_map_iterators_base.h @@ -39,7 +39,7 @@ namespace CGAL { */ //**************************************************************************** /// Enum of all the possible operations used by the ++ operator. - /// Extension of the enum for generalized maps. + /// Extension of the enum for combinatorial maps. enum { OP_ALPHAI=OP_END+1, ///< Previous op was the first alpha. @@ -71,7 +71,7 @@ namespace CGAL { public: /// Main constructor. - GMap_extend_iterator(Map& amap, Dart_handle adart, int amark): + GMap_extend_iterator(Map& amap, Dart_handle adart, size_type amark): Base(amap, adart), mmark_number(amark), minitial_dart(adart) @@ -82,8 +82,6 @@ namespace CGAL { 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); } } } @@ -91,22 +89,20 @@ namespace CGAL { /// Rewind of the iterator to its beginning. void rewind() { - CGAL_assertion(mmark_number != -1); + CGAL_assertion(mmark_number != Map::INVALID_MARK); 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(mmark_number != Map::INVALID_MARK); CGAL_assertion(this->cont()); do @@ -118,29 +114,34 @@ namespace CGAL { 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) ); + CGAL_assertion( !this->mmap->is_marked((*this), mmark_number) ); + this->mmap->mark((*this), mmark_number); - if (!this->mmap->is_free(*this, Ai) && - !this->mmap->is_marked(this->mmap->alpha(*this, Ai), mmark_number) ) + if (!this->mmap->template is_free(*this) && + !this->mmap->is_marked(this->mmap->template alpha(*this), mmark_number) ) { - mto_treat.push(this->mmap->alpha(*this, Ai)); - this->mmap->mark(this->mmap->alpha(*this, Ai), mmark_number); + mto_treat.push(this->mmap->template alpha(*this)); } } } else { this->mmap->mark((*this), mmark_number); - if (!this->mmap->is_free(*this, Ai) && + if (!this->mmap->template is_free(*this) && !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); + mto_treat.push(this->mmap->template alpha(*this)); } } @@ -156,7 +157,7 @@ namespace CGAL { std::queue mto_treat; /// Index of the used mark. - int mmark_number; + size_type mmark_number; /// Initial dart Dart_handle minitial_dart; @@ -178,8 +179,10 @@ namespace CGAL { typedef Tag_true Use_mark; + typedef typename Map::size_type size_type; + /// Main constructor. - GMap_extend_iterator(Map& amap, Dart_handle adart, int amark): + GMap_extend_iterator(Map& amap, Dart_handle adart, size_type amark): Base(amap, adart, amark) { if (adart!=amap.null_handle) @@ -188,7 +191,6 @@ namespace CGAL { !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); } } } @@ -196,12 +198,11 @@ namespace CGAL { /// Rewind of the iterator to its beginning. void rewind() { - CGAL_assertion(this->mmark_number != -1); + 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)); - this->mmap->mark(this->mmap->alpha(this->minitial_dart, Ai), this->mmark_number); } } @@ -219,7 +220,6 @@ namespace CGAL { 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; diff --git a/Generalized_map/include/CGAL/Generalized_map_storages.h b/Generalized_map/include/CGAL/Generalized_map_storages.h index c65b6d009c2..3a599f9bb0d 100644 --- a/Generalized_map/include/CGAL/Generalized_map_storages.h +++ b/Generalized_map/include/CGAL/Generalized_map_storages.h @@ -125,21 +125,21 @@ namespace CGAL { return ADart->get_marks(); } /// Return the mark value of dart a given mark number. - bool get_dart_mark(Dart_const_handle ADart, int amark) const + bool get_dart_mark(Dart_const_handle ADart, size_type amark) const { CGAL_assertion( ADart!=NULL ); return ADart->get_mark(amark); } /// Set the mark of a given mark number to a given value. - void set_dart_mark(Dart_const_handle ADart, int amark, bool avalue) const + void set_dart_mark(Dart_const_handle ADart, size_type amark, bool avalue) const { CGAL_assertion( ADart!=NULL ); ADart->set_mark(amark, avalue); } /// Flip the mark of a given mark number to a given value. - void flip_dart_mark(Dart_const_handle ADart, int amark) const + void flip_dart_mark(Dart_const_handle ADart, size_type amark) const { CGAL_assertion( ADart!=NULL ); ADart->flip_mark(amark);