Use unique_ptr, following Rineau's comment

This commit is contained in:
Thien Hoang 2019-08-13 15:12:07 +07:00
parent 7665677003
commit 5b001f72d8
3 changed files with 14 additions and 12 deletions

View File

@ -39,7 +39,7 @@ namespace Surface_mesh_topology {
/// clears this path. /// clears this path.
void clear(); void clear();
/// returns `true` iff `hd` can be added at the end of this path. If `flip` is true, `hd`'d direction is reversed before checking /// returns `true` iff `hd` can be added at the end of this path. If `flip` is true, `hd`'s direction is reversed before checking
bool can_be_pushed(halfedge_descriptor hd, bool flip=false) const; bool can_be_pushed(halfedge_descriptor hd, bool flip=false) const;
/// adds `hd` at the end of this path. If `flip` is true, the reverse of `hd` is considered. /// adds `hd` at the end of this path. If `flip` is true, the reverse of `hd` is considered.

View File

@ -28,6 +28,7 @@
#include <CGAL/Surface_mesh_topology/internal/Facewidth.h> #include <CGAL/Surface_mesh_topology/internal/Facewidth.h>
#include <CGAL/Surface_mesh_topology/internal/Generic_map_selector.h> #include <CGAL/Surface_mesh_topology/internal/Generic_map_selector.h>
#include <CGAL/Face_graph_wrapper.h> #include <CGAL/Face_graph_wrapper.h>
#include <memory>
namespace CGAL { namespace CGAL {
namespace Surface_mesh_topology { namespace Surface_mesh_topology {
@ -110,7 +111,7 @@ public:
Path_on_surface<Mesh> compute_edgewidth(const WeightFunctor& wf) const Path_on_surface<Mesh> compute_edgewidth(const WeightFunctor& wf) const
{ {
if (m_shortest_noncontractible_cycle==nullptr) if (m_shortest_noncontractible_cycle==nullptr)
{ m_shortest_noncontractible_cycle = new Shortest_noncontractible_cycle(m_original_map); } { update_shortest_noncontractible_cycle_pointer(); }
return m_shortest_noncontractible_cycle->compute_edgewidth(NULL, wf); return m_shortest_noncontractible_cycle->compute_edgewidth(NULL, wf);
} }
@ -118,7 +119,7 @@ public:
Path_on_surface<Mesh> compute_edgewidth() const Path_on_surface<Mesh> compute_edgewidth() const
{ {
if (m_shortest_noncontractible_cycle==nullptr) if (m_shortest_noncontractible_cycle==nullptr)
{ m_shortest_noncontractible_cycle = new Shortest_noncontractible_cycle(m_original_map); } { update_shortest_noncontractible_cycle_pointer(); }
return m_shortest_noncontractible_cycle->compute_edgewidth(); return m_shortest_noncontractible_cycle->compute_edgewidth();
} }
@ -127,7 +128,7 @@ public:
Path_on_surface<Mesh> compute_shortest_noncontractible_cycle_with_basepoint(DartHandle dh, const WeightFunctor& wf) const Path_on_surface<Mesh> compute_shortest_noncontractible_cycle_with_basepoint(DartHandle dh, const WeightFunctor& wf) const
{ {
if (m_shortest_noncontractible_cycle==nullptr) if (m_shortest_noncontractible_cycle==nullptr)
{ m_shortest_noncontractible_cycle = new Shortest_noncontractible_cycle(m_original_map); } { update_shortest_noncontractible_cycle_pointer(); }
return m_shortest_noncontractible_cycle->compute_cycle(dh, NULL, wf); return m_shortest_noncontractible_cycle->compute_cycle(dh, NULL, wf);
} }
@ -136,7 +137,7 @@ public:
Path_on_surface<Mesh> compute_shortest_noncontractible_cycle_with_basepoint(DartHandle dh) const Path_on_surface<Mesh> compute_shortest_noncontractible_cycle_with_basepoint(DartHandle dh) const
{ {
if (m_shortest_noncontractible_cycle==nullptr) if (m_shortest_noncontractible_cycle==nullptr)
{ m_shortest_noncontractible_cycle = new Shortest_noncontractible_cycle(m_original_map); } { update_shortest_noncontractible_cycle_pointer(); }
return m_shortest_noncontractible_cycle->compute_cycle(dh); return m_shortest_noncontractible_cycle->compute_cycle(dh);
} }
@ -144,27 +145,27 @@ public:
Path_on_surface<Mesh> compute_facewidth() const Path_on_surface<Mesh> compute_facewidth() const
{ {
if (m_facewidth==nullptr) if (m_facewidth==nullptr)
{ m_facewidth = new Facewidth(m_original_map); } { update_facewidth_pointer(); }
return m_facewidth->compute_facewidth(); return m_facewidth->compute_facewidth();
} }
void update_shortest_noncontractible_cycle_pointer() void update_shortest_noncontractible_cycle_pointer() const
{ {
m_shortest_noncontractible_cycle = new Shortest_noncontractible_cycle(m_original_map); m_shortest_noncontractible_cycle = std::make_unique<Shortest_noncontractible_cycle>(m_original_map);
} }
void update_facewidth_pointer() void update_facewidth_pointer() const
{ {
m_facewidth = new Facewidth(m_original_map); m_facewidth = std::make_unique<Facewidth>(m_original_map);
} }
protected: protected:
Mesh& m_original_map; Mesh& m_original_map;
mutable Gmap m_radial_map; mutable Gmap m_radial_map;
mutable internal::Minimal_quadrangulation<Mesh>* m_minimal_quadrangulation; mutable internal::Minimal_quadrangulation<Mesh>* m_minimal_quadrangulation;
mutable Shortest_noncontractible_cycle* m_shortest_noncontractible_cycle; mutable std::unique_ptr<Shortest_noncontractible_cycle> m_shortest_noncontractible_cycle;
mutable Facewidth* m_facewidth; mutable std::unique_ptr<Facewidth> m_facewidth;
typename Gmap_wrapper::Origin_to_copy_map m_origin_to_copy; typename Gmap_wrapper::Origin_to_copy_map m_origin_to_copy;
typename Gmap_wrapper::Copy_to_origin_map m_copy_to_origin; typename Gmap_wrapper::Copy_to_origin_map m_copy_to_origin;
}; };

View File

@ -69,6 +69,7 @@ public:
~Shortest_noncontractible_cycle() ~Shortest_noncontractible_cycle()
{ {
// std::cerr << "Destructor...\n"; // For testing unique_ptr
m_gmap.free_mark(m_is_hole); m_gmap.free_mark(m_is_hole);
} }