• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2010 Daniel James
3 
4     Use, modification and distribution is subject to the Boost Software
5     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6     http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 
9 #if !defined(BOOST_SPIRIT_QUICKBOOK_ITERATOR_HPP)
10 #define BOOST_SPIRIT_QUICKBOOK_ITERATOR_HPP
11 
12 #include <iterator>
13 #include <boost/iterator/iterator_traits.hpp>
14 #include <boost/operators.hpp>
15 #include <boost/range/iterator_range.hpp>
16 #include "string_view.hpp"
17 
18 namespace quickbook
19 {
20     template <typename Iterator>
21     struct lookback_iterator
22         : boost::forward_iterator_helper<
23               lookback_iterator<Iterator>,
24               typename boost::iterator_value<Iterator>::type,
25               typename boost::iterator_difference<Iterator>::type,
26               typename boost::iterator_pointer<Iterator>::type,
27               typename boost::iterator_reference<Iterator>::type>
28     {
lookback_iteratorquickbook::lookback_iterator29         lookback_iterator() {}
lookback_iteratorquickbook::lookback_iterator30         explicit lookback_iterator(Iterator i) : original_(i), base_(i) {}
31 
operator ==(lookback_iterator const & x,lookback_iterator const & y)32         friend bool operator==(
33             lookback_iterator const& x, lookback_iterator const& y)
34         {
35             return x.base_ == y.base_;
36         }
37 
operator ++quickbook::lookback_iterator38         lookback_iterator& operator++()
39         {
40             ++base_;
41             return *this;
42         }
43 
operator *quickbook::lookback_iterator44         typename boost::iterator_reference<Iterator>::type operator*() const
45         {
46             return *base_;
47         }
48 
basequickbook::lookback_iterator49         Iterator base() const { return base_; }
50 
51         typedef boost::iterator_range<std::reverse_iterator<Iterator> >
52             lookback_range;
53 
lookbackquickbook::lookback_iterator54         lookback_range lookback() const
55         {
56             return lookback_range(base_, original_);
57         }
58 
59       private:
60         Iterator original_;
61         Iterator base_;
62     };
63 
64     typedef lookback_iterator<string_iterator> parse_iterator;
65 }
66 
67 #endif
68