1 /*==============================================================================
2 Copyright (c) 2001-2010 Joel de Guzman
3 Copyright (c) 2004 Daniel Wallin
4 Copyright (c) 2010 Thomas Heller
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 ==============================================================================*/
9 #ifndef BOOST_PHOENIX_SCOPE_DYNAMIC_HPP
10 #define BOOST_PHOENIX_SCOPE_DYNAMIC_HPP
12 #include <boost/phoenix/core/limits.hpp>
13 #include <boost/assert.hpp>
14 #include <boost/noncopyable.hpp>
15 #include <boost/fusion/sequence/intrinsic/at.hpp>
16 #include <boost/phoenix/core/expression.hpp>
17 #include <boost/phoenix/core/meta_grammar.hpp>
18 #include <boost/phoenix/core/call.hpp>
19 #include <boost/phoenix/support/iterate.hpp>
20 #include <boost/preprocessor/seq/for_each.hpp>
21 #include <boost/preprocessor/seq/fold_left.hpp>
22 #include <boost/preprocessor/punctuation/comma.hpp>
23 #include <boost/type_traits/remove_pointer.hpp>
25 #define BOOST_PHOENIX_DYNAMIC_TEMPLATE_PARAMS(R, DATA, I, ELEM) \
26 BOOST_PP_COMMA_IF(I) BOOST_PP_TUPLE_ELEM(2, 0, ELEM) \
29 #define BOOST_PHOENIX_DYNAMIC_CTOR_INIT(R, DATA, I, ELEM) \
30 BOOST_PP_COMMA_IF(I) BOOST_PP_TUPLE_ELEM(2, 1, ELEM)(init<I>(this)) \
33 #define BOOST_PHOENIX_DYNAMIC_MEMBER(R, DATA, I, ELEM) \
34 BOOST_PP_CAT(member, BOOST_PP_INC(I)) BOOST_PP_TUPLE_ELEM(2, 1, ELEM); \
37 #define BOOST_PHOENIX_DYNAMIC_FILLER_0(X, Y) \
38 ((X, Y)) BOOST_PHOENIX_DYNAMIC_FILLER_1 \
41 #define BOOST_PHOENIX_DYNAMIC_FILLER_1(X, Y) \
42 ((X, Y)) BOOST_PHOENIX_DYNAMIC_FILLER_0 \
45 #define BOOST_PHOENIX_DYNAMIC_FILLER_0_END
46 #define BOOST_PHOENIX_DYNAMIC_FILLER_1_END
48 #define BOOST_PHOENIX_DYNAMIC_BASE(NAME, MEMBER) \
50 : ::boost::phoenix::dynamic< \
51 BOOST_PP_SEQ_FOR_EACH_I( \
52 BOOST_PHOENIX_DYNAMIC_TEMPLATE_PARAMS \
58 : BOOST_PP_SEQ_FOR_EACH_I(BOOST_PHOENIX_DYNAMIC_CTOR_INIT, _, MEMBER) \
61 BOOST_PP_SEQ_FOR_EACH_I(BOOST_PHOENIX_DYNAMIC_MEMBER, _, MEMBER) \
65 #define BOOST_PHOENIX_DYNAMIC(NAME, MEMBER) \
66 BOOST_PHOENIX_DYNAMIC_BASE( \
68 , BOOST_PP_CAT(BOOST_PHOENIX_DYNAMIC_FILLER_0 MEMBER,_END) \
72 BOOST_PHOENIX_DEFINE_EXPRESSION(
73 (boost)(phoenix)(dynamic_member)
74 , (proto::terminal<proto::_>)
75 (proto::terminal<proto::_>)
78 namespace boost { namespace phoenix
80 template <typename DynamicScope>
81 struct dynamic_frame : noncopyable
83 typedef typename DynamicScope::tuple_type tuple_type;
85 dynamic_frame(DynamicScope const& s)
93 template <typename Tuple>
94 dynamic_frame(DynamicScope const& s, Tuple const& init)
107 tuple_type& data() { return tuple; }
108 tuple_type const& data() const { return tuple; }
113 DynamicScope const& scope;
116 struct dynamic_member_eval
118 template <typename Sig>
121 template <typename This, typename N, typename Scope, typename Context>
122 struct result<This(N, Scope, Context)>
125 typename boost::remove_pointer<
126 typename proto::detail::uncvref<
127 typename proto::result_of::value<Scope>::type
132 typename scope_type::dynamic_frame_type::tuple_type
136 typename fusion::result_of::at_c<
138 , proto::detail::uncvref<
139 typename proto::result_of::value<N>::type
146 template <typename N, typename Scope, typename Context>
147 typename result<dynamic_member_eval(N, Scope, Context)>::type
148 operator()(N, Scope s, Context const &) const
152 proto::detail::uncvref<
153 typename proto::result_of::value<N>::type
156 proto::value(s)->frame->data()
161 template <typename Dummy>
162 struct default_actions::when<rule::dynamic_member, Dummy>
163 : call<dynamic_member_eval>
167 BOOST_PHOENIX_typename_A_void(BOOST_PHOENIX_DYNAMIC_LIMIT)
168 , typename Dummy = void
172 // Bring in the rest ...
173 #include <boost/phoenix/scope/detail/dynamic.hpp>