]> https://gitweb.dealii.org/ - dealii.git/blob
e70af081bc4f44caf8ba6debd525fa1c3f25a6b1
[dealii.git] /
1 //  Copyright (c) 2001 Daniel C. Nuffer
2 //  Copyright (c) 2001-2011 Hartmut Kaiser
3 // 
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)
6
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
9
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>
15
16 namespace boost { namespace spirit { namespace iterator_policies
17 {
18     ///////////////////////////////////////////////////////////////////////////
19     //  class input_iterator
20     //
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.
27     // 
28     //  The buffering_input_iterator encapsulates an input iterator of type T
29     ///////////////////////////////////////////////////////////////////////////
30     struct buffering_input_iterator
31     {
32         ///////////////////////////////////////////////////////////////////////
33         template <typename T>
34         class unique // : public detail::default_input_policy
35         {
36         private:
37             typedef
38                 typename boost::detail::iterator_traits<T>::value_type
39             result_type;
40
41         public:
42             typedef
43                 typename boost::detail::iterator_traits<T>::difference_type
44             difference_type;
45             typedef
46                 typename boost::detail::iterator_traits<T>::difference_type
47             distance_type;
48             typedef
49                 typename boost::detail::iterator_traits<T>::pointer
50             pointer;
51             typedef
52                 typename boost::detail::iterator_traits<T>::reference
53             reference;
54             typedef result_type value_type;
55
56         protected:
57             unique() {}
58             explicit unique(T x) {}
59
60             void swap(unique&) {}
61
62         public:
63             template <typename MultiPass>
64             static void destroy(MultiPass&) {}
65
66             template <typename MultiPass>
67             static typename MultiPass::reference get_input(MultiPass& mp)
68             {
69                 return mp.shared()->get_input();
70             }
71
72             template <typename MultiPass>
73             static void advance_input(MultiPass& mp)
74             {
75                 BOOST_ASSERT(0 != mp.shared());
76                 mp.shared()->advance_input();
77             }
78
79             // test, whether we reached the end of the underlying stream
80             template <typename MultiPass>
81             static bool input_at_eof(MultiPass const& mp) 
82             {
83                 static T const end_iter;
84                 return mp.shared()->input_ == end_iter;
85             }
86
87             template <typename MultiPass>
88             static bool input_is_valid(MultiPass const& mp, value_type const& t) 
89             {
90                 return mp.shared()->input_is_valid_;
91             }
92
93             // no unique data elements
94         };
95
96         ///////////////////////////////////////////////////////////////////////
97         template <typename T>
98         struct shared
99         {
100             typedef
101                 typename boost::detail::iterator_traits<T>::value_type
102             result_type;
103
104             explicit shared(T const& input) 
105               : input_(input), curtok_(0), input_is_valid_(false) {}
106
107             void advance_input()
108             {
109                 ++input_;
110                 input_is_valid_ = false;
111             }
112
113             result_type& get_input()
114             {
115                 if (!input_is_valid_) {
116                     curtok_ = *input_;
117                     input_is_valid_ = true;
118                 }
119                 return curtok_;
120             }
121
122             T input_;
123             result_type curtok_;
124             bool input_is_valid_;
125         };
126     };
127
128 }}}
129
130 #endif

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


Typeset in Trocchi and Trocchi Bold Sans Serif.