File indexing completed on 2025-01-18 09:46:32
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_PHOENIX_SCOPE_DYNAMIC_HPP
0010 #define BOOST_PHOENIX_SCOPE_DYNAMIC_HPP
0011
0012 #include <boost/phoenix/core/limits.hpp>
0013 #include <boost/assert.hpp>
0014 #include <boost/noncopyable.hpp>
0015 #include <boost/fusion/sequence/intrinsic/at.hpp>
0016 #include <boost/phoenix/core/expression.hpp>
0017 #include <boost/phoenix/core/meta_grammar.hpp>
0018 #include <boost/phoenix/core/call.hpp>
0019 #include <boost/phoenix/support/iterate.hpp>
0020 #include <boost/preprocessor/seq/for_each.hpp>
0021 #include <boost/preprocessor/seq/fold_left.hpp>
0022 #include <boost/preprocessor/punctuation/comma.hpp>
0023 #include <boost/type_traits/remove_pointer.hpp>
0024
0025 #define BOOST_PHOENIX_DYNAMIC_TEMPLATE_PARAMS(R, DATA, I, ELEM) \
0026 BOOST_PP_COMMA_IF(I) BOOST_PP_TUPLE_ELEM(2, 0, ELEM) \
0027
0028
0029 #define BOOST_PHOENIX_DYNAMIC_CTOR_INIT(R, DATA, I, ELEM) \
0030 BOOST_PP_COMMA_IF(I) BOOST_PP_TUPLE_ELEM(2, 1, ELEM)(init<I>(this)) \
0031
0032
0033 #define BOOST_PHOENIX_DYNAMIC_MEMBER(R, DATA, I, ELEM) \
0034 BOOST_PP_CAT(member, BOOST_PP_INC(I)) BOOST_PP_TUPLE_ELEM(2, 1, ELEM); \
0035
0036
0037 #define BOOST_PHOENIX_DYNAMIC_FILLER_0(X, Y) \
0038 ((X, Y)) BOOST_PHOENIX_DYNAMIC_FILLER_1 \
0039
0040
0041 #define BOOST_PHOENIX_DYNAMIC_FILLER_1(X, Y) \
0042 ((X, Y)) BOOST_PHOENIX_DYNAMIC_FILLER_0 \
0043
0044
0045 #define BOOST_PHOENIX_DYNAMIC_FILLER_0_END
0046 #define BOOST_PHOENIX_DYNAMIC_FILLER_1_END
0047
0048 #define BOOST_PHOENIX_DYNAMIC_BASE(NAME, MEMBER) \
0049 struct NAME \
0050 : ::boost::phoenix::dynamic< \
0051 BOOST_PP_SEQ_FOR_EACH_I( \
0052 BOOST_PHOENIX_DYNAMIC_TEMPLATE_PARAMS \
0053 , _ \
0054 , MEMBER) \
0055 > \
0056 { \
0057 NAME() \
0058 : BOOST_PP_SEQ_FOR_EACH_I(BOOST_PHOENIX_DYNAMIC_CTOR_INIT, _, MEMBER) \
0059 {} \
0060 \
0061 BOOST_PP_SEQ_FOR_EACH_I(BOOST_PHOENIX_DYNAMIC_MEMBER, _, MEMBER) \
0062 } \
0063
0064
0065 #define BOOST_PHOENIX_DYNAMIC(NAME, MEMBER) \
0066 BOOST_PHOENIX_DYNAMIC_BASE( \
0067 NAME \
0068 , BOOST_PP_CAT(BOOST_PHOENIX_DYNAMIC_FILLER_0 MEMBER,_END) \
0069 ) \
0070
0071
0072 BOOST_PHOENIX_DEFINE_EXPRESSION(
0073 (boost)(phoenix)(dynamic_member)
0074 , (proto::terminal<proto::_>)
0075 (proto::terminal<proto::_>)
0076 )
0077
0078 namespace boost { namespace phoenix
0079 {
0080 template <typename DynamicScope>
0081 struct dynamic_frame : noncopyable
0082 {
0083 typedef typename DynamicScope::tuple_type tuple_type;
0084
0085 dynamic_frame(DynamicScope const& s)
0086 : tuple()
0087 , save(s.frame)
0088 , scope(s)
0089 {
0090 scope.frame = this;
0091 }
0092
0093 template <typename Tuple>
0094 dynamic_frame(DynamicScope const& s, Tuple const& init)
0095 : tuple(init)
0096 , save(s.frame)
0097 , scope(s)
0098 {
0099 scope.frame = this;
0100 }
0101
0102 ~dynamic_frame()
0103 {
0104 scope.frame = save;
0105 }
0106
0107 tuple_type& data() { return tuple; }
0108 tuple_type const& data() const { return tuple; }
0109
0110 private:
0111 tuple_type tuple;
0112 dynamic_frame *save;
0113 DynamicScope const& scope;
0114 };
0115
0116 struct dynamic_member_eval
0117 {
0118 template <typename Sig>
0119 struct result;
0120
0121 template <typename This, typename N, typename Scope, typename Context>
0122 struct result<This(N, Scope, Context)>
0123 {
0124 typedef
0125 typename boost::remove_pointer<
0126 typename proto::detail::uncvref<
0127 typename proto::result_of::value<Scope>::type
0128 >::type
0129 >::type
0130 scope_type;
0131 typedef
0132 typename scope_type::dynamic_frame_type::tuple_type
0133 tuple_type;
0134
0135 typedef
0136 typename fusion::result_of::at_c<
0137 tuple_type
0138 , proto::detail::uncvref<
0139 typename proto::result_of::value<N>::type
0140 >::type::value
0141 >::type
0142 type;
0143
0144 };
0145
0146 template <typename N, typename Scope, typename Context>
0147 typename result<dynamic_member_eval(N, Scope, Context)>::type
0148 operator()(N, Scope s, Context const &) const
0149 {
0150 return
0151 fusion::at_c<
0152 proto::detail::uncvref<
0153 typename proto::result_of::value<N>::type
0154 >::type::value
0155 >(
0156 proto::value(s)->frame->data()
0157 );
0158 }
0159 };
0160
0161 template <typename Dummy>
0162 struct default_actions::when<rule::dynamic_member, Dummy>
0163 : call<dynamic_member_eval>
0164 {};
0165
0166
0167 template <
0168 BOOST_PHOENIX_typename_A_void(BOOST_PHOENIX_DYNAMIC_LIMIT)
0169 , typename Dummy = void
0170 >
0171 struct dynamic;
0172
0173
0174 #include <boost/phoenix/scope/detail/cpp03/dynamic.hpp>
0175
0176
0177
0178 }}
0179
0180 #endif