Fixed id() and identical() so they don't cast to 'long'

This commit is contained in:
Fernando Cacciola 2010-03-25 13:17:21 +00:00
parent a564b970be
commit a12e6dc61c
4 changed files with 31 additions and 31 deletions

View File

@ -43,6 +43,9 @@ class Rep
class Handle
{
public:
typedef std::ptrdiff_t Id_type ;
Handle()
: PTR(static_cast<Rep*>(0)) {}
@ -73,22 +76,17 @@ class Handle
int
refs() const { return PTR->count; }
friend std::ptrdiff_t id(const Handle& x);
friend bool identical(const Handle& h1, const Handle& h2);
Id_type id() const { return PTR - static_cast<Rep*>(0); }
bool identical(const Handle& h) const { return PTR == h.PTR; }
protected:
Rep* PTR;
};
inline
std::ptrdiff_t
id(const Handle& x)
{ return x.PTR - static_cast<Rep*>(static_cast<void*>(0)); }
//inline Handle::Id_type id(const Handle& x) { return x.id() ; }
inline
bool
identical(const Handle &h1, const Handle &h2)
{ return h1.PTR == h2.PTR; }
inline bool identical(const Handle &h1, const Handle &h2) { return h1.identical(h2); }
CGAL_END_NAMESPACE

View File

@ -27,6 +27,7 @@
#include <boost/config.hpp>
#include <CGAL/memory.h>
#include <algorithm>
#include <cstddef>
#if defined(BOOST_MSVC)
# pragma warning(push)
@ -52,6 +53,8 @@ class Handle_for
public:
typedef T element_type;
typedef std::ptrdiff_t Id_type ;
Handle_for()
: ptr_(allocator.allocate(1))
@ -186,13 +189,10 @@ public:
*this = t;
}
bool
identical(const Handle_for& h) const
{ return ptr_ == h.ptr_; }
Id_type id() const { return Ptr() - static_cast<T const*>(0); }
bool identical(const Handle_for& h) const { return Ptr() == h.Ptr(); }
long int
id() const
{ return reinterpret_cast<long int>(&*ptr_); }
// Ptr() is the "public" access to the pointer to the object.
// The non-const version asserts that the instance is not shared.
@ -284,13 +284,7 @@ identical(const Handle_for<T, Allocator> &h1,
return h1.identical(h2);
}
template <class T>
inline
bool
identical(const T &t1, const T &t2)
{
return &t1 == &t2;
}
template <class T> inline bool identical(const T &t1, const T &t2) { return &t1 == &t2; }
template <class T, class Allocator>
inline

View File

@ -27,6 +27,7 @@
#include <CGAL/basic.h>
#include <typeinfo>
#include <cstddef>
CGAL_BEGIN_NAMESPACE
@ -65,6 +66,8 @@ class Handle_for_virtual
{
public:
typedef std::ptrdiff_t Id_type ;
Handle_for_virtual(const RefCounted& rc)
{
ptr = new RefCounted(rc);
@ -118,13 +121,10 @@ class Handle_for_virtual
ptr = new T(rc);
}
bool
identical( const Handle_for_virtual& h) const
{ return ptr == h.ptr; }
Id_type id() const { return Ptr() - static_cast<RefCounted const*>(0); }
bool identical( const Handle_for_virtual& h) const { return Ptr() == h.Ptr(); }
long int
id() const
{ return reinterpret_cast<long int>(&*ptr); }
void
swap(Handle_for_virtual & h)
@ -174,6 +174,9 @@ protected:
RefCounted * ptr;
};
template <class RefCounted>
inline bool identical(const Handle_for_virtual<RefCounted> &h1, const Handle_for_virtual<RefCounted> &h2) { return h1.identical(h2); }
CGAL_END_NAMESPACE
#endif // CGAL_HANDLE_FOR_VIRTUAL_H

View File

@ -1126,7 +1126,8 @@ typename Handle_with_policy<T,Policy,Alloc>::Bind Handle_with_policy<T,Policy,Al
* ID numbers have to be fixed throughout an object's lifetime.
*/
template <class T, class A>
unsigned long ID_Number(const Handle_with_policy<T, Handle_policy_no_union, A>& h)
typename Handle_with_policy<T, Handle_policy_no_union, A>::Id_type
ID_Number(const Handle_with_policy<T, Handle_policy_no_union, A>& h)
{ return h.id(); }
template <class T, class Policy, class Alloc>
@ -1329,7 +1330,7 @@ public:
//! returns a unique id value. Two handles share their representation
//! is their id values are identical.
Id_type id() const { return reinterpret_cast<Id_type>(this); }
Id_type id() const { return ptr() - static_cast<T const*>(0); }
//! returns \c false since the representation is not shared for
//! this specialization.
@ -1357,6 +1358,10 @@ public:
#endif
};
template <class T, class HandlePolicy, class Allocator>
inline bool identical(const Handle_with_policy<T,HandlePolicy,Allocator> &h1, const Handle_with_policy<T,HandlePolicy,Allocator> &h2) { return h1.is_identical(h2); }
/*\brief
* This class' function call operator test whether one handle's \c id is
* less than the \c id of the other handle.