From 75c61a687d52a50bb23b42a32f00cf463ed83d79 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Tue, 15 Apr 2014 18:00:06 +0200 Subject: [PATCH] New implementation of Has_timestamp --- .../include/CGAL/Compact_mesh_cell_base_3.h | 12 +--- .../Mesh_3/Detect_polylines_in_polyhedra.h | 2 +- Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h | 2 +- Mesh_3/include/CGAL/Mesh_cell_base_3.h | 11 +-- Mesh_3/include/CGAL/Mesh_polyhedron_3.h | 33 ++------- Mesh_3/include/CGAL/Mesh_vertex_base_3.h | 11 +-- .../include/CGAL/Compact_container.h | 68 +++++++++++-------- STL_Extension/include/CGAL/Has_timestamp.h | 19 ++++-- 8 files changed, 66 insertions(+), 92 deletions(-) diff --git a/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h b/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h index 292e7ff36f7..ad2cdd893bf 100644 --- a/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h +++ b/Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h @@ -471,6 +471,8 @@ public: } #endif // CGAL_INTRUSIVE_LIST + typedef Tag_true Has_timestamp; + std::size_t time_stamp() const { return time_stamp_; } @@ -514,16 +516,6 @@ private: }; // end class Compact_mesh_cell_base_3 -namespace internal { -namespace Mesh_3 { - template < class GT, class MT, class Cb > - struct Has_timestamp< Compact_mesh_cell_base_3 > - : public CGAL::Tag_true - {}; -} // end namespace internal::Mesh_3 -} // end namespace internal - - template < class GT, class MT, class Cb > std::istream& operator>>(std::istream &is, diff --git a/Mesh_3/include/CGAL/Mesh_3/Detect_polylines_in_polyhedra.h b/Mesh_3/include/CGAL/Mesh_3/Detect_polylines_in_polyhedra.h index 38a13d5f44b..c9d06f6466a 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Detect_polylines_in_polyhedra.h +++ b/Mesh_3/include/CGAL/Mesh_3/Detect_polylines_in_polyhedra.h @@ -59,7 +59,7 @@ struct Detect_polyline_less { typedef typename std::iterator_traits::value_type Type; typedef typename boost::mpl::if_c< - CGAL::internal::Mesh_3::Has_timestamp::value, + CGAL::internal::Has_timestamp::value, CGAL_with_time_stamp, CGAL_no_time_stamp >::type Comparator; return Comparator::less(h1, h2); diff --git a/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h b/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h index 9addeea8b91..eea76ad1eb0 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h +++ b/Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h @@ -668,7 +668,7 @@ build_priority_queue(const FT& sliver_bound, PQueue& pqueue) const int pqueue_size = 0; typedef typename std::iterator_traits::value_type Vertex; - typedef CGAL::internal::Mesh_3::Has_timestamp Vertex_has_timestamp; + typedef CGAL::internal::Has_timestamp Vertex_has_timestamp; using CGAL::internal::Mesh_3::VHash; typedef VHash Hash_fct; typedef boost::unordered_map M; diff --git a/Mesh_3/include/CGAL/Mesh_cell_base_3.h b/Mesh_3/include/CGAL/Mesh_cell_base_3.h index ad1a008a525..b828e122794 100644 --- a/Mesh_3/include/CGAL/Mesh_cell_base_3.h +++ b/Mesh_3/include/CGAL/Mesh_cell_base_3.h @@ -163,6 +163,7 @@ public: } #endif // CGAL_INTRUSIVE_LIST + typedef Tag_true Has_timestamp; std::size_t time_stamp() const { return time_stamp_; } @@ -184,16 +185,6 @@ private: }; // end class Mesh_cell_base_3 -namespace internal { -namespace Mesh_3 { - template < class GT, class MT, class Cb > - struct Has_timestamp< Mesh_cell_base_3 > - : public CGAL::Tag_true - {}; -} // end namespace internal::Mesh_3 -} // end namespace internal - - template < class GT, class MT, class Cb > std::istream& operator>>(std::istream &is, diff --git a/Mesh_3/include/CGAL/Mesh_polyhedron_3.h b/Mesh_3/include/CGAL/Mesh_polyhedron_3.h index 8b34956916a..5de46450c06 100644 --- a/Mesh_3/include/CGAL/Mesh_polyhedron_3.h +++ b/Mesh_3/include/CGAL/Mesh_polyhedron_3.h @@ -63,6 +63,8 @@ public: indices.insert(i); } + typedef Tag_true Has_timestamp; + std::size_t time_stamp() const { return time_stamp_; } @@ -101,6 +103,8 @@ public: this->opposite()->feature_edge = b; } + typedef Tag_true Has_timestamp; + std::size_t time_stamp() const { return time_stamp_; } @@ -133,6 +137,8 @@ public: patch_id_ = i; } + typedef Tag_true Has_timestamp; + std::size_t time_stamp() const { return time_stamp_; } @@ -185,33 +191,6 @@ struct Mesh_polyhedron_3 typedef type Type; }; -namespace internal { -namespace Mesh_3 { - template - struct Has_timestamp > - : public CGAL::Tag_true - {}; -} // end namespace internal::Mesh_3 -} // end namespace internal - -namespace internal { -namespace Mesh_3 { - template - struct Has_timestamp > - : public CGAL::Tag_true - {}; -} // end namespace internal::Mesh_3 -} // end namespace internal - -namespace internal { -namespace Mesh_3 { - template - struct Has_timestamp > - : public CGAL::Tag_true - {}; -} // end namespace internal::Mesh_3 -} // end namespace internal - } // end namespace CGAL #endif // CGAL_MESH_POLYHEDRON_3_H diff --git a/Mesh_3/include/CGAL/Mesh_vertex_base_3.h b/Mesh_3/include/CGAL/Mesh_vertex_base_3.h index 4a3f51aeb1e..fde46a19b5d 100644 --- a/Mesh_3/include/CGAL/Mesh_vertex_base_3.h +++ b/Mesh_3/include/CGAL/Mesh_vertex_base_3.h @@ -126,6 +126,8 @@ public: } #endif + typedef Tag_true Has_timestamp; + std::size_t time_stamp() const { return time_stamp_; } @@ -192,15 +194,6 @@ private: }; // end class Mesh_vertex_base_3 -namespace internal { -namespace Mesh_3 { - template < class GT, class MT, class Vb > - struct Has_timestamp< Mesh_vertex_base_3 > - : public CGAL::Tag_true - {}; -} // end namespace internal::Mesh_3 -} // end namespace internal - template diff --git a/STL_Extension/include/CGAL/Compact_container.h b/STL_Extension/include/CGAL/Compact_container.h index 2ee78af9c2b..8d9e02d883d 100644 --- a/STL_Extension/include/CGAL/Compact_container.h +++ b/STL_Extension/include/CGAL/Compact_container.h @@ -149,6 +149,22 @@ public: void reset() {} }; +template ::value> +struct CC_ts_impl_impl : public CGAL_time_stamper +{}; + +template +struct CC_ts_impl_impl : public CGAL_no_time_stamp +{}; + +template +struct CC_ts_impl : public CC_ts_impl_impl +{}; + template < class T, class Allocator_ = Default, class TimeStamper_ = Default > @@ -158,11 +174,7 @@ class Compact_container typedef typename Default::Get< Al, CGAL_ALLOCATOR(T) >::type Allocator; typedef TimeStamper_ Ts; - typedef typename boost::mpl::if_c< - CGAL::internal::Mesh_3::Has_timestamp::value, - CGAL_time_stamper, - CGAL_no_time_stamp >::type Time_stamper_; - typedef typename Default::Get::type Time_stamper; + typedef CC_ts_impl Time_stamper_impl; typedef Compact_container Self; typedef Compact_container_traits Traits; @@ -185,7 +197,7 @@ public: explicit Compact_container(const Allocator &a = Allocator()) : alloc(a) - , time_stamper() + , time_stamper(new Time_stamper_impl()) { init(); } @@ -194,7 +206,7 @@ public: Compact_container(InputIterator first, InputIterator last, const Allocator & a = Allocator()) : alloc(a) - , time_stamper() + , time_stamper(new Time_stamper_impl()) { init(); std::copy(first, last, CGAL::inserter(*this)); @@ -203,11 +215,11 @@ public: // The copy constructor and assignment operator preserve the iterator order Compact_container(const Compact_container &c) : alloc(c.get_allocator()) - , time_stamper() + , time_stamper(new Time_stamper_impl()) { init(); block_size = c.block_size; - time_stamper = c.time_stamper; + *time_stamper = *c.time_stamper; std::copy(c.begin(), c.end(), CGAL::inserter(*this)); } @@ -223,6 +235,7 @@ public: ~Compact_container() { clear(); + delete time_stamper; } void swap(Self &c) @@ -281,7 +294,7 @@ public: new (ret) value_type(args...); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } #else @@ -296,7 +309,7 @@ public: new (ret) value_type(); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -312,7 +325,7 @@ public: new (ret) value_type(t1); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -328,7 +341,7 @@ public: new (ret) value_type(t1, t2); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -344,7 +357,7 @@ public: new (ret) value_type(t1, t2, t3); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -360,7 +373,7 @@ public: new (ret) value_type(t1, t2, t3, t4); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -377,7 +390,7 @@ public: new (ret) value_type(t1, t2, t3, t4, t5); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -395,7 +408,7 @@ public: new (ret) value_type(t1, t2, t3, t4, t5, t6); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -413,7 +426,7 @@ public: new (ret) value_type(t1, t2, t3, t4, t5, t6, t7); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -431,7 +444,7 @@ public: new (ret) value_type(t1, t2, t3, t4, t5, t6, t7, t8); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } #endif // CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES @@ -446,7 +459,7 @@ public: alloc.construct(ret, t); CGAL_assertion(type(ret) == USED); ++size_; - time_stamper.set_time_stamp(ret); + time_stamper->set_time_stamp(ret); return iterator(ret, 0); } @@ -637,7 +650,7 @@ private: first_item = NULL; last_item = NULL; all_items = All_items(); - time_stamper.reset(); + time_stamper->reset(); } allocator_type alloc; @@ -648,7 +661,7 @@ private: pointer first_item; pointer last_item; All_items all_items; - Time_stamper time_stamper; + Time_stamper_impl* time_stamper; }; template < class T, class Allocator, class TimeStamper> @@ -794,7 +807,6 @@ namespace internal { typedef typename DSC::value_type value_type; typedef typename DSC::size_type size_type; typedef typename DSC::difference_type difference_type; - typedef typename DSC::Time_stamper TimeStamper; typedef typename boost::mpl::if_c< Const, const value_type*, value_type*>::type pointer; typedef typename boost::mpl::if_c< Const, const value_type&, @@ -830,6 +842,8 @@ namespace internal { private: + typedef typename DSC::Time_stamper_impl Time_stamper_impl; + union { pointer p; void *vp; @@ -932,23 +946,23 @@ namespace internal { // For std::less... bool operator<(const CC_iterator& other) const { - return TimeStamper::less(m_ptr.p, other.m_ptr.p); + return Time_stamper_impl::less(m_ptr.p, other.m_ptr.p); } bool operator>(const CC_iterator& other) const { - return TimeStamper::less(other.m_ptr.p, m_ptr.p); + return Time_stamper_impl::less(other.m_ptr.p, m_ptr.p); } bool operator<=(const CC_iterator& other) const { - return TimeStamper::less(m_ptr.p, other.m_ptr.p) + return Time_stamper_impl::less(m_ptr.p, other.m_ptr.p) || (*this == other); } bool operator>=(const CC_iterator& other) const { - return TimeStamper::less(other.m_ptr.p, m_ptr.p) + return Time_stamper_impl::less(other.m_ptr.p, m_ptr.p) || (*this == other); } diff --git a/STL_Extension/include/CGAL/Has_timestamp.h b/STL_Extension/include/CGAL/Has_timestamp.h index eaef0ae56ce..7403b32cecf 100644 --- a/STL_Extension/include/CGAL/Has_timestamp.h +++ b/STL_Extension/include/CGAL/Has_timestamp.h @@ -17,8 +17,8 @@ // // Author(s) : Jane Tournois -#ifndef CGAL_MESH_3_HAS_TIMESTAMP_H -#define CGAL_MESH_3_HAS_TIMESTAMP_H +#ifndef CGAL_HAS_TIMESTAMP_H +#define CGAL_HAS_TIMESTAMP_H #include #include @@ -26,18 +26,23 @@ namespace CGAL { namespace internal { -namespace Mesh_3 { + + BOOST_MPL_HAS_XXX_TRAIT_DEF(Has_timestamp) // to have Mesh_3 deterministic, // a partial specialization of this class should be written next to // every class that implements concepts MeshCellBase_3 or MeshVertexBase_3 - template - struct Has_timestamp : public CGAL::Tag_false + template ::value> + struct Has_timestamp : public T::Has_timestamp + // when T does not have a partial specialization of Has_timestamp + {}; + + template + struct Has_timestamp : public Tag_false // when T does not have a partial specialization of Has_timestamp {}; -} // end namespace internal::Mesh_3 } // end namespace internal } // end namespace CGAL -#endif // CGAL_MESH_3_HAS_TIMESTAMP_H +#endif // CGAL_HAS_TIMESTAMP_H