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_ITERATOR_INPUT_ITERATOR_POLICY_MAR_16_2007_1156AM)
8 #define BOOST_SPIRIT_ITERATOR_INPUT_ITERATOR_POLICY_MAR_16_2007_1156AM
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/detail/iterator.hpp> // for boost::detail::iterator_traits
13 #include <boost/assert.hpp>
15 namespace boost { namespace spirit { namespace iterator_policies
17 namespace input_iterator_is_valid_test_
19 ///////////////////////////////////////////////////////////////////////
20 template <typename Token>
21 inline bool token_is_valid(Token const& c)
23 return c ? true : false;
27 ///////////////////////////////////////////////////////////////////////////
28 // class input_iterator
29 // Implementation of the InputPolicy used by multi_pass
31 // The input_iterator encapsulates an input iterator of type T
32 ///////////////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////
37 class unique // : public detail::default_input_policy
41 typename boost::detail::iterator_traits<T>::value_type
46 typename boost::detail::iterator_traits<T>::difference_type
49 typename boost::detail::iterator_traits<T>::difference_type
52 typename boost::detail::iterator_traits<T>::pointer
55 typename boost::detail::iterator_traits<T>::reference
57 typedef result_type value_type;
61 explicit unique(T x) {}
66 template <typename MultiPass>
67 static void destroy(MultiPass&) {}
69 template <typename MultiPass>
70 static typename MultiPass::reference get_input(MultiPass& mp)
72 return *mp.shared()->input_;
75 template <typename MultiPass>
76 static void advance_input(MultiPass& mp)
78 ++mp.shared()->input_;
81 // test, whether we reached the end of the underlying stream
82 template <typename MultiPass>
83 static bool input_at_eof(MultiPass const& mp)
85 static T const end_iter;
86 return mp.shared()->input_ == end_iter;
89 template <typename MultiPass>
90 static bool input_is_valid(MultiPass const& mp, value_type const& t)
92 using namespace input_iterator_is_valid_test_;
93 return token_is_valid(t);
96 // no unique data elements
99 ///////////////////////////////////////////////////////////////////////
100 template <typename T>
103 explicit shared(T const& input) : input_(input) {}
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