New implementation of Has_timestamp

This commit is contained in:
Laurent Rineau 2014-04-15 18:00:06 +02:00
parent f8a97dc424
commit 75c61a687d
8 changed files with 66 additions and 92 deletions

View File

@ -471,6 +471,8 @@ public:
} }
#endif // CGAL_INTRUSIVE_LIST #endif // CGAL_INTRUSIVE_LIST
typedef Tag_true Has_timestamp;
std::size_t time_stamp() const { std::size_t time_stamp() const {
return time_stamp_; return time_stamp_;
} }
@ -514,16 +516,6 @@ private:
}; // end class Compact_mesh_cell_base_3 }; // 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<GT, MT, Cb> >
: public CGAL::Tag_true
{};
} // end namespace internal::Mesh_3
} // end namespace internal
template < class GT, class MT, class Cb > template < class GT, class MT, class Cb >
std::istream& std::istream&
operator>>(std::istream &is, operator>>(std::istream &is,

View File

@ -59,7 +59,7 @@ struct Detect_polyline_less
{ {
typedef typename std::iterator_traits<Handle>::value_type Type; typedef typename std::iterator_traits<Handle>::value_type Type;
typedef typename boost::mpl::if_c< typedef typename boost::mpl::if_c<
CGAL::internal::Mesh_3::Has_timestamp<Type>::value, CGAL::internal::Has_timestamp<Type>::value,
CGAL_with_time_stamp<Handle>, CGAL_with_time_stamp<Handle>,
CGAL_no_time_stamp<Handle> >::type Comparator; CGAL_no_time_stamp<Handle> >::type Comparator;
return Comparator::less(h1, h2); return Comparator::less(h1, h2);

View File

@ -668,7 +668,7 @@ build_priority_queue(const FT& sliver_bound, PQueue& pqueue) const
int pqueue_size = 0; int pqueue_size = 0;
typedef typename std::iterator_traits<Vertex_handle>::value_type Vertex; typedef typename std::iterator_traits<Vertex_handle>::value_type Vertex;
typedef CGAL::internal::Mesh_3::Has_timestamp<Vertex> Vertex_has_timestamp; typedef CGAL::internal::Has_timestamp<Vertex> Vertex_has_timestamp;
using CGAL::internal::Mesh_3::VHash; using CGAL::internal::Mesh_3::VHash;
typedef VHash<Tr, Vertex_has_timestamp::value> Hash_fct; typedef VHash<Tr, Vertex_has_timestamp::value> Hash_fct;
typedef boost::unordered_map<Vertex_handle,PVertex,Hash_fct> M; typedef boost::unordered_map<Vertex_handle,PVertex,Hash_fct> M;

View File

@ -163,6 +163,7 @@ public:
} }
#endif // CGAL_INTRUSIVE_LIST #endif // CGAL_INTRUSIVE_LIST
typedef Tag_true Has_timestamp;
std::size_t time_stamp() const { std::size_t time_stamp() const {
return time_stamp_; return time_stamp_;
} }
@ -184,16 +185,6 @@ private:
}; // end class Mesh_cell_base_3 }; // 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<GT, MT, Cb> >
: public CGAL::Tag_true
{};
} // end namespace internal::Mesh_3
} // end namespace internal
template < class GT, class MT, class Cb > template < class GT, class MT, class Cb >
std::istream& std::istream&
operator>>(std::istream &is, operator>>(std::istream &is,

View File

@ -63,6 +63,8 @@ public:
indices.insert(i); indices.insert(i);
} }
typedef Tag_true Has_timestamp;
std::size_t time_stamp() const { std::size_t time_stamp() const {
return time_stamp_; return time_stamp_;
} }
@ -101,6 +103,8 @@ public:
this->opposite()->feature_edge = b; this->opposite()->feature_edge = b;
} }
typedef Tag_true Has_timestamp;
std::size_t time_stamp() const { std::size_t time_stamp() const {
return time_stamp_; return time_stamp_;
} }
@ -133,6 +137,8 @@ public:
patch_id_ = i; patch_id_ = i;
} }
typedef Tag_true Has_timestamp;
std::size_t time_stamp() const { std::size_t time_stamp() const {
return time_stamp_; return time_stamp_;
} }
@ -185,33 +191,6 @@ struct Mesh_polyhedron_3
typedef type Type; typedef type Type;
}; };
namespace internal {
namespace Mesh_3 {
template <typename Refs, typename Tag, typename Pt, typename P_id>
struct Has_timestamp<CGAL::Mesh_3::Mesh_polyhedron_vertex<Refs, Tag, Pt, P_id> >
: public CGAL::Tag_true
{};
} // end namespace internal::Mesh_3
} // end namespace internal
namespace internal {
namespace Mesh_3 {
template <class Refs, class Tprev, class Tv, class Tf>
struct Has_timestamp<CGAL::Mesh_3::Mesh_polyhedron_halfedge<Refs, Tprev, Tv, Tf> >
: public CGAL::Tag_true
{};
} // end namespace internal::Mesh_3
} // end namespace internal
namespace internal {
namespace Mesh_3 {
template <class Refs, class T_, class Pln_, class Pid_>
struct Has_timestamp<CGAL::Mesh_3::Mesh_polyhedron_face<Refs, T_, Pln_, Pid_> >
: public CGAL::Tag_true
{};
} // end namespace internal::Mesh_3
} // end namespace internal
} // end namespace CGAL } // end namespace CGAL
#endif // CGAL_MESH_POLYHEDRON_3_H #endif // CGAL_MESH_POLYHEDRON_3_H

