source: NonGTP/Boost/boost/spirit/dynamic/rule_alias.hpp @ 857

Revision 857, 1.9 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 1998-2003 Joel de Guzman
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#if !defined(BOOST_SPIRIT_RULE_ALIAS_HPP)
10#define BOOST_SPIRIT_RULE_ALIAS_HPP
11
12#include <boost/spirit/core/parser.hpp>
13
14namespace boost { namespace spirit {
15
16    ///////////////////////////////////////////////////////////////////////////
17    //
18    //  rule_alias class
19    //
20    ///////////////////////////////////////////////////////////////////////////
21    template <typename ParserT>
22    class rule_alias :
23        public parser<rule_alias<ParserT> >
24    {
25    public:
26   
27        typedef rule_alias<ParserT> self_t;
28   
29        template <typename ScannerT>
30        struct result
31        {
32            typedef typename parser_result<ParserT, ScannerT>::type type;
33        };
34   
35        rule_alias()
36        : ptr(0) {}
37       
38        rule_alias(ParserT const& p)
39        : ptr(&p) {}
40       
41        rule_alias&
42        operator=(ParserT const& p)
43        {
44            ptr = &p;
45            return *this;
46        }
47   
48        template <typename ScannerT>
49        typename parser_result<ParserT, ScannerT>::type
50        parse(ScannerT const& scan) const
51        {
52            if (ptr)
53                return ptr->parse(scan);
54            else
55                return scan.no_match();
56        }
57       
58        ParserT const&
59        get() const
60        {
61            assert(ptr != 0);
62            return *ptr;
63        }
64   
65    private:
66   
67        ParserT const* ptr; // hold it by pointer
68    };
69
70}} // namespace boost::spirit
71
72#endif
Note: See TracBrowser for help on using the repository browser.