|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r66047 - trunk/boost/spirit/home/support/iterators/detail
From: hartmut.kaiser_at_[hidden]
Date: 2010-10-17 15:49:52
Author: hkaiser
Date: 2010-10-17 15:49:48 EDT (Sun, 17 Oct 2010)
New Revision: 66047
URL: http://svn.boost.org/trac/boost/changeset/66047
Log:
Spirit: fixing problem with the multi_pass/fixed_size_queue policy
Text files modified:
trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue.hpp | 48 +++++++++++++++++++++------------------
trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue_policy.hpp | 37 +++++++++++++++++-------------
2 files changed, 47 insertions(+), 38 deletions(-)
Modified: trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue.hpp 2010-10-17 15:49:48 EDT (Sun, 17 Oct 2010)
@@ -33,21 +33,22 @@
///////////////////////////////////////////////////////////////////////////
template <typename Queue, typename T, typename Pointer>
class fsq_iterator
- : public boost::iterator_adaptor<
- fsq_iterator<Queue, T, Pointer>, Pointer, T,
+ : public boost::iterator_facade<
+ fsq_iterator<Queue, T, Pointer>, T,
std::random_access_iterator_tag
>
{
public:
typedef typename Queue::position_type position_type;
- typedef boost::iterator_adaptor<
- fsq_iterator<Queue, T, Pointer>, Pointer, T,
+ typedef boost::iterator_facade<
+ fsq_iterator<Queue, T, Pointer>, T,
std::random_access_iterator_tag
> base_type;
fsq_iterator() {}
fsq_iterator(position_type const &p_) : p(p_) {}
+ position_type &get_position() { return p; }
position_type const &get_position() const { return p; }
private:
@@ -73,30 +74,30 @@
--p.pos;
}
- template <
- typename OtherDerived, typename OtherIterator,
- typename V, typename C, typename R, typename D
- >
- bool equal(iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D>
- const &x) const
+ bool is_eof() const
{
- position_type const &rhs_pos =
- static_cast<OtherDerived const &>(x).get_position();
+ return p.self == 0 || p.pos == p.self->size();
+ }
+
+ template <typename Q, typename T_, typename P>
+ bool equal(fsq_iterator<Q, T_, P> const &x) const
+ {
+ if (is_eof())
+ return x.is_eof();
+ if (x.is_eof())
+ return false;
+
+ position_type const &rhs_pos = x.get_position();
return (p.self == rhs_pos.self) && (p.pos == rhs_pos.pos);
}
- template <
- typename OtherDerived, typename OtherIterator,
- typename V, typename C, typename R, typename D
- >
+ template <typename Q, typename T_, typename P>
typename base_type::difference_type distance_to(
- iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D>
- const &x) const
+ fsq_iterator<Q, T_, P> const &x) const
{
typedef typename base_type::difference_type difference_type;
- position_type const &p2 =
- static_cast<OtherDerived const &>(x).get_position();
+ position_type const &p2 = x.get_position();
std::size_t pos1 = p.pos;
std::size_t pos2 = p2.pos;
@@ -161,6 +162,9 @@
position(const fixed_size_queue* s, std::size_t p)
: self(const_cast<fixed_size_queue*>(s)), pos(p)
{}
+
+ bool is_initialized() const { return self != 0; }
+ void set_queue(fixed_size_queue* q) { self = q; }
};
public:
@@ -206,12 +210,12 @@
iterator end()
{
- return iterator(position(this, m_tail));
+ return iterator(position(0, m_tail));
}
const_iterator end() const
{
- return const_iterator(position(this, m_tail));
+ return const_iterator(position(0, m_tail));
}
std::size_t size() const
Modified: trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue_policy.hpp
==============================================================================
--- trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue_policy.hpp (original)
+++ trunk/boost/spirit/home/support/iterators/detail/fixed_size_queue_policy.hpp 2010-10-17 15:49:48 EDT (Sun, 17 Oct 2010)
@@ -41,11 +41,11 @@
unique() {}
unique(unique const& x)
- : queuePosition(x.queuePosition) {}
+ : queued_position(x.queued_position) {}
void swap(unique& x)
{
- boost::swap(queuePosition, x.queuePosition);
+ boost::swap(queued_position, x.queued_position);
}
// This is called when the iterator is dereferenced. It's a
@@ -55,11 +55,13 @@
static typename MultiPass::reference
dereference(MultiPass const& mp)
{
- if (mp.queuePosition == mp.shared()->queuedElements.end())
- {
+ if (!mp.queued_position.get_position().is_initialized())
+ mp.queued_position.get_position().set_queue(&mp.shared()->queued_elements);
+
+ if (mp.queued_position == mp.shared()->queued_elements.end())
return MultiPass::get_input(mp);
- }
- return *mp.queuePosition;
+
+ return *mp.queued_position;
}
// This is called when the iterator is incremented. It's a
@@ -68,17 +70,20 @@
template <typename MultiPass>
static void increment(MultiPass& mp)
{
- if (mp.queuePosition == mp.shared()->queuedElements.end())
+ if (!mp.queued_position.get_position().is_initialized())
+ mp.queued_position.get_position().set_queue(&mp.shared()->queued_elements);
+
+ if (mp.queued_position == mp.shared()->queued_elements.end())
{
// don't let the queue get larger than N
- if (mp.shared()->queuedElements.size() >= N)
- mp.shared()->queuedElements.pop_front();
+ if (mp.shared()->queued_elements.size() >= N)
+ mp.shared()->queued_elements.pop_front();
- mp.shared()->queuedElements.push_back(
+ mp.shared()->queued_elements.push_back(
MultiPass::get_input(mp));
MultiPass::advance_input(mp);
}
- ++mp.queuePosition;
+ ++mp.queued_position;
}
// clear_queue is a no-op
@@ -87,7 +92,7 @@
template <typename MultiPass>
static bool is_eof(MultiPass const& mp)
{
- return mp.queuePosition == mp.shared()->queuedElements.end() &&
+ return mp.queued_position == mp.shared()->queued_elements.end() &&
MultiPass::input_at_eof(mp);
}
@@ -95,18 +100,18 @@
template <typename MultiPass>
static bool equal_to(MultiPass const& mp, MultiPass const& x)
{
- return mp.queuePosition == x.queuePosition;
+ return mp.queued_position == x.queued_position;
}
// called by operator<
template <typename MultiPass>
static bool less_than(MultiPass const& mp, MultiPass const& x)
{
- return mp.queuePosition < x.queuePosition;
+ return mp.queued_position < x.queued_position;
}
protected:
- mutable typename queue_type::iterator queuePosition;
+ mutable typename queue_type::iterator queued_position;
};
///////////////////////////////////////////////////////////////////////
@@ -114,7 +119,7 @@
struct shared
{
typedef detail::fixed_size_queue<Value, N> queue_type;
- queue_type queuedElements;
+ queue_type queued_elements;
};
};
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk