add a "less" function to CGAL_time_stamper

and handle null pointers given to comparison
it is necessary for example in Triangulation_3::remove_3D
This commit is contained in:
Jane Tournois 2014-02-21 14:41:41 +01:00
parent fc8a81f344
commit 9d19ac0f96
1 changed files with 16 additions and 6 deletions

View File

@ -123,7 +123,12 @@ public:
: time_stamp_(ts.time_stamp_) {}
void set_time_stamp(T* pt) { pt->set_time_stamp(time_stamp_++); }
static std::size_t get(T* pt) { return pt->time_stamp(); }
static bool less(T* p_t1, T* p_t2)
{
if(p_t1 == NULL) return (p_t2 != NULL);
else if(p_t2 == NULL) return false;
else return p_t1->time_stamp() < p_t2->time_stamp();
}
void reset() { time_stamp_ = 0; }
private:
@ -136,7 +141,10 @@ struct CGAL_no_time_stamp
public:
CGAL_no_time_stamp() {}
void set_time_stamp(T* pt) {}
static T* get(T* pt) { return pt; }
static bool less(T* p_t1, T* p_t2)
{
return p_t1 < p_t2;
}
void reset() {}
};
@ -923,22 +931,24 @@ namespace internal {
// For std::less...
bool operator<(const CC_iterator& other) const
{
return TimeStamper::get(m_ptr.p) < TimeStamper::get(other.m_ptr.p);
return TimeStamper::less(m_ptr.p, other.m_ptr.p);
}
bool operator>(const CC_iterator& other) const
{
return TimeStamper::get(m_ptr.p) > TimeStamper::get(other.m_ptr.p);
return TimeStamper::less(other.m_ptr.p, m_ptr.p);
}
bool operator<=(const CC_iterator& other) const
{
return TimeStamper::get(m_ptr.p) <= TimeStamper::get(other.m_ptr.p);
return TimeStamper::less(m_ptr.p, other.m_ptr.p)
|| (*this == other);
}
bool operator>=(const CC_iterator& other) const
{
return TimeStamper::get(m_ptr.p) >= TimeStamper::get(other.m_ptr.p);
return TimeStamper::less(other.m_ptr.p, m_ptr.p)
|| (*this == other);
}
// Can itself be used for bit-squatting.