add the time stamper mecanism into In_place_list

This commit is contained in:
Sébastien Loriot 2014-05-21 16:33:54 +02:00
parent 1bffc44ed4
commit 5e2ab7fddc
1 changed files with 45 additions and 17 deletions

View File

@ -33,6 +33,7 @@
#include <functional>
#include <algorithm>
#include <CGAL/memory.h>
#include <CGAL/Time_stamper.h>
namespace CGAL {
@ -87,10 +88,10 @@ namespace internal {
bool operator==( const Self& x) const { return node == x.node; }
bool operator!=( const Self& x) const { return node != x.node; }
bool operator< ( const Self& x) const { return node< x.node; }
bool operator<=( const Self& x) const { return node<= x.node; }
bool operator> ( const Self& x) const { return node> x.node; }
bool operator>=( const Self& x) const { return node>= x.node; }
bool operator< ( const Self& x) const { return Get_time_stamper<T>::type::less(node, x.node); }
bool operator<=( const Self& x) const { return Get_time_stamper<T>::type::less(node, x.node) || node==x.node; }
bool operator> ( const Self& x) const { return Get_time_stamper<T>::type::less(x.node, node); }
bool operator>=( const Self& x) const { return Get_time_stamper<T>::type::less(x.node, node) || node==x.node; }
T& operator*() const { return *node; }
T* operator->() const { return node; }
Self& operator++() {
@ -138,12 +139,12 @@ namespace internal {
In_place_list_const_iterator( Iterator i) : node(&*i) {}
In_place_list_const_iterator(const T* x) : node(x) {}
bool operator==( const Self& x) const { return node == x.node; }
bool operator!=( const Self& x) const { return node != x.node; }
bool operator< ( const Self& x) const { return node< x.node; }
bool operator<=( const Self& x) const { return node<= x.node; }
bool operator> ( const Self& x) const { return node> x.node; }
bool operator>=( const Self& x) const { return node>= x.node; }
bool operator==( const Self& x) const { return node == x.node; }
bool operator!=( const Self& x) const { return node != x.node; }
bool operator< ( const Self& x) const { return Get_time_stamper<T>::type::less(node, x.node); }
bool operator<=( const Self& x) const { return Get_time_stamper<T>::type::less(node, x.node) || node==x.node; }
bool operator> ( const Self& x) const { return Get_time_stamper<T>::type::less(x.node, node); }
bool operator>=( const Self& x) const { return Get_time_stamper<T>::type::less(x.node, node) || node==x.node; }
const T& operator*() const { return *node; }
const T* operator->() const { return node; }
Self& operator++() {
@ -233,6 +234,7 @@ protected:
pointer node;
size_type length;
Time_stamper_impl<T>* time_stamper_ptr;
// These are the only places where the allocator gets called.
pointer get_node() {
pointer p = allocator.allocate(1);
@ -265,8 +267,10 @@ public:
// CREATION
//
// New creation variable is: `l'
explicit In_place_list() : length(0) {
explicit In_place_list()
: length(0)
, time_stamper_ptr(new Time_stamper_impl<T>())
{
// introduces an empty list.
node = get_node();
(*node).next_link = node;
@ -314,6 +318,7 @@ public:
(*((*position.node).prev_link)).next_link = &x;
(*position.node).prev_link = &x;
++length;
time_stamper_ptr->set_time_stamp(&x);
return &x;
}
iterator insert(T* pos, T& x) {
@ -385,11 +390,17 @@ public:
erase( iterator(first), iterator(last));
}
void clear() { erase( begin(), end()); }
void clear() {
erase( begin(), end());
time_stamper_ptr->reset();
}
// CREATION (Continued)
explicit In_place_list(size_type n, const T& value = T()) : length(0) {
explicit In_place_list(size_type n, const T& value = T())
: length(0)
, time_stamper_ptr(new Time_stamper_impl<T>())
{
// introduces a list with n items, all initialized with copies of
// value.
node = get_node();
@ -399,7 +410,10 @@ public:
}
template <class InputIterator>
In_place_list( InputIterator first, InputIterator last) : length(0) {
In_place_list( InputIterator first, InputIterator last)
: length(0)
, time_stamper_ptr(new Time_stamper_impl<T>())
{
// a list with copies from the range [`first,last').
node = get_node();
(*node).next_link = node;
@ -407,14 +421,21 @@ public:
insert( begin(), first, last);
}
In_place_list(const T* first, const T* last) : length(0) {
In_place_list(const T* first, const T* last)
: length(0)
, time_stamper_ptr(new Time_stamper_impl<T>())
{
// a list with copies from the range [`first,last').
node = get_node();
(*node).next_link = node;
(*node).prev_link = node;
insert(begin(), first, last);
}
In_place_list(const Self& x) : length(0) {
In_place_list(const Self& x)
: length(0)
, time_stamper_ptr(new Time_stamper_impl<T>())
{
// copy constructor. Each item in `l1' is copied.
node = get_node();
(*node).next_link = node;
@ -424,6 +445,7 @@ public:
~In_place_list() {
erase(begin(), end());
put_node(node);
delete time_stamper_ptr;
}
Self& operator=(const Self& x);
@ -486,6 +508,8 @@ protected:
public:
void splice(iterator position, Self& x) {
// make sure splice is not called if time stamps are used
CGAL_static_assertion( !internal::Has_timestamp<T>::value );
// inserts the list x before position `pos' and x becomes empty.
// It takes constant time. Precondition: `&l != &x'.
if (!x.empty()) {
@ -498,6 +522,8 @@ public:
splice( iterator(position), x);
}
void splice( iterator position, Self& x, iterator i) {
// make sure splice is not called if time stamps are used
CGAL_static_assertion( !internal::Has_timestamp<T>::value );
// inserts an element pointed to by i from list x before position
// `pos' and removes the element from x. It takes constant time. i
// is a valid dereferenceable iterator of x. The result is
@ -512,6 +538,8 @@ public:
splice( iterator(position), x, iterator(i));
}
void splice(iterator pos, Self& x, iterator first, iterator last) {
// make sure splice is not called if time stamps are used
CGAL_static_assertion( !internal::Has_timestamp<T>::value );
// inserts elements in the range [`first, last') before position
// `pos' and removes the elements from x. It takes constant time
// if `&x == $l'; otherwise, it takes linear time. [`first,