source: NonGTP/Boost/boost/spirit/utility/flush_multi_pass.hpp @ 857

Revision 857, 2.6 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 2001-2003 Daniel Nuffer
3    http://spirit.sourceforge.net/
4
5    Use, modification and distribution is subject to the Boost Software
6    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7    http://www.boost.org/LICENSE_1_0.txt)
8=============================================================================*/
9#ifndef BOOST_SPIRIT_FLUSH_MULTI_PASS_HPP
10#define BOOST_SPIRIT_FLUSH_MULTI_PASS_HPP
11
12///////////////////////////////////////////////////////////////////////////////
13#include <boost/spirit/core.hpp>
14#include <boost/spirit/iterator/multi_pass.hpp>
15
16///////////////////////////////////////////////////////////////////////////////
17namespace boost { namespace spirit {
18
19    namespace impl {
20
21        template <typename T>
22        void flush_iterator(T &) {}
23
24        template <typename T1, typename T2, typename T3, typename T4>
25        void flush_iterator(boost::spirit::multi_pass<
26            T1, T2, T3, T4, boost::spirit::multi_pass_policies::std_deque> &i)
27        {
28            i.clear_queue();
29        }
30
31    }   // namespace impl
32
33    ///////////////////////////////////////////////////////////////////////////
34    //
35    //  flush_multi_pass_parser
36    //
37    //      The flush_multi_pass_parser flushes an underlying
38    //      multi_pass_iterator during the normal parsing process. This may
39    //      be used at certain points during the parsing process, when it is
40    //      clear, that no backtracking is needed anymore and the input
41    //      gathered so far may be discarded.
42    //
43    ///////////////////////////////////////////////////////////////////////////
44    class flush_multi_pass_parser
45    :   public parser<flush_multi_pass_parser>
46    {
47    public:
48        typedef flush_multi_pass_parser this_t;
49
50        template <typename ScannerT>
51        typename parser_result<this_t, ScannerT>::type
52        parse(ScannerT const& scan) const
53        {
54            impl::flush_iterator(scan.first);
55            return scan.empty_match();
56        }
57    };
58
59    ///////////////////////////////////////////////////////////////////////////
60    //
61    //  predefined flush_multi_pass_p object
62    //
63    //      This object should may used to flush a multi_pass_iterator along
64    //      the way during the normal parsing process.
65    //
66    ///////////////////////////////////////////////////////////////////////////
67
68    flush_multi_pass_parser const
69        flush_multi_pass_p = flush_multi_pass_parser();
70
71}} // namespace boost::spirit
72
73#endif // BOOST_SPIRIT_FLUSH_MULTI_PASS_HPP
Note: See TracBrowser for help on using the repository browser.