mirror of
https://github.com/boostorg/circular_buffer.git
synced 2026-02-10 23:32:21 +00:00
Fix for VC6, updated TODO, source formatting.
[SVN r2592]
This commit is contained in:
@@ -448,7 +448,7 @@ public:
|
||||
return begin() + index;
|
||||
}
|
||||
|
||||
//!! See the circular_buffer source documentation.
|
||||
//!! See the circular_buffer source documentation.
|
||||
/*!
|
||||
\warning The rules for iterator invalidation differ from the original
|
||||
circular_buffer. See the <a href="../circular_buffer_adaptor.html#invalidation">
|
||||
|
||||
@@ -160,7 +160,7 @@ public:
|
||||
|
||||
//! Return a reverse iterator pointing to the end of the reversed circular buffer.
|
||||
reverse_iterator rend() { return reverse_iterator(begin()); }
|
||||
|
||||
|
||||
//! Return a const reverse iterator pointing to the beginning of the reversed circular buffer.
|
||||
const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
|
||||
|
||||
@@ -306,7 +306,7 @@ public:
|
||||
|
||||
//! Return the largest possible size (or capacity) of the circular buffer.
|
||||
size_type max_size() const { return m_alloc.max_size(); }
|
||||
|
||||
|
||||
//! Is the circular buffer empty?
|
||||
/*!
|
||||
\return <code>true</code> if there are no elements stored in the circular buffer.
|
||||
@@ -553,7 +553,7 @@ public:
|
||||
\note For iterator invalidation see the <a href="../circular_buffer.html#invalidation">documentation</a>.
|
||||
*/
|
||||
void assign(size_type n, param_value_type item) { do_assign(n, assign_n(n, item, m_alloc)); }
|
||||
|
||||
|
||||
//! Assign a copy of range.
|
||||
/*!
|
||||
\pre Valid range <code>[first, last)</code>.
|
||||
@@ -999,18 +999,18 @@ public:
|
||||
BOOST_CB_ASSERT(first <= last); // check for wrong range
|
||||
if (first == last)
|
||||
return first;
|
||||
pointer p = first.m_it;
|
||||
pointer p = first.m_it;
|
||||
while (last.m_it != 0)
|
||||
replace((first++).m_it, *last++);
|
||||
do {
|
||||
decrement(m_last);
|
||||
destroy_item(m_last);
|
||||
--m_size;
|
||||
} while(m_last != first.m_it);
|
||||
decrement(m_last);
|
||||
destroy_item(m_last);
|
||||
--m_size;
|
||||
} while(m_last != first.m_it);
|
||||
return m_last == p ? end() : iterator(this, p);
|
||||
}
|
||||
|
||||
//! Erase the element at the given position.
|
||||
//! Erase the element at the given position.
|
||||
/*!
|
||||
\pre Valid <code>pos</code> iterator.
|
||||
\pre <code>size_type old_size = (*this).size()</code>
|
||||
@@ -1024,11 +1024,11 @@ public:
|
||||
BOOST_CB_ASSERT(pos.is_valid()); // check for uninitialized or invalidated iterator
|
||||
BOOST_CB_ASSERT(pos.m_it != 0); // check for iterator pointing to end()
|
||||
pointer prev = pos.m_it;
|
||||
pointer p = prev;
|
||||
pointer p = prev;
|
||||
for (decrement(prev); p != m_first; p = prev, decrement(prev))
|
||||
replace(p, *prev);
|
||||
destroy_item(m_first);
|
||||
increment(m_first);
|
||||
increment(m_first);
|
||||
--m_size;
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
return p == pos.m_it ? begin() : iterator(this, pos.m_it);
|
||||
@@ -1067,9 +1067,9 @@ public:
|
||||
--m_size;
|
||||
} while(m_first != p);
|
||||
if (m_first == last.m_it)
|
||||
return begin();
|
||||
decrement(last.m_it);
|
||||
return iterator(this, last.m_it);
|
||||
return begin();
|
||||
decrement(last.m_it);
|
||||
return iterator(this, last.m_it);
|
||||
}
|
||||
|
||||
//! Erase all stored elements.
|
||||
@@ -1149,7 +1149,7 @@ private:
|
||||
|
||||
//! Replace an element.
|
||||
void replace(pointer pos, param_value_type item) {
|
||||
*pos = item;
|
||||
*pos = item;
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
invalidate_iterators(iterator(this, pos));
|
||||
#endif
|
||||
|
||||
@@ -19,51 +19,7 @@ namespace cb_details {
|
||||
|
||||
#if BOOST_CB_ENABLE_DEBUG
|
||||
|
||||
class cb_iterator_base;
|
||||
|
||||
/*!
|
||||
\class cb_iterator_registry
|
||||
\brief Registry of valid iterators.
|
||||
|
||||
This class is intended to be a base class of a container.
|
||||
*/
|
||||
class cb_iterator_registry {
|
||||
|
||||
//! Pointer to the chain of valid iterators.
|
||||
mutable const cb_iterator_base* m_iterators;
|
||||
|
||||
public:
|
||||
// Methods
|
||||
|
||||
//! Default constructor.
|
||||
cb_iterator_registry() : m_iterators(0) {}
|
||||
|
||||
//! Register an iterator into the list of valid iterators.
|
||||
/*!
|
||||
\note The method is const in order to register iterators into const containers, too.
|
||||
*/
|
||||
void register_iterator(const cb_iterator_base* it) const;
|
||||
|
||||
//! Unregister an iterator from the list of valid iterators.
|
||||
/*!
|
||||
\note The method is const in order to unregister iterators from const containers, too.
|
||||
*/
|
||||
void unregister_iterator(const cb_iterator_base* it) const;
|
||||
|
||||
//! Invalidate all iterators.
|
||||
void invalidate_all_iterators();
|
||||
|
||||
//! Invalidate every iterator conforming to the condition.
|
||||
template <class Iterator0>
|
||||
void invalidate_iterators(const Iterator0& it);
|
||||
|
||||
private:
|
||||
// Helpers
|
||||
|
||||
//! Remove the current iterator from the iterator chain.
|
||||
void remove(const cb_iterator_base* current,
|
||||
const cb_iterator_base* previous) const; // the implementation is below
|
||||
};
|
||||
class cb_iterator_registry;
|
||||
|
||||
/*!
|
||||
\class cb_iterator_base
|
||||
@@ -86,105 +42,161 @@ public:
|
||||
// Construction/destruction
|
||||
|
||||
//! Default constructor.
|
||||
cb_iterator_base() : m_registry(0), m_next(0) {}
|
||||
cb_iterator_base();
|
||||
|
||||
//! Constructor taking the iterator registry as a parameter.
|
||||
cb_iterator_base(const cb_iterator_registry* registry)
|
||||
: m_registry(registry), m_next(0) {
|
||||
register_self();
|
||||
}
|
||||
cb_iterator_base(const cb_iterator_registry* registry);
|
||||
|
||||
//! Copy constructor.
|
||||
cb_iterator_base(const cb_iterator_base& rhs)
|
||||
: m_registry(rhs.m_registry), m_next(0) {
|
||||
register_self();
|
||||
}
|
||||
cb_iterator_base(const cb_iterator_base& rhs);
|
||||
|
||||
//! Destructor.
|
||||
~cb_iterator_base() { unregister_self(); }
|
||||
|
||||
//! Assign operator.
|
||||
cb_iterator_base& operator = (const cb_iterator_base& rhs) {
|
||||
if (m_registry == rhs.m_registry)
|
||||
return *this;
|
||||
unregister_self();
|
||||
m_registry = rhs.m_registry;
|
||||
register_self();
|
||||
return *this;
|
||||
}
|
||||
~cb_iterator_base();
|
||||
|
||||
// Methods
|
||||
|
||||
//! Assign operator.
|
||||
cb_iterator_base& operator = (const cb_iterator_base& rhs);
|
||||
|
||||
//! Is the iterator valid?
|
||||
bool is_valid() const { return m_registry != 0; }
|
||||
bool is_valid() const;
|
||||
|
||||
//! Invalidate the iterator.
|
||||
/*!
|
||||
\note The method is const in order to invalidate const iterators, too.
|
||||
*/
|
||||
void invalidate() const { m_registry = 0; }
|
||||
void invalidate() const;
|
||||
|
||||
//! Return the next iterator in the iterator chain.
|
||||
const cb_iterator_base* next() const { return m_next; }
|
||||
const cb_iterator_base* next() const;
|
||||
|
||||
//! Set the next iterator in the iterator chain.
|
||||
/*!
|
||||
\note The method is const in order to set a next iterator to a const iterator, too.
|
||||
*/
|
||||
void set_next(const cb_iterator_base* it) const { m_next = it; }
|
||||
void set_next(const cb_iterator_base* it) const;
|
||||
|
||||
private:
|
||||
// Helpers
|
||||
|
||||
//! Register self as a valid iterator.
|
||||
void register_self() {
|
||||
if (m_registry != 0)
|
||||
m_registry->register_iterator(this);
|
||||
}
|
||||
void register_self();
|
||||
|
||||
//! Unregister self from valid iterators.
|
||||
void unregister_self() {
|
||||
if (m_registry != 0)
|
||||
m_registry->unregister_iterator(this);
|
||||
void unregister_self();
|
||||
};
|
||||
|
||||
/*!
|
||||
\class cb_iterator_registry
|
||||
\brief Registry of valid iterators.
|
||||
|
||||
This class is intended to be a base class of a container.
|
||||
*/
|
||||
class cb_iterator_registry {
|
||||
|
||||
//! Pointer to the chain of valid iterators.
|
||||
mutable const cb_iterator_base* m_iterators;
|
||||
|
||||
public:
|
||||
// Methods
|
||||
|
||||
//! Default constructor.
|
||||
cb_iterator_registry() : m_iterators(0) {}
|
||||
|
||||
//! Register an iterator into the list of valid iterators.
|
||||
/*!
|
||||
\note The method is const in order to register iterators into const containers, too.
|
||||
*/
|
||||
void register_iterator(const cb_iterator_base* it) const {
|
||||
it->set_next(m_iterators);
|
||||
m_iterators = it;
|
||||
}
|
||||
|
||||
//! Unregister an iterator from the list of valid iterators.
|
||||
/*!
|
||||
\note The method is const in order to unregister iterators from const containers, too.
|
||||
*/
|
||||
void unregister_iterator(const cb_iterator_base* it) const {
|
||||
const cb_iterator_base* previous = 0;
|
||||
for (const cb_iterator_base* p = m_iterators; p != it; previous = p, p = p->next());
|
||||
remove(it, previous);
|
||||
}
|
||||
|
||||
//! Invalidate all iterators.
|
||||
void invalidate_all_iterators() {
|
||||
for (const cb_iterator_base* p = m_iterators; p != 0; p = p->next())
|
||||
p->invalidate();
|
||||
m_iterators = 0;
|
||||
}
|
||||
|
||||
//! Invalidate every iterator conforming to the condition.
|
||||
template <class Iterator0>
|
||||
void invalidate_iterators(const Iterator0& it) {
|
||||
const cb_iterator_base* previous = 0;
|
||||
for (const cb_iterator_base* p = m_iterators; p != 0; p = p->next()) {
|
||||
if (((Iterator0*)p)->m_it == it.m_it) {
|
||||
p->invalidate();
|
||||
remove(p, previous);
|
||||
continue;
|
||||
}
|
||||
previous = p;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
// Helpers
|
||||
|
||||
//! Remove the current iterator from the iterator chain.
|
||||
void remove(const cb_iterator_base* current,
|
||||
const cb_iterator_base* previous) const {
|
||||
if (previous == 0)
|
||||
m_iterators = m_iterators->next();
|
||||
else
|
||||
previous->set_next(current->next());
|
||||
}
|
||||
};
|
||||
|
||||
inline void cb_iterator_registry::register_iterator(const cb_iterator_base* it) const {
|
||||
it->set_next(m_iterators);
|
||||
m_iterators = it;
|
||||
// Implementation of the cb_iterator_base methods.
|
||||
|
||||
inline cb_iterator_base::cb_iterator_base() : m_registry(0), m_next(0) {}
|
||||
|
||||
inline cb_iterator_base::cb_iterator_base(const cb_iterator_registry* registry)
|
||||
: m_registry(registry), m_next(0) {
|
||||
register_self();
|
||||
}
|
||||
|
||||
inline void cb_iterator_registry::unregister_iterator(const cb_iterator_base* it) const {
|
||||
const cb_iterator_base* previous = 0;
|
||||
for (const cb_iterator_base* p = m_iterators; p != it; previous = p, p = p->next());
|
||||
remove(it, previous);
|
||||
inline cb_iterator_base::cb_iterator_base(const cb_iterator_base& rhs)
|
||||
: m_registry(rhs.m_registry), m_next(0) {
|
||||
register_self();
|
||||
}
|
||||
|
||||
inline void cb_iterator_registry::invalidate_all_iterators() {
|
||||
for (const cb_iterator_base* p = m_iterators; p != 0; p = p->next())
|
||||
p->invalidate();
|
||||
m_iterators = 0;
|
||||
inline cb_iterator_base::~cb_iterator_base() { unregister_self(); }
|
||||
|
||||
inline cb_iterator_base& cb_iterator_base::operator = (const cb_iterator_base& rhs) {
|
||||
if (m_registry == rhs.m_registry)
|
||||
return *this;
|
||||
unregister_self();
|
||||
m_registry = rhs.m_registry;
|
||||
register_self();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class Iterator0>
|
||||
inline void cb_iterator_registry::invalidate_iterators(const Iterator0& it) {
|
||||
const cb_iterator_base* previous = 0;
|
||||
for (const cb_iterator_base* p = m_iterators; p != 0; p = p->next()) {
|
||||
if (((Iterator0*)p)->m_it == it.m_it) {
|
||||
p->invalidate();
|
||||
remove(p, previous);
|
||||
continue;
|
||||
}
|
||||
previous = p;
|
||||
}
|
||||
inline bool cb_iterator_base::is_valid() const { return m_registry != 0; }
|
||||
|
||||
inline void cb_iterator_base::invalidate() const { m_registry = 0; }
|
||||
|
||||
inline const cb_iterator_base* cb_iterator_base::next() const { return m_next; }
|
||||
|
||||
inline void cb_iterator_base::set_next(const cb_iterator_base* it) const { m_next = it; }
|
||||
|
||||
inline void cb_iterator_base::register_self() {
|
||||
if (m_registry != 0)
|
||||
m_registry->register_iterator(this);
|
||||
}
|
||||
|
||||
inline void cb_iterator_registry::remove(const cb_iterator_base* current,
|
||||
const cb_iterator_base* previous) const {
|
||||
if (previous == 0)
|
||||
m_iterators = m_iterators->next();
|
||||
else
|
||||
previous->set_next(current->next());
|
||||
inline void cb_iterator_base::unregister_self() {
|
||||
if (m_registry != 0)
|
||||
m_registry->unregister_iterator(this);
|
||||
}
|
||||
|
||||
#else // #if BOOST_CB_ENABLE_DEBUG
|
||||
|
||||
@@ -123,8 +123,8 @@ struct cb_helper_pointer {
|
||||
\note This iterator is not circular. It was designed
|
||||
for iterating from begin() to end() of the circular buffer.
|
||||
*/
|
||||
template <class Buff, class Traits>
|
||||
class cb_iterator :
|
||||
template <class Buff, class Traits>
|
||||
class cb_iterator :
|
||||
public boost::iterator<
|
||||
std::random_access_iterator_tag,
|
||||
typename Traits::value_type,
|
||||
|
||||
Reference in New Issue
Block a user