Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/spirit/dynamic/stored_rule.hpp @ 33

Last change on this file since 33 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

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