Fix new (recycled) time stamps when a TDS is copied

This commit is contained in:
Laurent Rineau 2017-05-09 17:47:18 +02:00
parent 0757cfaeb0
commit e294cd8fe9
3 changed files with 55 additions and 1 deletions

View File

@ -54,6 +54,34 @@
struct Bissection_tag {};
struct Polyhedral_tag {};
// Verify that the time stamps of vertices and cells are strictly
// increasing
template <typename C3t3>
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 <typename C3t3>
void verify_time_stamps(const C3t3&, CGAL::Parallel_tag) {}
template <typename K>
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
//-------------------------------------------------------

View File

@ -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);
}
}

View File

@ -19,6 +19,7 @@ template <typename Has_timestamp_ = CGAL::Tag_true>
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<C4>();
// Check the time stamper policies
if(! boost::is_base_of<CGAL::Time_stamper<T1>,
C1::Time_stamper_impl>::value)