|
Boost-Commit : |
From: ockham_at_[hidden]
Date: 2008-06-27 13:26:10
Author: bernhard.reiter
Date: 2008-06-27 13:26:10 EDT (Fri, 27 Jun 2008)
New Revision: 46781
URL: http://svn.boost.org/trac/boost/changeset/46781
Log:
Derive cursor_adaptor from cursor_facade (instead of iterator_adaptor).
This was necessary as the previous implementation just overrode range and cursor
specific functions, such as (to_)begin() etc.
Text files modified:
sandbox/SOC/2006/tree/trunk/boost/tree/cursor_helpers.hpp | 256 ++++++++++++++++++++++++++++++---------
sandbox/SOC/2006/tree/trunk/boost/tree/detail/cursor/forest.hpp | 7
2 files changed, 194 insertions(+), 69 deletions(-)
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/cursor_helpers.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/cursor_helpers.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/cursor_helpers.hpp 2008-06-27 13:26:10 EDT (Fri, 27 Jun 2008)
@@ -14,11 +14,13 @@
#ifndef BOOST_TREE_CURSOR_HELPERS_HPP
#define BOOST_TREE_CURSOR_HELPERS_HPP
+#include <boost/tree/cursor.hpp>
#include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/type_traits/integral_constant.hpp>
+#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <boost/utility/enable_if.hpp>
@@ -188,108 +190,236 @@
}
};
+// We'll abuse iterator_adaptor to determine our types.
template <
class Derived
, class Base
- , class Value = use_default
- , class HorizontalTraversal = use_default
- , class VerticalTraversal = use_default
- , class Reference = use_default
- , class Difference = use_default
- , class Size = use_default
+ , class Value = use_default
+ , class HorizontalTraversalOrCategory = use_default
+ , class VerticalTraversalOrCategory = use_default
+ , class Reference = use_default
+ , class Difference = use_default
+ , class Size = use_default
+>
+class eval_use_default
+: private iterator_adaptor<Derived
+ , Base
+ , Value
+ , HorizontalTraversalOrCategory
+ , Reference
+ , Difference>
+, private iterator_adaptor<Derived
+ , Base
+ , Value
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference>
+{
+private:
+ eval_use_default() {} // This class is used for typedefs only.
+
+ typedef typename iterator_adaptor<Derived, Base, Value
+ , HorizontalTraversalOrCategory, Reference
+ , Difference>::super_t h_super_t;
+ typedef typename iterator_adaptor<Derived, Base, Value
+ , VerticalTraversalOrCategory, Reference
+ , Difference>::super_t v_super_t;
+public:
+ typedef typename h_super_t::value_type value_type;
+ typedef typename h_super_t::reference reference;
+ typedef typename h_super_t::difference_type difference_type;
+ typedef typename h_super_t::pointer pointer;
+ typedef typename h_super_t::iterator_category iterator_category;
+ typedef typename v_super_t::iterator_category vertical_traversal;
+
+ // size_type isn't in iterator_adaptor,
+ // so we have to calculate it on our own:
+ typedef typename mpl::eval_if<
+ is_same<Size, use_default>
+ , boost::tree::cursor_size<Base>
+ , mpl::identity<Size>
+ >::type size_type;
+};
+
+template <
+ class Derived
+ , class Base
+ , class Value = use_default
+ , class HorizontalTraversalOrCategory = use_default
+ , class VerticalTraversalOrCategory = use_default
+ , class Reference = use_default
+ , class Difference = use_default
+ , class Size = use_default
>
class cursor_adaptor
- : public iterator_adaptor<Derived, Base, Value, HorizontalTraversal, Reference,
- Difference>
+: public cursor_facade<
+ Derived
+ , typename eval_use_default<Derived
+ , Base
+ , Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size>::value_type
+ , typename eval_use_default<Derived
+ , Base
+ , Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size>::iterator_category
+ , typename eval_use_default<Derived
+ , Base
+ , Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size>::vertical_traversal
+ , typename eval_use_default<Derived
+ , Base
+ , Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size>::reference
+ , typename eval_use_default<Derived
+ , Base
+ , Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size>::difference_type
+ , typename eval_use_default<Derived
+ , Base
+ , Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size>::size_type>
{
friend class iterator_core_access;
friend class cursor_core_access;
- typedef iterator_adaptor<Derived, Base, Value, HorizontalTraversal, Reference,
- Difference> iterator_adaptor_;
-
-private:
- // Curiously Recurring Template interface.
+ typedef cursor_facade<Derived
+ , Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size> cursor_facade_;
- Derived& derived()
- {
- return *static_cast<Derived*>(this);
- }
-
- Derived const& derived() const
- {
- return *static_cast<Derived const*>(this);
- }
-
-public:
- cursor_adaptor() : iterator_adaptor_()
- { }
+ public:
+ cursor_adaptor() {}
- explicit cursor_adaptor(Base const& iter) : iterator_adaptor_(iter)
+ explicit cursor_adaptor(Base const& cur) : m_cursor(cur)
{ }
- typedef HorizontalTraversal horizontal_traversal;
- typedef VerticalTraversal cursor_category;
+ Base const& base() const
+ { return m_cursor; }
+
+ typedef typename cursor_facade_::iterator_category iterator_category;
+
+ typedef typename cursor_facade_::horizontal_traversal horizontal_traversal;
+ typedef typename cursor_facade_::vertical_traversal cursor_category;
typedef Size size_type;
typedef Base base_type;
-
-
+
protected:
- typedef cursor_adaptor cursor_adaptor_;
-
+ typedef cursor_adaptor<Derived, Base, Value, HorizontalTraversalOrCategory,
+ VerticalTraversalOrCategory, Reference, Difference,
+ Size> cursor_adaptor_;
+
+ typedef eval_use_default<Derived
+ , Base
+ , Value
+ , HorizontalTraversalOrCategory
+ , VerticalTraversalOrCategory
+ , Reference
+ , Difference
+ , Size> super_t;
+
+ Base const& base_reference() const
+ { return m_cursor; }
+
+ Base& base_reference()
+ { return m_cursor; }
+
public:
- bool const empty() const
+
+ typename super_t::reference dereference() const
+ {
+ return *m_cursor;
+ }
+
+ void increment()
+ {
+ ++m_cursor;
+ }
+
+ void decrement()
+ {
+ --m_cursor;
+ }
+
+ template <class OtherDerived, class OtherCursor, class V, class C,
+ class R, class D, class S>
+ bool equal(cursor_adaptor<OtherDerived, OtherCursor,
+ V, C, R, D, S> const& x) const
+ {
+ return m_cursor == x.base();
+ }
+
+ template <class OtherDerived, class OtherCursor, class V, class C,
+ class R, class D, class S>
+ Difference distance_to(cursor_adaptor<OtherDerived, OtherCursor,
+ V, C, R, D, S> const& x) const
{
- return this->base().empty();
+ return x.base() - m_cursor;
}
-
- size_type const size() const
+
+ bool const empty_() const
{
- return this->base().size();
+ return m_cursor.empty();
}
- size_type const max_size() const
+ size_type const size_() const
{
- return this->base().max_size();
+ return m_cursor.size();
}
-
- size_type const parity() const
+
+ size_type const max_size_() const
{
- return this->base().parity();
+ return m_cursor.max_size();
}
- Derived& to_begin()
+ size_type const par() const
{
- this->base_reference().to_begin();
- return this->derived();
- }
-
- Derived begin()
- {
- return Derived(this->base_reference().begin());
+ return m_cursor.parity();
}
- Derived& to_end()
+ void left()
{
- this->base_reference().to_end();
- return this->derived();
+ m_cursor.to_begin();
}
- Derived end()
+ void right()
{
- return Derived(this->base_reference().end());
+ m_cursor.to_end();
}
- Derived& to_parent()
+ void up()
{
- this->base_reference().to_parent();
- return this->derived();
+ m_cursor.to_parent();
}
- Derived parent()
- {
- return Derived(this->base_reference().parent());
- }
+private:
+ Base m_cursor;
};
//TODO: Put somewhere else?
Modified: sandbox/SOC/2006/tree/trunk/boost/tree/detail/cursor/forest.hpp
==============================================================================
--- sandbox/SOC/2006/tree/trunk/boost/tree/detail/cursor/forest.hpp (original)
+++ sandbox/SOC/2006/tree/trunk/boost/tree/detail/cursor/forest.hpp 2008-06-27 13:26:10 EDT (Fri, 27 Jun 2008)
@@ -175,12 +175,7 @@
}
// Range stuff.
- // left() remains unchanged.
-
-// void left()
-// {
-// this->base_reference().to_begin();
-// }
+ // left() remains unchanged, so no need to re-implement it.
void right()
{
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