diff --git a/STL_Extension/include/CGAL/Handle.h b/STL_Extension/include/CGAL/Handle.h index d2c93f4ff6d..2395097dc4a 100644 --- a/STL_Extension/include/CGAL/Handle.h +++ b/STL_Extension/include/CGAL/Handle.h @@ -43,6 +43,9 @@ class Rep class Handle { public: + + typedef std::ptrdiff_t Id_type ; + Handle() : PTR(static_cast(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(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(static_cast(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 diff --git a/STL_Extension/include/CGAL/Handle_for.h b/STL_Extension/include/CGAL/Handle_for.h index f97b1ad3de1..3ea2fca597d 100644 --- a/STL_Extension/include/CGAL/Handle_for.h +++ b/STL_Extension/include/CGAL/Handle_for.h @@ -27,6 +27,7 @@ #include #include #include +#include #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(0); } + + bool identical(const Handle_for& h) const { return Ptr() == h.Ptr(); } - long int - id() const - { return reinterpret_cast(&*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 &h1, return h1.identical(h2); } -template -inline -bool -identical(const T &t1, const T &t2) -{ - return &t1 == &t2; -} +template inline bool identical(const T &t1, const T &t2) { return &t1 == &t2; } template inline diff --git a/STL_Extension/include/CGAL/Handle_for_virtual.h b/STL_Extension/include/CGAL/Handle_for_virtual.h index ad74c8e96e9..5c7d1e90773 100644 --- a/STL_Extension/include/CGAL/Handle_for_virtual.h +++ b/STL_Extension/include/CGAL/Handle_for_virtual.h @@ -27,6 +27,7 @@ #include #include +#include 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(0); } + + bool identical( const Handle_for_virtual& h) const { return Ptr() == h.Ptr(); } - long int - id() const - { return reinterpret_cast(&*ptr); } void swap(Handle_for_virtual & h) @@ -174,6 +174,9 @@ protected: RefCounted * ptr; }; +template +inline bool identical(const Handle_for_virtual &h1, const Handle_for_virtual &h2) { return h1.identical(h2); } + CGAL_END_NAMESPACE #endif // CGAL_HANDLE_FOR_VIRTUAL_H diff --git a/STL_Extension/include/CGAL/Handle_with_policy.h b/STL_Extension/include/CGAL/Handle_with_policy.h index 40d9a80ff7e..5476089351e 100644 --- a/STL_Extension/include/CGAL/Handle_with_policy.h +++ b/STL_Extension/include/CGAL/Handle_with_policy.h @@ -1126,7 +1126,8 @@ typename Handle_with_policy::Bind Handle_with_policy -unsigned long ID_Number(const Handle_with_policy& h) +typename Handle_with_policy::Id_type +ID_Number(const Handle_with_policy& h) { return h.id(); } template @@ -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(this); } + Id_type id() const { return ptr() - static_cast(0); } //! returns \c false since the representation is not shared for //! this specialization. @@ -1357,6 +1358,10 @@ public: #endif }; +template +inline bool identical(const Handle_with_policy &h1, const Handle_with_policy &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.