1 // Copyright (c) 2001 Daniel C. Nuffer
2 // Copyright (c) 2001-2011 Hartmut Kaiser
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #if !defined(BOOST_SPIRIT_BUFFERING_ITERATOR_INPUT_ITERATOR_POLICY_MAR_04_2010_1224AM)
8 #define BOOST_SPIRIT_BUFFERING_ITERATOR_INPUT_ITERATOR_POLICY_MAR_04_2010_1224AM
10 #include <boost/spirit/home/support/iterators/multi_pass_fwd.hpp>
11 #include <boost/spirit/home/support/iterators/detail/multi_pass.hpp>
12 #include <boost/spirit/home/support/iterators/detail/input_iterator_policy.hpp>
13 #include <boost/detail/iterator.hpp> // for boost::detail::iterator_traits
14 #include <boost/assert.hpp>
16 namespace boost { namespace spirit { namespace iterator_policies
18 ///////////////////////////////////////////////////////////////////////////
19 // class input_iterator
21 // Implementation of the InputPolicy used by multi_pass, this is different
22 // from the input_iterator policy only as it is buffering the last input
23 // character to allow returning it by reference. This is needed for
24 // wrapping iterators not buffering the last item (such as the
25 // std::istreambuf_iterator). Unfortunately there is no way to
26 // automatically figure this out at compile time.
28 // The buffering_input_iterator encapsulates an input iterator of type T
29 ///////////////////////////////////////////////////////////////////////////
30 struct buffering_input_iterator
32 ///////////////////////////////////////////////////////////////////////
34 class unique // : public detail::default_input_policy
38 typename boost::detail::iterator_traits<T>::value_type
43 typename boost::detail::iterator_traits<T>::difference_type
46 typename boost::detail::iterator_traits<T>::difference_type
49 typename boost::detail::iterator_traits<T>::pointer
52 typename boost::detail::iterator_traits<T>::reference
54 typedef result_type value_type;
58 explicit unique(T x) {}
63 template <typename MultiPass>
64 static void destroy(MultiPass&) {}
66 template <typename MultiPass>
67 static typename MultiPass::reference get_input(MultiPass& mp)
69 return mp.shared()->get_input();
72 template <typename MultiPass>
73 static void advance_input(MultiPass& mp)
75 BOOST_ASSERT(0 != mp.shared());
76 mp.shared()->advance_input();
79 // test, whether we reached the end of the underlying stream
80 template <typename MultiPass>
81 static bool input_at_eof(MultiPass const& mp)
83 static T const end_iter;
84 return mp.shared()->input_ == end_iter;
87 template <typename MultiPass>
88 static bool input_is_valid(MultiPass const& mp, value_type const& t)
90 return mp.shared()->input_is_valid_;
93 // no unique data elements
96 ///////////////////////////////////////////////////////////////////////
101 typename boost::detail::iterator_traits<T>::value_type
104 explicit shared(T const& input)
105 : input_(input), curtok_(0), input_is_valid_(false) {}
110 input_is_valid_ = false;
113 result_type& get_input()
115 if (!input_is_valid_) {
117 input_is_valid_ = true;
124 bool input_is_valid_;
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams