From e294cd8fe9542944dd6113fb2211fd5ecf4779cf Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 9 May 2017 17:47:18 +0200 Subject: [PATCH] Fix new (recycled) time stamps when a TDS is copied --- Mesh_3/test/Mesh_3/test_meshing_utilities.h | 29 +++++++++++++++++++ STL_Extension/include/CGAL/Time_stamper.h | 8 ++++- .../STL_Extension/test_Compact_container.cpp | 19 ++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/Mesh_3/test/Mesh_3/test_meshing_utilities.h b/Mesh_3/test/Mesh_3/test_meshing_utilities.h index ca657b17288..580cc66b454 100644 --- a/Mesh_3/test/Mesh_3/test_meshing_utilities.h +++ b/Mesh_3/test/Mesh_3/test_meshing_utilities.h @@ -54,6 +54,34 @@ struct Bissection_tag {}; struct Polyhedral_tag {}; +// Verify that the time stamps of vertices and cells are strictly +// increasing +template +void verify_time_stamps(const C3t3& c3t3, CGAL::Sequential_tag) { + typedef typename C3t3::Triangulation::Triangulation_data_structure TDS; + const TDS& tds = c3t3.triangulation().tds(); + { + typename TDS::Vertex_iterator prev = tds.vertices_begin(); + assert(0 == prev->time_stamp()); + typename TDS::Vertex_iterator vit = prev; + ++vit; + for(; vit != tds.vertices_end(); ++vit, ++prev) { + assert(prev->time_stamp() < vit->time_stamp()); + } + } + { + typename TDS::Cell_iterator prev = tds.cells_begin(); + typename TDS::Cell_iterator cit = prev; + ++cit; + for(; cit != tds.cells_end(); ++cit, ++prev) { + assert(prev->time_stamp() < cit->time_stamp()); + } + } +} + +// Do not verify time stamps in parallel mode +template +void verify_time_stamps(const C3t3&, CGAL::Parallel_tag) {} template struct Tester @@ -180,6 +208,7 @@ struct Tester const std::size_t min_cells_expected = 0, const std::size_t max_cells_expected = STD_SIZE_T_MAX ) const { + verify_time_stamps(c3t3, typename C3t3::Concurrency_tag()); //------------------------------------------------------- // Verifications //------------------------------------------------------- diff --git a/STL_Extension/include/CGAL/Time_stamper.h b/STL_Extension/include/CGAL/Time_stamper.h index 57c58f5ce58..a35f29a2e30 100644 --- a/STL_Extension/include/CGAL/Time_stamper.h +++ b/STL_Extension/include/CGAL/Time_stamper.h @@ -39,7 +39,13 @@ struct Time_stamper void set_time_stamp(T* pt) { if(pt->time_stamp() == std::size_t(-1)) pt->set_time_stamp(time_stamp_++); - // else: the time stamp is re-used + else { + // else: the time stamp is re-used + + // Enforces that the time stamp is greater than the current value. + // That is used when a TDS_3 is copied. + time_stamp_ = (std::max)(time_stamp_, pt->time_stamp() + 1); + } } diff --git a/STL_Extension/test/STL_Extension/test_Compact_container.cpp b/STL_Extension/test/STL_Extension/test_Compact_container.cpp index 567e78c872f..19d40d71549 100644 --- a/STL_Extension/test/STL_Extension/test_Compact_container.cpp +++ b/STL_Extension/test/STL_Extension/test_Compact_container.cpp @@ -19,6 +19,7 @@ template struct Node_1 : public CGAL::Compact_container_base { + Node_1() {} // // it is important `time_stamp_` is not initialized bool operator==(const Node_1 &) const { return true; } bool operator!=(const Node_1 &) const { return false; } bool operator< (const Node_1 &) const { return false; } @@ -273,6 +274,22 @@ void test_index(const Cont &C) } } +template < class Cont > +void test_time_stamps() { + Cont c1; + for (std::size_t i = 0 ; i < 10 ; ++i) + c1.emplace(); + typename Cont::iterator it = c1.begin(); + for (std::size_t i = 0 ; i < 10 ; ++i) { + assert(i == it++->time_stamp()); + } + Cont c2(c1); + it = c2.begin(); + for (std::size_t i = 0 ; i < 10 ; ++i) { + assert(i == it++->time_stamp()); + } +} + struct Incomplete_struct; int main() @@ -298,6 +315,8 @@ int main() C3 c3; test(c3); C4 c4; test(c4); + test_time_stamps(); + // Check the time stamper policies if(! boost::is_base_of, C1::Time_stamper_impl>::value)