Change the API of `for_compact_container`/`Compact_container_traits`

Now, we have a proper pair of getter/setter, and the `void` pointer is
get by a `reinterpret_cast`, instead of a union.

Cc: @mglisse
This commit is contained in:
Laurent Rineau 2020-03-06 16:42:23 +01:00
parent e3d7f7946d
commit 378554e5a7
29 changed files with 96 additions and 100 deletions

View File

@ -197,8 +197,8 @@ namespace CGAL {
void * for_compact_container() const
{ return vp; }
void * & for_compact_container()
{ return vp; }
void for_compact_container(void *p)
{ vp = p; }
private:
/// Reference counting: the number of darts linked to this cell.
@ -310,8 +310,8 @@ namespace CGAL {
void * for_compact_container() const
{ return mdart.for_compact_container(); }
void * & for_compact_container()
{ return mdart.for_compact_container(); }
void for_compact_container(void *p)
{ mdart.for_compact_container(p); }
private:
/// The dart handle associated with the cell.

View File

@ -105,8 +105,8 @@ namespace CGAL {
void * for_compact_container() const
{ return mf[0].for_compact_container(); }
void * & for_compact_container()
{ return mf[0].for_compact_container(); }
void for_compact_container(void *p)
{ mf[0].for_compact_container(p); }
Dart_handle get_f(unsigned int i) const
{

View File

@ -87,7 +87,7 @@ public:
void* pp;
void* for_compact_container() const { return pp; }
void* & for_compact_container() { return pp; }
void for_compact_container(void *p) { pp = p; }
#ifdef CGAL_USE_LEDA
LEDA_MEMORY(RC_vertex_d)
@ -153,7 +153,7 @@ public:
void* pp;
void* for_compact_container() const { return pp; }
void* & for_compact_container() { return pp; }
void for_compact_container(void *p) { pp = p; }
#if 0
struct Point_const_iterator {

View File

@ -115,7 +115,7 @@ class Interval_for_container : public Interval_
{}
void * for_compact_container() const { return p; }
void * & for_compact_container() { return p; }
void for_compact_container(void *ptr) { p = ptr; }
};
@ -457,7 +457,7 @@ class Interval_for_container : public Interval_
public:
#ifdef CGAL_ISL_USE_CCC
void * for_compact_container() const { return p; }
void * & for_compact_container() { return p; }
void for_compact_container(void *ptr) { p = ptr; }
#endif
bool operator==(const IntervalListElt& e)

View File

@ -491,7 +491,7 @@ public:
// For use by Compact_container.
void * for_compact_container() const { return N[0].for_compact_container(); }
void * & for_compact_container() { return N[0].for_compact_container(); }
void for_compact_container(void *p) { N[0].for_compact_container(p); }
// TDS internal data access functions.
TDS_data& tds_data() { return _tds_data; }

View File

@ -233,7 +233,7 @@ public:
// For use by Compact_container.
void * for_compact_container() const { return N[0].for_compact_container(); }
void * & for_compact_container() { return N[0].for_compact_container(); }
void for_compact_container(void *p) { N[0].for_compact_container(p); }
// TDS internal data access functions.
TDS_data& tds_data() { return _tds_data; }

View File

@ -80,8 +80,8 @@ public:
// For use by the Compact_container.
void * for_compact_container() const
{ return _c.for_compact_container(); }
void * & for_compact_container()
{ return _c.for_compact_container(); }
void for_compact_container(void *p)
{ _c.for_compact_container(p); }
private:
Cell_handle _c;

View File

@ -26,7 +26,7 @@ struct Truc
{
Truc(int v = 0) : value(v), /*value2(v), */p(NULL) {}
void * for_compact_container() const { return p; }
void * & for_compact_container() { return p; }
void for_compact_container(void *ptr) { p = ptr; }
int value;
int value2;

View File

@ -30,10 +30,9 @@ Returns the pointer necessary for `Compact_container_traits<T>`.
void * for_compact_container() const;
/*!
Returns a reference to the pointer necessary for
`Compact_container_traits<T>`.
Sets the pointer necessary for `Compact_container_traits<T>` to `p`.
*/
void * & for_compact_container();
void for_compact_container(void* p);
/// @}
@ -796,7 +795,7 @@ types `T` to make them usable with the default `Compact_container_traits`.
`void * t.for_compact_container() const;`
`void *& t.for_compact_container();`.
`void t.for_compact_container(void *);`.
*/
@ -820,11 +819,11 @@ static void * pointer(const T &t);
/// \name Operations
/// @{
/*!
Returns a reference to the pointer held by `t`.
The template version defines this function as: `return t.for_compact_container();`
Sets the pointer held by `t` to `p`.
The template version defines this function as: `t.for_compact_container(p);`
*/
static void * & pointer(T &t);
static void set_pointer(T &t, void* p);

View File

@ -22,7 +22,7 @@ types `T` to make them usable with the default `Concurrent_compact_container`.
`T` is any type providing the following member functions:
`void * t.for_compact_container() const;`
`void *& t.for_compact_container();`.
`void t.for_compact_container(void *);`.
*/
template< typename T >
struct Concurrent_compact_container_traits {
@ -40,11 +40,11 @@ struct Concurrent_compact_container_traits {
/// \name Operations
/// @{
/*!
Returns a reference to the pointer held by `t`.
The template version defines this function as: `return t.for_compact_container();`
Sets the pointer held by `t` to `p`.
The template version defines this function as: `t.for_compact_container(p);`
*/
static void * & pointer(T &t);
static void set_pointer(T &t, void* p);
/// @}

View File

@ -149,15 +149,15 @@ public:
Compact_container_base()
: p(nullptr) {}
void * for_compact_container() const { return p; }
void * & for_compact_container() { return p; }
void for_compact_container(void* ptr) { p = ptr; }
};
// The traits class describes the way to access the pointer.
// It can be specialized.
template < class T >
struct Compact_container_traits {
static void * pointer(const T &t) { return t.for_compact_container(); }
static void * & pointer(T &t) { return t.for_compact_container(); }
static void * pointer(const T &t) { return t.for_compact_container(); }
static void set_pointer(T &t, void* p) { t.for_compact_container(p); }
};
namespace internal {
@ -645,8 +645,8 @@ private:
// This out of range compare is always true and causes lots of
// unnecessary warnings.
// CGAL_precondition(0 <= t && t < 4);
Traits::pointer(*ptr) = reinterpret_cast<void *>
(reinterpret_cast<std::ptrdiff_t>(clean_pointer((char *) p)) + (int) t);
Traits::set_pointer(*ptr, reinterpret_cast<void *>
(reinterpret_cast<std::ptrdiff_t>(clean_pointer((char *) p)) + (int) t));
}
public:
@ -872,7 +872,7 @@ namespace internal {
: ts(0)
#endif
{
m_ptr.p = nullptr;
m_ptr = nullptr;
}
CC_iterator (const CC_iterator &it)
@ -880,7 +880,7 @@ namespace internal {
: ts(Time_stamper::time_stamp(it.operator->()))
#endif
{
m_ptr.p = it.operator->();
m_ptr = it.operator->();
}
// Converting constructor from mutable to constant iterator
@ -892,7 +892,7 @@ namespace internal {
: ts(Time_stamper::time_stamp(const_it.operator->()))
#endif
{
m_ptr.p = const_it.operator->();
m_ptr = const_it.operator->();
}
// Assignment operator from mutable to constant iterator
@ -901,7 +901,7 @@ namespace internal {
typename std::enable_if<(!OtherConst && Const), DSC>::type,
OtherConst> &const_it)
{
m_ptr.p = const_it.operator->();
m_ptr = const_it.operator->();
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
ts = Time_stamper::time_stamp(const_it.operator->());
#endif
@ -920,7 +920,7 @@ namespace internal {
#endif
{
CGAL_assertion (n == nullptr);
m_ptr.p = nullptr;
m_ptr = nullptr;
}
private:
@ -929,10 +929,7 @@ namespace internal {
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
std::size_t ts;
#endif
union {
pointer p;
void *vp;
} m_ptr;
pointer m_ptr;
// Only Compact_container and Concurrent_compact_container should
// access these constructors.
@ -948,16 +945,16 @@ namespace internal {
: ts(0)
#endif
{
m_ptr.p = ptr;
if (m_ptr.p == nullptr) // empty container.
m_ptr = ptr;
if (m_ptr == nullptr) // empty container.
return;
++(m_ptr.p); // if not empty, p = start
if (DSC::type(m_ptr.p) == DSC::FREE)
++(m_ptr); // if not empty, p = start
if (DSC::type(m_ptr) == DSC::FREE)
increment();
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
else
ts = Time_stamper::time_stamp(m_ptr.p);
ts = Time_stamper::time_stamp(m_ptr);
#endif // CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
}
@ -967,10 +964,10 @@ namespace internal {
: ts(0)
#endif
{
m_ptr.p = ptr;
m_ptr = ptr;
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
if(ptr != nullptr){
ts = Time_stamper::time_stamp(m_ptr.p);
ts = Time_stamper::time_stamp(m_ptr);
}
#endif // end CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
}
@ -979,49 +976,49 @@ namespace internal {
void increment()
{
// It's either pointing to end(), or valid.
CGAL_assertion_msg(m_ptr.p != nullptr,
CGAL_assertion_msg(m_ptr != nullptr,
"Incrementing a singular iterator or an empty container iterator ?");
CGAL_assertion_msg(DSC::type(m_ptr.p) != DSC::START_END,
CGAL_assertion_msg(DSC::type(m_ptr) != DSC::START_END,
"Incrementing end() ?");
// If it's not end(), then it's valid, we can do ++.
do {
++(m_ptr.p);
if (DSC::type(m_ptr.p) == DSC::USED ||
DSC::type(m_ptr.p) == DSC::START_END)
++(m_ptr);
if (DSC::type(m_ptr) == DSC::USED ||
DSC::type(m_ptr) == DSC::START_END)
{
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
ts = Time_stamper::time_stamp(m_ptr.p);
ts = Time_stamper::time_stamp(m_ptr);
#endif
return;
}
if (DSC::type(m_ptr.p) == DSC::BLOCK_BOUNDARY)
m_ptr.p = DSC::clean_pointee(m_ptr.p);
if (DSC::type(m_ptr) == DSC::BLOCK_BOUNDARY)
m_ptr = DSC::clean_pointee(m_ptr);
} while (true);
}
void decrement()
{
// It's either pointing to end(), or valid.
CGAL_assertion_msg(m_ptr.p != nullptr,
CGAL_assertion_msg(m_ptr != nullptr,
"Decrementing a singular iterator or an empty container iterator ?");
CGAL_assertion_msg(DSC::type(m_ptr.p - 1) != DSC::START_END,
CGAL_assertion_msg(DSC::type(m_ptr - 1) != DSC::START_END,
"Decrementing begin() ?");
// If it's not begin(), then it's valid, we can do --.
do {
--m_ptr.p;
if (DSC::type(m_ptr.p) == DSC::USED ||
DSC::type(m_ptr.p) == DSC::START_END)
--m_ptr;
if (DSC::type(m_ptr) == DSC::USED ||
DSC::type(m_ptr) == DSC::START_END)
{
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
ts = Time_stamper::time_stamp(m_ptr.p);
ts = Time_stamper::time_stamp(m_ptr);
#endif
return;
}
if (DSC::type(m_ptr.p) == DSC::BLOCK_BOUNDARY)
m_ptr.p = DSC::clean_pointee(m_ptr.p);
if (DSC::type(m_ptr) == DSC::BLOCK_BOUNDARY)
m_ptr = DSC::clean_pointee(m_ptr);
} while (true);
}
@ -1029,9 +1026,9 @@ namespace internal {
Self & operator++()
{
CGAL_assertion_msg(m_ptr.p != nullptr,
CGAL_assertion_msg(m_ptr != nullptr,
"Incrementing a singular iterator or an empty container iterator ?");
/* CGAL_assertion_msg(DSC::type(m_ptr.p) == DSC::USED,
/* CGAL_assertion_msg(DSC::type(m_ptr) == DSC::USED,
"Incrementing an invalid iterator."); */
increment();
return *this;
@ -1039,10 +1036,10 @@ namespace internal {
Self & operator--()
{
CGAL_assertion_msg(m_ptr.p != nullptr,
CGAL_assertion_msg(m_ptr != nullptr,
"Decrementing a singular iterator or an empty container iterator ?");
/*CGAL_assertion_msg(DSC::type(m_ptr.p) == DSC::USED
|| DSC::type(m_ptr.p) == DSC::START_END,
/*CGAL_assertion_msg(DSC::type(m_ptr) == DSC::USED
|| DSC::type(m_ptr) == DSC::START_END,
"Decrementing an invalid iterator.");*/
decrement();
return *this;
@ -1054,13 +1051,13 @@ namespace internal {
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
bool is_time_stamp_valid() const
{
return (ts == 0) || (ts == Time_stamper::time_stamp(m_ptr.p));
return (ts == 0) || (ts == Time_stamper::time_stamp(m_ptr));
}
#endif // CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
reference operator*() const { return *(m_ptr.p); }
reference operator*() const { return *(m_ptr); }
pointer operator->() const { return (m_ptr.p); }
pointer operator->() const { return (m_ptr); }
// For std::less...
bool operator<(const CC_iterator& other) const
@ -1068,7 +1065,7 @@ namespace internal {
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
assert( is_time_stamp_valid() );
#endif
return Time_stamper::less(m_ptr.p, other.m_ptr.p);
return Time_stamper::less(m_ptr, other.m_ptr);
}
bool operator>(const CC_iterator& other) const
@ -1076,7 +1073,7 @@ namespace internal {
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
assert( is_time_stamp_valid() );
#endif
return Time_stamper::less(other.m_ptr.p, m_ptr.p);
return Time_stamper::less(other.m_ptr, m_ptr);
}
bool operator<=(const CC_iterator& other) const
@ -1084,7 +1081,7 @@ namespace internal {
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
assert( is_time_stamp_valid() );
#endif
return Time_stamper::less(m_ptr.p, other.m_ptr.p)
return Time_stamper::less(m_ptr, other.m_ptr)
|| (*this == other);
}
@ -1093,13 +1090,13 @@ namespace internal {
#ifdef CGAL_COMPACT_CONTAINER_DEBUG_TIME_STAMP
assert( is_time_stamp_valid() );
#endif
return Time_stamper::less(other.m_ptr.p, m_ptr.p)
return Time_stamper::less(other.m_ptr, m_ptr)
|| (*this == other);
}
// Can itself be used for bit-squatting.
void * for_compact_container() const { return (m_ptr.vp); }
void * & for_compact_container() { return (m_ptr.vp); }
void * for_compact_container() const { return m_ptr; }
void for_compact_container(void* p) { m_ptr = static_cast<pointer>(p); }
};
template < class DSC, bool Const1, bool Const2 >

View File

@ -66,7 +66,7 @@ template<typename T> class has_##X { \
template < class T >
struct Concurrent_compact_container_traits {
static void * pointer(const T &t) { return t.for_compact_container(); }
static void * & pointer(T &t) { return t.for_compact_container(); }
static void set_pointer(T &t, void* p) { t.for_compact_container(p); }
};
namespace CCC_internal {
@ -613,8 +613,8 @@ private:
// This out of range compare is always true and causes lots of
// unnecessary warnings.
// CGAL_precondition(0 <= t && t < 4);
Traits::pointer(*ptr) = reinterpret_cast<void *>
(reinterpret_cast<std::ptrdiff_t>(clean_pointer((char *) p)) + (int) t);
Traits::set_pointer(*ptr, reinterpret_cast<void *>
(reinterpret_cast<std::ptrdiff_t>(clean_pointer((char *) p)) + (int) t));
}
typedef tbb::queuing_mutex Mutex;

View File

@ -72,7 +72,7 @@ public:
bool operator< (const Node_2 &n) const { return rnd < n.rnd; }
void * for_compact_container() const { return p_cc; }
void * & for_compact_container() { return p_cc; }
void for_compact_container(void *p) { p_cc = p; }
};
template < class Cont >

View File

@ -15,7 +15,7 @@ public:
{}
void * for_compact_container() const { return p_cc; }
void * & for_compact_container() { return p_cc; }
void for_compact_container(void *p) { p_cc = p; }
};
int main()

View File

@ -67,7 +67,7 @@ public:
bool operator< (const Node_2 &n) const { return rnd < n.rnd; }
void * for_compact_container() const { return p_cc; }
void * & for_compact_container() { return p_cc; }
void for_compact_container(void *p) { p_cc = p; }
};
template < class Cont >

View File

@ -183,7 +183,7 @@ void * for_compact_container() const;
/*!
*/
void * & for_compact_container();
void for_compact_container(void *p);
/// @}

View File

@ -118,7 +118,7 @@ void * for_compact_container() const;
/*!
*/
void * & for_compact_container();
void for_compact_container(void* p);
/// @}

View File

@ -79,7 +79,7 @@ public:
// For use by Compact_container.
void * for_compact_container() const {return N[0].for_compact_container(); }
void * & for_compact_container() { return N[0].for_compact_container();}
void for_compact_container(void* p) { N[0].for_compact_container(p);}
static int ccw(int i) {return Triangulation_cw_ccw_2::ccw(i);}

View File

@ -49,7 +49,7 @@ public:
// For use by the Compact_container.
void * for_compact_container() const { return _f.for_compact_container(); }
void * & for_compact_container() { return _f.for_compact_container(); }
void for_compact_container(void* p) { _f.for_compact_container(p); }
private:
Face_handle _f;

View File

@ -136,7 +136,7 @@ void * for_compact_container() const;
/*!
*/
void * & for_compact_container();
void for_compact_container(void *p);
/// @}

View File

@ -116,7 +116,7 @@ void * for_compact_container() const;
/*!
*/
void * & for_compact_container();
void for_compact_container(void *);
/*!
Inputs the non-combinatorial information given by the vertex.

View File

@ -180,7 +180,7 @@ public:
// For use by Compact_container.
void * for_compact_container() const { return N[0].for_compact_container(); }
void * & for_compact_container() { return N[0].for_compact_container(); }
void for_compact_container(void* p) { N[0].for_compact_container(p); }
// TDS internal data access functions.
TDS_data& tds_data() { return _tds_data; }

View File

@ -59,8 +59,8 @@ public:
// For use by the Compact_container.
void * for_compact_container() const
{ return _c.for_compact_container(); }
void * & for_compact_container()
{ return _c.for_compact_container(); }
void for_compact_container(void* p)
{ _c.for_compact_container(p); }
private:
Cell_handle _c;

View File

@ -107,7 +107,7 @@ void * for_compact_container() const;
/*!
*/
void * & for_compact_container();
void for_compact_container(void *p);
/// @}

View File

@ -106,7 +106,7 @@ void * for_compact_container() const;
/*!
*/
void * & for_compact_container();
void for_compact_container(void *p);
/// @}

View File

@ -44,7 +44,7 @@ struct TFC_data< Vertex_handle, Full_cell_handle, Dimen, TDS_full_cell_default_s
: vertices_(dmax+1), neighbors_(dmax+1)
{}
void* for_compact_container() const { return vertices_.for_compact_container(); }
void* & for_compact_container() { return vertices_.for_compact_container(); }
void for_compact_container(void *p){ vertices_.for_compact_container(p); }
int dimension() const { return ( vertices_.size() - 1 ); }
void set_mirror_index(const int, const int) {}
#ifdef BOOST_NO_INT64_T

View File

@ -204,7 +204,7 @@ public:
TDS_data & tds_data() { return tds_data_; } /* Concept */
void* for_compact_container() const { return combinatorics_.for_compact_container(); }
void* & for_compact_container() { return combinatorics_.for_compact_container(); }
void for_compact_container(void* p){ combinatorics_.for_compact_container(p); }
bool is_valid(bool verbose = false, int = 0) const /* Concept */
{

View File

@ -102,7 +102,7 @@ public:
public: // FOR MEMORY MANAGEMENT
void* for_compact_container() const { return full_cell_.for_compact_container(); }
void* & for_compact_container() { return full_cell_.for_compact_container(); }
void for_compact_container(void *p){ full_cell_.for_compact_container(p); }
}; // end of Triangulation_ds_vertex

View File

@ -66,9 +66,9 @@ struct S_or_D_array< Containee, Dimension_tag< D >, WithCompactContainerHelper >
{
return (*this)[0].for_compact_container();
}
void* & for_compact_container()
void for_compact_container(void *p)
{
return (*this)[0].for_compact_container();
(*this)[0].for_compact_container(p);
}
};
@ -101,7 +101,7 @@ struct S_or_D_array< Containee, Dynamic_dimension_tag, true >
{}
void* fcc_;
void* for_compact_container() const { return fcc_; }
void* & for_compact_container() { return fcc_; }
void for_compact_container(void* p) { fcc_ = p; }
};
} // end of namespace internal