Eliminated the error-prone c-style casting of the arrangement object that occurs when using observers.

This commit is contained in:
Efi Fogel 2023-12-12 01:50:26 +02:00
parent a2ea1742c3
commit 5544ff4893
22 changed files with 58 additions and 183 deletions

View File

@ -5706,17 +5706,19 @@ changes when they occur. In our case observers can be attached to an
arrangement object. An attached observer receives notifications about
the changes this arrangement undergoes.
An observer object, the type of which is an instance of the
`Arr_observer<Arrangement>` class template, stores a pointer to an
arrangement object. When the `Arr_observer<Arrangement>` class
template is instantiated, the `Arrangement` parameter must be
substituted with the type of the arrangement object. The observer
receives notifications <em>just before</em> a structural change occurs
in the arrangement and <em>immediately after</em> such a change takes
place. `Arr_observer` serves as a base class for other
observer classes and defines a set of virtual notification
functions, with default empty implementations. The set of functions
can be divided into three categories, as follows:
An observer object that observes changes that an arrangement object of
type `Arrangement` undergoes must be of a type derived from
`Arrangement::Observer`. The observer object stores a pointer to the
observed arrangement object. The observer receives notifications
<em>just before</em> a structural change occurs in the arrangement and
<em>immediately after</em> such a change takes place.
`Arrangement::Observer` is an alias to
`Arr_observer<CGAL::Arrangement_on_surface_2<>>`, where
`CGAL::Arrangement_on_surface_2<>` is the type of the arrangement
object or its base type. It serves as a base type for other observer
classes and defines a set of virtual notification functions, with
default empty implementations. The set of functions can be divided
into three categories, as follows:
<OL>

View File

@ -21,12 +21,11 @@ to dynamically maintain the mapping of face handles to indices.
\cgalModels{DefaultConstructible,CopyConstructible,Assignable,ReadablePropertyMap}
\sa `Arr_observer<Arrangement>`
\sa `Arr_vertex_index_map<Arrangement>`
*/
template< typename Arrangement >
class Arr_face_index_map: public Arr_observer<Arrangement> {
class Arr_face_index_map: public Arrangement::Observer {
public:
/// \name Types
@ -74,4 +73,3 @@ Arr_face_index_map(Arrangement_2& arr);
}; /* end Arr_accessor */
} /* end namespace CGAL */

View File

@ -23,7 +23,6 @@ namespace CGAL {
*/
template <typename Arrangement_>
class Arr_triangulation_point_location : public Arr_observer<Arrangement_>
{}
class Arr_triangulation_point_location : public Arrangement_::Observer {}
}

View File

@ -21,12 +21,11 @@ to dynamically maintain the mapping of vertex handles to indices.
\cgalModels{DefaultConstructible,CopyConstructible,Assignable,ReadablePropertyMap}
\sa `Arr_observer<Arrangement>`
\sa `Arr_face_index_map<Arrangement>`
*/
template< typename Arrangement >
class Arr_vertex_index_map: public Arr_observer<Arrangement> {
class Arr_vertex_index_map: public Arrangement::Observer {
public:
/// \name Types
@ -74,9 +73,3 @@ Arr_vertex_index_map(Arrangement_2& arr);
}; /* end Arr_accessor */
} /* end namespace CGAL */

View File

