1 | /////////////////////////////////////////////////////////////////////////////// |
---|
2 | /// \file branch.hpp |
---|
3 | /// A special-purpose proto compiler for compiling one branch of the expression |
---|
4 | /// tree separately from the rest. Given an expression and a proto lambda, it |
---|
5 | /// compiles the expression using an initial state determined by the lambda. |
---|
6 | /// It then passes the result along with the current state and the visitor |
---|
7 | /// to the lambda for further processing. |
---|
8 | // |
---|
9 | // Copyright 2004 Eric Niebler. Distributed under the Boost |
---|
10 | // Software License, Version 1.0. (See accompanying file |
---|
11 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
12 | |
---|
13 | #ifndef BOOST_PROTO_COMPILER_BRANCH_HPP_EAN_04_01_2005 |
---|
14 | #define BOOST_PROTO_COMPILER_BRANCH_HPP_EAN_04_01_2005 |
---|
15 | |
---|
16 | #include <boost/xpressive/proto/proto_fwd.hpp> |
---|
17 | |
---|
18 | namespace boost { namespace proto |
---|
19 | { |
---|
20 | |
---|
21 | /////////////////////////////////////////////////////////////////////////////// |
---|
22 | // branch_compiler |
---|
23 | template<typename Lambda, typename DomainTag> |
---|
24 | struct branch_compiler |
---|
25 | { |
---|
26 | template<typename Op, typename State, typename Visitor> |
---|
27 | struct apply |
---|
28 | { |
---|
29 | typedef proto::compiler<typename tag_type<Op>::type, DomainTag> compiler_type; |
---|
30 | |
---|
31 | // Compile the branch |
---|
32 | typedef typename compiler_type::BOOST_NESTED_TEMPLATE apply |
---|
33 | < |
---|
34 | Op |
---|
35 | , typename Lambda::state_type |
---|
36 | , Visitor |
---|
37 | >::type branch_type; |
---|
38 | |
---|
39 | // Pass the branch, state and visitor to the lambda |
---|
40 | typedef typename Lambda::BOOST_NESTED_TEMPLATE apply |
---|
41 | < |
---|
42 | branch_type |
---|
43 | , State |
---|
44 | , Visitor |
---|
45 | >::type type; |
---|
46 | }; |
---|
47 | |
---|
48 | template<typename Op, typename State, typename Visitor> |
---|
49 | static typename apply<Op, State, Visitor>::type |
---|
50 | call(Op const &op, State const &state, Visitor &visitor) |
---|
51 | { |
---|
52 | return Lambda::call |
---|
53 | ( |
---|
54 | proto::compile(op, typename Lambda::state_type(), visitor, DomainTag()) |
---|
55 | , state |
---|
56 | , visitor |
---|
57 | ); |
---|
58 | } |
---|
59 | }; |
---|
60 | |
---|
61 | }} |
---|
62 | |
---|
63 | #endif |
---|