View File

@ -126,6 +126,8 @@ public:
} }
#endif #endif
typedef Tag_true Has_timestamp;
std::size_t time_stamp() const { std::size_t time_stamp() const {
return time_stamp_; return time_stamp_;
} }
@ -192,15 +194,6 @@ private:
}; // end class Mesh_vertex_base_3 }; // 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<GT, MT, Vb> >
: public CGAL::Tag_true
{};
} // end namespace internal::Mesh_3
} // end namespace internal
template<class GT, template<class GT,
class MD, class MD,
class Vb> class Vb>

View File

@ -149,6 +149,22 @@ public:
void reset() {} void reset() {}
}; };
template <class T,
class TimeStamper_,
bool has_ts = CGAL::internal::Has_timestamp<T>::value>
struct CC_ts_impl_impl : public CGAL_time_stamper<T>
{};
template <class T,
class TimeStamper_>
struct CC_ts_impl_impl<T, TimeStamper_, false> : public CGAL_no_time_stamp<T>
{};
template <class T,
class TimeStamper_>
struct CC_ts_impl : public CC_ts_impl_impl<T, TimeStamper_>
{};
template < class T, template < class T,
class Allocator_ = Default, class Allocator_ = Default,
class TimeStamper_ = Default > class TimeStamper_ = Default >
@ -158,11 +174,7 @@ class Compact_container
typedef typename Default::Get< Al, CGAL_ALLOCATOR(T) >::type Allocator; typedef typename Default::Get< Al, CGAL_ALLOCATOR(T) >::type Allocator;
typedef TimeStamper_ Ts; typedef TimeStamper_ Ts;
typedef typename boost::mpl::if_c< typedef CC_ts_impl<T, Ts> Time_stamper_impl;
CGAL::internal::Mesh_3::Has_timestamp<T>::value,
CGAL_time_stamper<T>,
CGAL_no_time_stamp<T> >::type Time_stamper_;
typedef typename Default::Get<Ts, Time_stamper_>::type Time_stamper;
typedef Compact_container <T, Al, Ts> Self; typedef Compact_container <T, Al, Ts> Self;
typedef Compact_container_traits <T> Traits; typedef Compact_container_traits <T> Traits;
@ -185,7 +197,7 @@ public:
explicit Compact_container(const Allocator &a = Allocator()) explicit Compact_container(const Allocator &a = Allocator())
: alloc(a) : alloc(a)
, time_stamper() , time_stamper(new Time_stamper_impl())
{ {
init(); init();
} }
@ -194,7 +206,7 @@ public:
Compact_container(InputIterator first, InputIterator last, Compact_container(InputIterator first, InputIterator last,
const Allocator & a = Allocator()) const Allocator & a = Allocator())
: alloc(a) : alloc(a)
, time_stamper() , time_stamper(new Time_stamper_impl())
{ {
init(); init();
std::copy(first, last, CGAL::inserter(*this)); std::copy(first, last, CGAL::inserter(*this));
@ -203,11 +215,11 @@ public:
// The copy constructor and assignment operator preserve the iterator order // The copy constructor and assignment operator preserve the iterator order
Compact_container(const Compact_container &c) Compact_container(const Compact_container &c)
: alloc(c.get_allocator()) : alloc(c.get_allocator())
, time_stamper() , time_stamper(new Time_stamper_impl())
{ {
init(); init();
block_size = c.block_size; block_size = c.block_size;
time_stamper = c.time_stamper; *time_stamper = *c.time_stamper;
std::copy(c.begin(), c.end(), CGAL::inserter(*this)); std::copy(c.begin(), c.end(), CGAL::inserter(*this));
} }
@ -223,6 +235,7 @@ public:
~Compact_container() ~Compact_container()
{ {
clear(); clear();
delete time_stamper;
} }
void swap(Self &c) void swap(Self &c)
@ -281,7 +294,7 @@ public:
new (ret) value_type(args...); new (ret) value_type(args...);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
#else #else
@ -296,7 +309,7 @@ public:
new (ret) value_type(); new (ret) value_type();
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -312,7 +325,7 @@ public:
new (ret) value_type(t1); new (ret) value_type(t1);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -328,7 +341,7 @@ public:
new (ret) value_type(t1, t2); new (ret) value_type(t1, t2);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -344,7 +357,7 @@ public:
new (ret) value_type(t1, t2, t3); new (ret) value_type(t1, t2, t3);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -360,7 +373,7 @@ public:
new (ret) value_type(t1, t2, t3, t4); new (ret) value_type(t1, t2, t3, t4);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -377,7 +390,7 @@ public:
new (ret) value_type(t1, t2, t3, t4, t5); new (ret) value_type(t1, t2, t3, t4, t5);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -395,7 +408,7 @@ public:
new (ret) value_type(t1, t2, t3, t4, t5, t6); new (ret) value_type(t1, t2, t3, t4, t5, t6);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -413,7 +426,7 @@ public:
new (ret) value_type(t1, t2, t3, t4, t5, t6, t7); new (ret) value_type(t1, t2, t3, t4, t5, t6, t7);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -431,7 +444,7 @@ public:
new (ret) value_type(t1, t2, t3, t4, t5, t6, t7, t8); new (ret) value_type(t1, t2, t3, t4, t5, t6, t7, t8);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
#endif // CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES #endif // CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES
@ -446,7 +459,7 @@ public:
alloc.construct(ret, t); alloc.construct(ret, t);
CGAL_assertion(type(ret) == USED); CGAL_assertion(type(ret) == USED);
++size_; ++size_;
time_stamper.set_time_stamp(ret); time_stamper->set_time_stamp(ret);
return iterator(ret, 0); return iterator(ret, 0);
} }
@ -637,7 +650,7 @@ private:
first_item = NULL; first_item = NULL;
last_item = NULL; last_item = NULL;
all_items = All_items(); all_items = All_items();
time_stamper.reset(); time_stamper->reset();
} }
allocator_type alloc; allocator_type alloc;
@ -648,7 +661,7 @@ private:
pointer first_item; pointer first_item;
pointer last_item; pointer last_item;
All_items all_items; All_items all_items;
Time_stamper time_stamper; Time_stamper_impl* time_stamper;
}; };
template < class T, class Allocator, class TimeStamper> template < class T, class Allocator, class TimeStamper>
@ -794,7 +807,6 @@ namespace internal {
typedef typename DSC::value_type value_type; typedef typename DSC::value_type value_type;
typedef typename DSC::size_type size_type; typedef typename DSC::size_type size_type;
typedef typename DSC::difference_type difference_type; typedef typename DSC::difference_type difference_type;
typedef typename DSC::Time_stamper TimeStamper;
typedef typename boost::mpl::if_c< Const, const value_type*, typedef typename boost::mpl::if_c< Const, const value_type*,
value_type*>::type pointer; value_type*>::type pointer;
typedef typename boost::mpl::if_c< Const, const value_type&, typedef typename boost::mpl::if_c< Const, const value_type&,
@ -830,6 +842,8 @@ namespace internal {
private: private:
typedef typename DSC::Time_stamper_impl Time_stamper_impl;
union { union {
pointer p; pointer p;
void *vp; void *vp;
@ -932,23 +946,23 @@ namespace internal {
// For std::less... // For std::less...
bool operator<(const CC_iterator& other) const 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 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 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); || (*this == other);
} }
bool operator>=(const CC_iterator& other) const 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); || (*this == other);
} }

