File indexing completed on 2024-11-15 09:31:20
0001
0002
0003
0004
0005
0006
0007
0008 #if !defined(BOOST_SPIRIT_STORED_RULE_HPP)
0009 #define BOOST_SPIRIT_STORED_RULE_HPP
0010
0011
0012 #include <boost/spirit/home/classic/namespace.hpp>
0013 #include <boost/spirit/home/classic/core/non_terminal/impl/rule.ipp>
0014 #include <boost/spirit/home/classic/dynamic/rule_alias.hpp>
0015 #include <boost/shared_ptr.hpp>
0016
0017 #include <boost/spirit/home/classic/dynamic/stored_rule_fwd.hpp>
0018
0019
0020 namespace boost { namespace spirit {
0021
0022 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0023
0024
0025
0026
0027
0028
0029 template <
0030 typename T0
0031 , typename T1
0032 , typename T2
0033 , bool EmbedByValue
0034 >
0035 class stored_rule
0036 : public impl::rule_base<
0037 stored_rule<T0, T1, T2, EmbedByValue>
0038 , typename mpl::if_c<
0039 EmbedByValue
0040 , stored_rule<T0, T1, T2, true>
0041 , stored_rule<T0, T1, T2> const&>::type
0042 , T0, T1, T2>
0043 {
0044 public:
0045
0046 typedef stored_rule<T0, T1, T2, EmbedByValue> self_t;
0047 typedef impl::rule_base<
0048 self_t
0049 , typename mpl::if_c<
0050 EmbedByValue
0051 , stored_rule<T0, T1, T2, true>
0052 , self_t const&>::type
0053 , T0, T1, T2>
0054 base_t;
0055
0056 typedef typename base_t::scanner_t scanner_t;
0057 typedef typename base_t::attr_t attr_t;
0058 typedef impl::abstract_parser<scanner_t, attr_t> abstract_parser_t;
0059 typedef rule_alias<self_t> alias_t;
0060
0061 stored_rule() : ptr() {}
0062 ~stored_rule() {}
0063
0064 stored_rule(stored_rule const& r)
0065 : ptr(r.ptr) {}
0066
0067 template <typename ParserT>
0068 stored_rule(ParserT const& p)
0069 : ptr(new impl::concrete_parser<ParserT, scanner_t, attr_t>(p)) {}
0070
0071 template <typename ParserT>
0072 stored_rule& operator=(ParserT const& p)
0073 {
0074 ptr.reset(new impl::concrete_parser<ParserT, scanner_t, attr_t>(p));
0075 return *this;
0076 }
0077
0078 stored_rule& operator=(stored_rule const& r)
0079 {
0080
0081
0082
0083 ptr = r.ptr;
0084 return *this;
0085 }
0086
0087 stored_rule<T0, T1, T2, true>
0088 copy() const
0089 {
0090 return stored_rule<T0, T1, T2, true>(ptr);
0091 }
0092
0093 alias_t
0094 alias() const
0095 {
0096 return alias_t(*this);
0097 }
0098
0099 private:
0100
0101 friend class impl::rule_base_access;
0102 friend class stored_rule<T0, T1, T2, !EmbedByValue>;
0103
0104 abstract_parser_t*
0105 get() const
0106 {
0107 return ptr.get();
0108 }
0109
0110 stored_rule(shared_ptr<abstract_parser_t> const& ptr)
0111 : ptr(ptr) {}
0112
0113 shared_ptr<abstract_parser_t> ptr;
0114 };
0115
0116
0117 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0118
0119 }}
0120
0121 #endif