@ -3,7 +3,6 @@
#include <CGAL/basic.h>
#include <CGAL/Arr_extended_dcel.h>
#include <CGAL/Arr_observer.h>
#include "arr_exact_construction_segments.h"
@ -12,13 +11,14 @@ using Ex_arrangement = CGAL::Arrangement_2<Traits, Dcel>;
// An arrangement observer, used to receive notifications of face splits and
// to update the indices of the newly created faces.
class Face_index_observer : public CGAL::Arr_observer<Ex_arrangement> {
class Face_index_observer : public Ex_arrangement::Observer {
private:
size_t n_faces; // the current number of faces
public:
Face_index_observer(Ex_arrangement& arr) :
CGAL::Arr_observer<Ex_arrangement>(arr), n_faces(0)
Ex_arrangement::Observer(arr),
n_faces(0)
{
CGAL_precondition(arr.is_empty());
arr.unbounded_face()->set_data (0);

View File

@ -2,15 +2,14 @@
// Using a simple arrangement observer.
#include <CGAL/basic.h>
#include <CGAL/Arr_observer.h>
#include "arr_exact_construction_segments.h"
#include "arr_print.h"
// An observer that receives notifications of face splits and face mergers.
class My_observer : public CGAL::Arr_observer<Arrangement> {
class My_observer : public Arrangement::Observer {
public:
My_observer(Arrangement& arr) : CGAL::Arr_observer<Arrangement>(arr) {}
My_observer(Arrangement& arr) : Arrangement::Observer(arr) {}
virtual void before_split_face(Face_handle, Halfedge_handle e) {
std::cout << "-> The insertion of : [ " << e->curve()

View File

@ -21,7 +21,6 @@
* Definition of the Arr_face_index_map<Arrangement> class.
*/
#include <CGAL/Arr_observer.h>
#include <CGAL/Unique_hash_map.h>
#include <CGAL/property_map.h>
@ -35,8 +34,7 @@ namespace CGAL {
* of faces in the arrangement.
*/
template <class Arrangement_>
class Arr_face_index_map : public Arr_observer<Arrangement_>
{
class Arr_face_index_map : public Arrangement_::Observer {
public:
typedef Arrangement_ Arrangement_2;
@ -51,7 +49,7 @@ public:
private:
typedef Arr_face_index_map<Arrangement_2> Self;
typedef Arr_observer<Arrangement_2> Base;
typedef typename Arrangement_2::Observer Base;
typedef Unique_hash_map<Face_handle, unsigned int> Index_map;
@ -80,7 +78,7 @@ public:
/*! Copy constructor. */
Arr_face_index_map (const Self& other) :
Base (const_cast<Arrangement_2&> (*(other.arrangement())))
Base(const_cast<typename Base::Arrangement_2&>(*(other.arrangement())))
{
_init();
}
@ -92,7 +90,7 @@ public:
return (*this);
this->detach();
this->attach (const_cast<Arrangement_2&> (*(other.arrangement())));
this->attach(const_cast<typename Base::Arrangement_2&>(*(other.arrangement())));
return (*this);
}

View File

@ -20,7 +20,6 @@
* Definition of the Arr_landmarks_generator_base<Arrangement> template.
*/
#include <CGAL/Arr_point_location_result.h>
#include <CGAL/Arr_observer.h>
#include <CGAL/Arrangement_2/Arr_traits_adaptor_2.h>
#include <CGAL/Arr_point_location/Arr_lm_nearest_neighbor.h>
#include <CGAL/Arr_batched_point_location.h>
@ -44,7 +43,7 @@ namespace CGAL {
template <typename Arrangement_,
typename Nearest_neighbor_ =
Arr_landmarks_nearest_neighbor<Arrangement_> >
class Arr_landmarks_generator_base : public Arr_observer <Arrangement_> {
class Arr_landmarks_generator_base : public Arrangement_::Observer {
public:
typedef Arrangement_ Arrangement_2;
typedef Nearest_neighbor_ Nearest_neighbor;
@ -110,7 +109,7 @@ public:
* \param arr (in) The arrangement.
*/
Arr_landmarks_generator_base(const Arrangement_2& arr) :
Arr_observer<Arrangement_2> (const_cast<Arrangement_2 &>(arr)),
Arrangement_2::Observer(const_cast<Arrangement_2&>(arr)),
m_traits(static_cast<const Traits_adaptor_2*>(arr.geometry_traits())),
m_ignore_notifications(false),
m_ignore_remove_edge(false),

View File

@ -99,13 +99,12 @@ public:
{
// Go over the arrangement, and insert all its vertices as landmarks.
NN_Point_list nnp_list;
const Arrangement_2* arr = this->arrangement();
Vertex_const_iterator vit;
const auto* arr = this->arrangement();
num_landmarks = 0;
for (vit = arr->vertices_begin(); vit != arr->vertices_end(); ++vit) {
for (auto vit = arr->vertices_begin(); vit != arr->vertices_end(); ++vit) {
Vertex_const_handle vh = vit;
nnp_list.push_back(NN_Point_2(vh->point(), this->pl_make_result(vh)));
num_landmarks++;
++num_landmarks;
}
// Update the search structure.

View File

@ -26,7 +26,6 @@
#include <CGAL/Arrangement_2/Arr_traits_adaptor_2.h>
#include <CGAL/Arr_point_location/Trapezoidal_decomposition_2.h>
#include <CGAL/Arr_point_location/Td_traits.h>
#include <CGAL/Arr_observer.h>
namespace CGAL {
@ -36,7 +35,7 @@ namespace CGAL {
* The Arrangement parameter corresponds to an arrangement instantiation.
*/
template <typename Arrangement_>
class Arr_trapezoid_ric_point_location : public Arr_observer <Arrangement_> {
class Arr_trapezoid_ric_point_location : public Arrangement_::Observer {
public:
//type of arrangement on surface
typedef Arrangement_ Arrangement_on_surface_2;
@ -148,8 +147,8 @@ public:
bool with_guarantees = true,
double depth_thrs = CGAL_TD_DEFAULT_DEPTH_THRESHOLD,
double size_thrs = CGAL_TD_DEFAULT_SIZE_THRESHOLD) :
Arr_observer<Arrangement_on_surface_2>
(const_cast<Arrangement_on_surface_2 &>(arr)),
Arrangement_on_surface_2::
Observer(const_cast<Arrangement_on_surface_2&>(arr)),
m_with_guarantees(with_guarantees)
{
m_traits = static_cast<const Traits_adaptor_2*> (arr.geometry_traits());
@ -352,7 +351,7 @@ protected:
std::vector<Halfedge_const_handle> he_container;
Edge_const_iterator eit;
Halfedge_const_handle he_cst;
Arrangement_on_surface_2 *arr = this->arrangement();
auto* arr = this->arrangement();
//collect the arrangement halfedges
for (eit = arr->edges_begin(); eit != arr->edges_end(); ++eit)
{

View File

@ -39,8 +39,7 @@ namespace CGAL {
* triangulation algorithm.
*/
template <typename Arrangement_>
class Arr_triangulation_point_location : public Arr_observer<Arrangement_>
{
class Arr_triangulation_point_location : public Arrangement_::Observer {
public:
typedef Arrangement_ Arrangement_2;
@ -129,7 +128,7 @@ public:
* \param arr (in) The arrangement.
*/
Arr_triangulation_point_location(const Arrangement_2& arr) :
Arr_observer<Arrangement_2>(const_cast<Arrangement_2&>(arr)),
Arrangement_2::Observer(const_cast<Arrangement_2&>(arr)),
m_traits(static_cast<const Traits_adaptor_2*>(arr.geometry_traits())),
m_ignore_notifications(false),
m_ignore_remove_edge(false)

View File

@ -22,7 +22,6 @@
/*! \file
* Definition of the Arr_vertex_index_map<Arrangement> class.
*/
#include <CGAL/Arr_observer.h>
#include <CGAL/Unique_hash_map.h>
#include <CGAL/property_map.h>
@ -36,8 +35,7 @@ namespace CGAL {
* of vertices in the arrangement.
*/
template <class Arrangement_>
class Arr_vertex_index_map : public Arr_observer<Arrangement_>
{
class Arr_vertex_index_map : public Arrangement_::Observer {
public:
typedef Arrangement_ Arrangement_2;
@ -52,7 +50,7 @@ public:
private:
typedef Arr_vertex_index_map<Arrangement_2> Self;
typedef Arr_observer<Arrangement_2> Base;
typedef typename Arrangement_2::Observer Base;
typedef Unique_hash_map<Vertex_handle, unsigned int> Index_map;
@ -81,7 +79,7 @@ public:
/*! Copy constructor. */
Arr_vertex_index_map (const Self& other) :
Base (const_cast<Arrangement_2&> (*(other.arrangement())))
Base(const_cast<typename Base::Arrangement_2&> (*(other.arrangement())))
{
_init();
}
@ -93,7 +91,7 @@ public:
return (*this);
this->detach();
this->attach (const_cast<Arrangement_2&> (*(other.arrangement())));
this->attach (const_cast<typename Base::Arrangement_2&> (*(other.arrangement())));
return (*this);
}

View File

@ -115,12 +115,9 @@ public:
typedef typename Base::Inner_ccb_const_iterator Hole_const_iterator;
private:
friend class Arr_observer<Self>;
friend class Arr_accessor<Self>;
public:
/// \name Constructors.
//@{
@ -215,34 +212,6 @@ public:
}
//@}
protected:
/// \name Managing and notifying the arrangement observers.
//@{
typedef Arr_observer<Self> Observer;
/*!
* Register a new observer (so it starts receiving notifications).
* \param p_obs A pointer to the observer object.
*/
void _register_observer (Observer *p_obs)
{
Base::_register_observer ((typename Base::Observer*)p_obs);
return;
}
/*!
* Unregister a new observer (so it stops receiving notifications).
* \param p_obs A pointer to the observer object.
* \return Whether the observer was successfully unregistered.
*/
bool _unregister_observer (Observer *p_obs)
{
return (Base::_unregister_observer ((typename Base::Observer*)p_obs));
}
//@}
};
} //namespace CGAL

View File

@ -273,29 +273,6 @@ bool Arrangement_on_surface_with_history_2<GeomTr,TopTr>::are_mergeable
e2->curve()));
}
//-----------------------------------------------------------------------------
// Register a new observer (so it starts receiving notifications).
//
template<class GeomTr, class TopTr>
void Arrangement_on_surface_with_history_2<GeomTr,TopTr>::
_register_observer(Arr_observer<Self> *p_obs)
{
Base_arr_2::_register_observer
(reinterpret_cast<Arr_observer<Base_arr_2>*>(p_obs));
return;
}
//-----------------------------------------------------------------------------
// Unregister an observer (so it stops receiving notifications).
//
template<class GeomTr, class TopTr>
bool Arrangement_on_surface_with_history_2<GeomTr,TopTr>::
_unregister_observer(Arr_observer<Self> *p_obs)
{
return (Base_arr_2::_unregister_observer
(reinterpret_cast<Arr_observer<Base_arr_2>*>(p_obs)));
}
} //namespace CGAL
#endif

View File

@ -109,6 +109,8 @@ public:
typedef typename Topology_traits::Dcel Dcel;
typedef typename Dcel::Size Size;
typedef Arr_observer<Self> Observer;
protected:
friend class Arr_observer<Self>;
friend class Arr_accessor<Self>;
@ -892,7 +894,6 @@ protected:
typedef CGAL_ALLOCATOR(Point_2) Points_alloc;
typedef CGAL_ALLOCATOR(X_monotone_curve_2) Curves_alloc;
typedef Arr_observer<Self> Observer;
typedef std::list<Observer*> Observers_container;
typedef typename Observers_container::iterator Observers_iterator;

View File

@ -26,7 +26,6 @@
#include <CGAL/Arrangement_on_surface_2.h>
#include <CGAL/Arr_overlay_2.h>
#include <CGAL/Arr_consolidated_curve_data_traits_2.h>
#include <CGAL/Arr_observer.h>
#include <CGAL/In_place_list.h>
#include <CGAL/Arrangement_2/Arr_with_history_accessor.h>
@ -75,10 +74,7 @@ public:
typedef typename Geometry_traits_2::Curve_2 Curve_2;
typedef typename Geometry_traits_2::X_monotone_curve_2 X_monotone_curve_2;
typedef Arr_observer<Self> Observer;
protected:
friend class Arr_observer<Self>;
friend class Arr_accessor<Self>;
friend class Arr_with_history_accessor<Self>;
@ -582,24 +578,6 @@ public:
//@}
protected:
/// \name Managing and notifying the arrangement observers.
//@{
/*!
* Register a new observer (so it starts receiving notifications).
* \param p_obs A pointer to the observer object.
*/
void _register_observer (Observer *p_obs);
/*!
* Unregister an observer (so it stops receiving notifications).
* \param p_obs A pointer to the observer object.
* \return Whether the observer was successfully unregistered.
*/
bool _unregister_observer (Observer *p_obs);
//@}
/// \name Curve insertion and deletion.
//@{

View File

@ -119,7 +119,6 @@ public:
private:
typedef Arrangement_with_history_2<Geometry_traits_2, Dcel> Self;
friend class Arr_observer<Self>;
friend class Arr_accessor<Self>;
public:
@ -233,35 +232,8 @@ public:
return (Face_const_handle (p_oc->face()));
}
//@}
protected:
/// \name Managing and notifying the arrangement observers.
//@{
typedef Arr_observer<Self> Observer;
/*!
* Register a new observer (so it starts receiving notifications).
* \param p_obs A pointer to the observer object.
*/
void _register_observer (Observer *p_obs)
{
Base::_register_observer ((typename Base::Observer*)p_obs);
return;
}
/*!
* Unregister a new observer (so it stops receiving notifications).
* \param p_obs A pointer to the observer object.
* \return Whether the observer was successfully unregistered.
*/
bool _unregister_observer (Observer *p_obs)
{
return (Base::_unregister_observer ((typename Base::Observer*)p_obs));
}
//@}
};
} //namespace CGAL

View File

@ -5,7 +5,6 @@
#include <CGAL/MP_Float.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arrangement_2.h>
#include <CGAL/Arr_observer.h>
#include <CGAL/Arr_enums.h>
#include <iostream>
@ -57,14 +56,11 @@ void compare_results(std::string str)
// An arrangement observer, used to receive notifications of face splits and
// face mergers.
class Test_observer : public CGAL::Arr_observer<Arrangement_2>
{
class Test_observer : public Arrangement_2::Observer {
public:
Test_observer (Arrangement_2& arr) :
CGAL::Arr_observer<Arrangement_2> (arr)
{}
Test_observer(Arrangement_2& arr) : Arrangement_2::Observer(arr) {}
/// \name Notification functions on global arrangement operations.
//@{

View File

@ -28,7 +28,6 @@
#include <time.h>
#include <CGAL/enum.h>
#include <CGAL/Arr_observer.h>
#include <CGAL/Envelope_3/Envelope_base.h>
#include <CGAL/Envelope_3/Envelope_overlay_2.h>
#include <CGAL/Envelope_3/Envelope_element_visitor_3.h>
@ -134,7 +133,8 @@ protected:
typedef typename Minimization_diagram_2::Inner_ccb_iterator
Inner_ccb_iterator;
typedef Arr_observer<Minimization_diagram_2> Md_observer;
typedef typename Minimization_diagram_2::Observer
Md_observer;
typedef typename Minimization_diagram_2::Dcel::Dcel_data_iterator
Envelope_data_iterator;

View File

@ -96,7 +96,7 @@ protected:
typedef typename Minimization_diagram_2::Dcel::Dcel_data_iterator
Envelope_data_iterator;
typedef Arr_observer<Minimization_diagram_2> Md_observer;
typedef typename Minimization_diagram_2::Observer Md_observer;
typedef Arr_accessor<Minimization_diagram_2> Md_accessor;
typedef typename Topology_traits::Default_point_location_strategy

View File

@ -77,9 +77,9 @@ private:
// An arrangement observer, used to receive notifications of face splits and
// face mergers.
class My_observer : public CGAL::Arr_observer<Arrangement_2> {
class My_observer : public Arrangement_2::Observer {
public:
My_observer(Arrangement_2& arr) : Arr_observer<Arrangement_2>(arr) {}
My_observer(Arrangement_2& arr) : Arrangement_2::Observer(arr) {}
virtual void after_split_face(Face_handle f, Face_handle new_f,
bool /* is_hole */)

View File

@ -21,7 +21,6 @@
#include <memory>
#include <CGAL/boost/iterator/transform_iterator.hpp>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Arr_observer.h>
#include <CGAL/assertions.h>
#include <CGAL/use.h>
@ -86,10 +85,10 @@ private:
};
// Observer to track any changes of the attached arrangement.
class Observer : public Arr_observer<Arrangement_2>
class Observer : public Arrangement_2::Observer
{
typedef Arr_observer<Arrangement_2> Base;
typedef typename Arrangement_2::Observer Base;
typedef Observer Self;