1 /*=============================================================================
2 Copyright (c) 1998-2003 Joel de Guzman
3 http://spirit.sourceforge.net/
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 =============================================================================*/
8 #if !defined(BOOST_SPIRIT_STORED_RULE_HPP)
9 #define BOOST_SPIRIT_STORED_RULE_HPP
11 ///////////////////////////////////////////////////////////////////////////////
12 #include <boost/spirit/home/classic/namespace.hpp>
13 #include <boost/spirit/home/classic/core/non_terminal/impl/rule.ipp>
14 #include <boost/spirit/home/classic/dynamic/rule_alias.hpp>
15 #include <boost/shared_ptr.hpp>
17 #include <boost/spirit/home/classic/dynamic/stored_rule_fwd.hpp>
19 ///////////////////////////////////////////////////////////////////////////////
20 namespace boost { namespace spirit {
22 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
24 ///////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////
36 : public impl::rule_base<
37 stored_rule<T0, T1, T2, EmbedByValue>
40 , stored_rule<T0, T1, T2, true>
41 , stored_rule<T0, T1, T2> const&>::type
46 typedef stored_rule<T0, T1, T2, EmbedByValue> self_t;
47 typedef impl::rule_base<
51 , stored_rule<T0, T1, T2, true>
52 , self_t const&>::type
56 typedef typename base_t::scanner_t scanner_t;
57 typedef typename base_t::attr_t attr_t;
58 typedef impl::abstract_parser<scanner_t, attr_t> abstract_parser_t;
59 typedef rule_alias<self_t> alias_t;
61 stored_rule() : ptr() {}
64 stored_rule(stored_rule const& r)
67 template <typename ParserT>
68 stored_rule(ParserT const& p)
69 : ptr(new impl::concrete_parser<ParserT, scanner_t, attr_t>(p)) {}
71 template <typename ParserT>
72 stored_rule& operator=(ParserT const& p)
74 ptr.reset(new impl::concrete_parser<ParserT, scanner_t, attr_t>(p));
78 stored_rule& operator=(stored_rule const& r)
80 // If this is placed above the templatized assignment
81 // operator, VC6 incorrectly complains ambiguity with
82 // r1 = r2, where r1 and r2 are both rules.
87 stored_rule<T0, T1, T2, true>
90 return stored_rule<T0, T1, T2, true>(ptr);
96 return alias_t(*this);
101 friend class impl::rule_base_access;
102 friend class stored_rule<T0, T1, T2, !EmbedByValue>;
110 stored_rule(shared_ptr<abstract_parser_t> const& ptr)
113 shared_ptr<abstract_parser_t> ptr;
116 ///////////////////////////////////////////////////////////////////////////////
117 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
119 }} // namespace BOOST_SPIRIT_CLASSIC_NS