diff --git a/Arrangement_on_surface_2/include/CGAL/Arr_dcel_base.h b/Arrangement_on_surface_2/include/CGAL/Arr_dcel_base.h index 37a34750d7f..0d91b8c5044 100644 --- a/Arrangement_on_surface_2/include/CGAL/Arr_dcel_base.h +++ b/Arrangement_on_surface_2/include/CGAL/Arr_dcel_base.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -89,9 +89,6 @@ public: /*! Destructor. */ virtual ~Arr_vertex_base() {} - void* for_compact_container() const { return static_cast(p_pt); } - void for_compact_container(void* ptr) { p_pt = static_cast(ptr); } - // Access/modification for pointer squatting void* inc() const { return p_inc; } void set_inc(void * inc) const @@ -184,9 +181,6 @@ public: /*! Destructor. */ virtual ~Arr_halfedge_base() {} - void* for_compact_container() const { return static_cast(p_cv); } - void for_compact_container(void* ptr) { p_cv = static_cast(ptr); } - /*! Check if the curve pointer is nullptr. */ bool has_null_curve() const { return (p_cv == nullptr); } @@ -288,7 +282,7 @@ template class Arr_isolated_vertex; * The default arrangement DCEL vertex class. */ template -class Arr_vertex : public V +class Arr_vertex : public V, public In_place_list_base > { public: @@ -355,7 +349,8 @@ public: * The default arrangement DCEL halfedge class. */ template -class Arr_halfedge : public H +class Arr_halfedge : public H, + public In_place_list_base > { public: typedef H Base; @@ -535,7 +530,7 @@ public: */ template class Arr_face : public F, - public Compact_container_base + public In_place_list_base > { public: typedef F Base; @@ -726,7 +721,7 @@ public: * Representation of an outer CCB. */ template -class Arr_outer_ccb { +class Arr_outer_ccb : public In_place_list_base > { public: typedef Arr_outer_ccb Self; typedef Arr_halfedge Halfedge; @@ -747,9 +742,6 @@ public: p_f(other.p_f), iter_is_not_singular(other.iter_is_not_singular) { if (other.iter_is_not_singular) iter = other.iter; } - void* for_compact_container() const { return static_cast(p_f); } - void for_compact_container(void* ptr) { p_f = static_cast(ptr); } - /*! Get a halfedge along the component (const version). */ const Halfedge* halfedge() const { return (*iter); } @@ -794,7 +786,7 @@ public: * Representation of an inner CCB. */ template -class Arr_inner_ccb : public Compact_container_base +class Arr_inner_ccb : public In_place_list_base > { public: typedef Arr_inner_ccb Self; @@ -914,7 +906,8 @@ public: * Representation of an isolated vertex. */ template -class Arr_isolated_vertex { +class Arr_isolated_vertex : +public In_place_list_base > { public: typedef Arr_isolated_vertex Self; typedef Arr_face Face; @@ -934,9 +927,6 @@ public: p_f(other.p_f), iter_is_not_singular(other.iter_is_not_singular) { if (other.iter_is_not_singular) iv_it = other.iv_it; } - void* for_compact_container() const { return static_cast(p_f); } - void for_compact_container(void* ptr) { p_f = static_cast(ptr); } - /*! Get the containing face (const version). */ const Face* face() const { return (p_f); } @@ -987,6 +977,13 @@ public: typedef Inner_ccb Hole; protected: + // The vetices, halfedges and faces are stored in three in-place lists. + typedef In_place_list Vertex_list; + typedef In_place_list Halfedge_list; + typedef In_place_list Face_list; + typedef In_place_list Outer_ccb_list; + typedef In_place_list Inner_ccb_list; + typedef In_place_list Iso_vert_list; typedef std::allocator_traits Allocator_traits; typedef typename Allocator_traits::template rebind_alloc Vertex_allocator; @@ -996,13 +993,6 @@ protected: typedef typename Allocator_traits::template rebind_alloc Inner_ccb_allocator; typedef typename Allocator_traits::template rebind_alloc Iso_vert_allocator; - typedef Compact_container Vertex_list; - typedef Compact_container Halfedge_list; - typedef Compact_container Face_list; - typedef Compact_container Outer_ccb_list; - typedef Compact_container Inner_ccb_list; - typedef Compact_container Iso_vert_list; - public: typedef typename Halfedge_list::size_type Size; typedef typename Halfedge_list::size_type size_type; @@ -1019,6 +1009,13 @@ protected: Inner_ccb_list in_ccbs; // The inner CCBs. Iso_vert_list iso_verts; // The isolated vertices. + Vertex_allocator vertex_alloc; // An allocator for vertices. + Halfedge_allocator halfedge_alloc; // An allocator for halfedges. + Face_allocator face_alloc; // An allocator for faces. + Outer_ccb_allocator out_ccb_alloc; // An allocator for outer CCBs. + Inner_ccb_allocator in_ccb_alloc; // An allocator for inner CCBs. + Iso_vert_allocator iso_vert_alloc; // Allocator for isolated vertices. + public: // Definitions of iterators. typedef typename Vertex_list::iterator Vertex_iterator; @@ -1145,7 +1142,10 @@ public: /*! Create a new vertex. */ Vertex* new_vertex() { - return &*vertices.emplace(); + Vertex* v = vertex_alloc.allocate(1); + std::allocator_traits::construct(vertex_alloc,v); + vertices.push_back(*v); + return v; } /*! Create a new pair of opposite halfedges. */ @@ -1165,25 +1165,37 @@ public: /*! Create a new face. */ Face* new_face() { - return &*faces.emplace(); + Face* f = face_alloc.allocate(1); + std::allocator_traits::construct(face_alloc, f); + faces.push_back (*f); + return(f); } /*! Create a new outer CCB. */ Outer_ccb* new_outer_ccb() { - return &*out_ccbs.emplace(); + Outer_ccb* oc = out_ccb_alloc.allocate(1); + std::allocator_traits::construct(out_ccb_alloc, oc); + out_ccbs.push_back(*oc); + return (oc); } /*! Create a new inner CCB. */ Inner_ccb* new_inner_ccb() { - return &*in_ccbs.emplace(); + Inner_ccb* ic = in_ccb_alloc.allocate(1); + std::allocator_traits::construct(in_ccb_alloc, ic); + in_ccbs.push_back(*ic); + return (ic); } /*! Create a new isolated vertex. */ Isolated_vertex* new_isolated_vertex() { - return &*iso_verts.emplace(); + Isolated_vertex* iv = iso_vert_alloc.allocate(1); + std::allocator_traits::construct(iso_vert_alloc, iv); + iso_verts.push_back(*iv); + return (iv); } //@} @@ -1192,7 +1204,9 @@ public: /*! Delete an existing vertex. */ void delete_vertex(Vertex* v) { - vertices.erase (vertices.iterator_to(*v)); + vertices.erase(v); + std::allocator_traits::destroy(vertex_alloc, v); + vertex_alloc.deallocate(v,1); } /*! Delete an existing pair of opposite halfedges. */ @@ -1206,36 +1220,85 @@ public: /*! Delete an existing face. */ void delete_face(Face* f) { - faces.erase (faces.iterator_to(*f)); + faces.erase(f); + std::allocator_traits::destroy(face_alloc, f); + face_alloc.deallocate(f, 1); } /*! Delete an existing outer CCB. */ void delete_outer_ccb(Outer_ccb* oc) { - out_ccbs.erase (out_ccbs.iterator_to(*oc)); + out_ccbs.erase(oc); + std::allocator_traits::destroy(out_ccb_alloc, oc); + out_ccb_alloc.deallocate(oc, 1); } /*! Delete an existing inner CCB. */ void delete_inner_ccb(Inner_ccb* ic) { - in_ccbs.erase (in_ccbs.iterator_to(*ic)); + in_ccbs.erase(ic); + std::allocator_traits::destroy(in_ccb_alloc, ic); + in_ccb_alloc.deallocate(ic, 1); } /*! Delete an existing isolated vertex. */ void delete_isolated_vertex(Isolated_vertex* iv) { - iso_verts.erase (iso_verts.iterator_to(*iv)); + iso_verts.erase(iv); + std::allocator_traits::destroy(iso_vert_alloc, iv); + iso_vert_alloc.deallocate(iv, 1); } /*! Delete all DCEL features. */ void delete_all() { - vertices.clear(); - halfedges.clear(); - faces.clear(); - out_ccbs.clear(); - in_ccbs.clear(); - iso_verts.clear(); + // Free all vertices. + Vertex_iterator vit = vertices.begin(), v_curr; + while (vit != vertices.end()) { + v_curr = vit; + ++vit; + delete_vertex(&(*v_curr)); + } + + // Free all halfedges. + Halfedge_iterator hit = halfedges.begin(), h_curr; + while (hit != halfedges.end()) { + h_curr = hit; + ++hit; + _delete_halfedge(&(*h_curr)); + } + + // Free all faces. + Face_iterator fit = faces.begin(), f_curr; + while (fit != faces.end()) { + f_curr = fit; + ++fit; + delete_face(&(*f_curr)); + } + + // Free all outer CCBs. + typename Outer_ccb_list::iterator ocit = out_ccbs.begin(), oc_curr; + while (ocit != out_ccbs.end()) { + oc_curr = ocit; + ++ocit; + delete_outer_ccb(&(*oc_curr)); + } + + // Free all inner CCBs. + typename Inner_ccb_list::iterator icit = in_ccbs.begin(), ic_curr; + while (icit != in_ccbs.end()) { + ic_curr = icit; + ++icit; + delete_inner_ccb(&(*ic_curr)); + } + + // Free all isolated vertices. + typename Iso_vert_list::iterator ivit = iso_verts.begin(), iv_curr; + while (ivit != iso_verts.end()) { + iv_curr = ivit; + ++ivit; + delete_isolated_vertex(&(*iv_curr)); + } } //@} @@ -1442,13 +1505,18 @@ protected: /*! Create a new halfedge. */ Halfedge* _new_halfedge() { - return &*halfedges.emplace(); + Halfedge* h = halfedge_alloc.allocate(1); + std::allocator_traits::construct(halfedge_alloc, h); + halfedges.push_back(*h); + return (h); } /*! Delete an existing halfedge. */ void _delete_halfedge(Halfedge* h) { - halfedges.erase (halfedges.iterator_to(*h)); + halfedges.erase(h); + std::allocator_traits::destroy(halfedge_alloc,h); + halfedge_alloc.deallocate(h, 1); } };