View File

@ -17,8 +17,8 @@
// //
// Author(s) : Jane Tournois // Author(s) : Jane Tournois
#ifndef CGAL_MESH_3_HAS_TIMESTAMP_H #ifndef CGAL_HAS_TIMESTAMP_H
#define CGAL_MESH_3_HAS_TIMESTAMP_H #define CGAL_HAS_TIMESTAMP_H
#include <boost/mpl/has_xxx.hpp> #include <boost/mpl/has_xxx.hpp>
#include <CGAL/tags.h> #include <CGAL/tags.h>
@ -26,18 +26,23 @@
namespace CGAL { namespace CGAL {
namespace internal { namespace internal {
namespace Mesh_3 {
BOOST_MPL_HAS_XXX_TRAIT_DEF(Has_timestamp)
// to have Mesh_3 deterministic, // to have Mesh_3 deterministic,
// a partial specialization of this class should be written next to // a partial specialization of this class should be written next to
// every class that implements concepts MeshCellBase_3 or MeshVertexBase_3 // every class that implements concepts MeshCellBase_3 or MeshVertexBase_3
template <typename T> template <typename T, bool has_ts = has_Has_timestamp<T>::value>
struct Has_timestamp : public CGAL::Tag_false struct Has_timestamp : public T::Has_timestamp
// when T does not have a partial specialization of Has_timestamp
{};
template <typename T>
struct Has_timestamp<T, false> : public Tag_false
// when T does not have a partial specialization of Has_timestamp // when T does not have a partial specialization of Has_timestamp
{}; {};
} // end namespace internal::Mesh_3
} // end namespace internal } // end namespace internal
} // end namespace CGAL } // end namespace CGAL
#endif // CGAL_MESH_3_HAS_TIMESTAMP_H #endif // CGAL_HAS_TIMESTAMP_H