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_STORED_RULE_HPP)
|
---|
10 | #define BOOST_SPIRIT_STORED_RULE_HPP
|
---|
11 |
|
---|
12 | ///////////////////////////////////////////////////////////////////////////////
|
---|
13 | #include <boost/spirit/core/non_terminal/impl/rule.ipp>
|
---|
14 | #include <boost/spirit/dynamic/rule_alias.hpp>
|
---|
15 | #include <boost/shared_ptr.hpp>
|
---|
16 |
|
---|
17 | ///////////////////////////////////////////////////////////////////////////////
|
---|
18 | namespace boost { namespace spirit {
|
---|
19 |
|
---|
20 | ///////////////////////////////////////////////////////////////////////////
|
---|
21 | //
|
---|
22 | // stored_rule class
|
---|
23 | //
|
---|
24 | ///////////////////////////////////////////////////////////////////////////
|
---|
25 | template <
|
---|
26 | typename T0 = nil_t
|
---|
27 | , typename T1 = nil_t
|
---|
28 | , typename T2 = nil_t
|
---|
29 | , bool EmbedByValue = false
|
---|
30 | >
|
---|
31 | class stored_rule
|
---|
32 | : public impl::rule_base<
|
---|
33 | stored_rule<T0, T1, T2, EmbedByValue>
|
---|
34 | , typename mpl::if_c<
|
---|
35 | EmbedByValue
|
---|
36 | , stored_rule<T0, T1, T2, true>
|
---|
37 | , stored_rule<T0, T1, T2> const&>::type
|
---|
38 | , T0, T1, T2>
|
---|
39 | {
|
---|
40 | public:
|
---|
41 |
|
---|
42 | typedef stored_rule<T0, T1, T2, EmbedByValue> self_t;
|
---|
43 | typedef impl::rule_base<
|
---|
44 | self_t
|
---|
45 | , typename mpl::if_c<
|
---|
46 | EmbedByValue
|
---|
47 | , stored_rule<T0, T1, T2, true>
|
---|
48 | , self_t const&>::type
|
---|
49 | , T0, T1, T2>
|
---|
50 | base_t;
|
---|
51 |
|
---|
52 | typedef typename base_t::scanner_t scanner_t;
|
---|
53 | typedef typename base_t::attr_t attr_t;
|
---|
54 | typedef impl::abstract_parser<scanner_t, attr_t> abstract_parser_t;
|
---|
55 | typedef rule_alias<self_t> alias_t;
|
---|
56 |
|
---|
57 | stored_rule() : ptr() {}
|
---|
58 | ~stored_rule() {}
|
---|
59 |
|
---|
60 | stored_rule(stored_rule const& r)
|
---|
61 | : ptr(r.ptr) {}
|
---|
62 |
|
---|
63 | template <typename ParserT>
|
---|
64 | stored_rule(ParserT const& p)
|
---|
65 | : ptr(new impl::concrete_parser<ParserT, scanner_t, attr_t>(p)) {}
|
---|
66 |
|
---|
67 | template <typename ParserT>
|
---|
68 | stored_rule& operator=(ParserT const& p)
|
---|
69 | {
|
---|
70 | ptr.reset(new impl::concrete_parser<ParserT, scanner_t, attr_t>(p));
|
---|
71 | return *this;
|
---|
72 | }
|
---|
73 |
|
---|
74 | stored_rule& operator=(stored_rule const& r)
|
---|
75 | {
|
---|
76 | // If this is placed above the templatized assignment
|
---|
77 | // operator, VC6 incorrectly complains ambiguity with
|
---|
78 | // r1 = r2, where r1 and r2 are both rules.
|
---|
79 | ptr = r.ptr;
|
---|
80 | return *this;
|
---|
81 | }
|
---|
82 |
|
---|
83 | stored_rule<T0, T1, T2, true>
|
---|
84 | copy() const
|
---|
85 | {
|
---|
86 | return stored_rule<T0, T1, T2, true>(ptr);
|
---|
87 | }
|
---|
88 |
|
---|
89 | alias_t
|
---|
90 | alias() const
|
---|
91 | {
|
---|
92 | return alias_t(*this);
|
---|
93 | }
|
---|
94 |
|
---|
95 | private:
|
---|
96 |
|
---|
97 | friend class impl::rule_base_access;
|
---|
98 | friend class stored_rule<T0, T1, T2, !EmbedByValue>;
|
---|
99 |
|
---|
100 | #if defined(__GNUC__) && (__GNUC__ < 3)
|
---|
101 | public:
|
---|
102 | #endif
|
---|
103 | abstract_parser_t*
|
---|
104 | get() const
|
---|
105 | {
|
---|
106 | return ptr.get();
|
---|
107 | }
|
---|
108 | #if defined(__GNUC__) && (__GNUC__ < 3)
|
---|
109 | private:
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | stored_rule(shared_ptr<abstract_parser_t> const& ptr)
|
---|
113 | : ptr(ptr) {}
|
---|
114 |
|
---|
115 | shared_ptr<abstract_parser_t> ptr;
|
---|
116 | };
|
---|
117 |
|
---|
118 | ///////////////////////////////////////////////////////////////////////////////
|
---|
119 | }} // namespace boost::spirit
|
---|
120 |
|
---|
121 | #endif
|
---|