comparison DEPENDENCIES/generic/include/boost/spirit/home/phoenix/statement/try_catch.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /*=============================================================================
2 Copyright (c) 2005-2007 Dan Marsden
3 Copyright (c) 2005-2007 Joel de Guzman
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8
9 #ifndef PHOENIX_STATEMENT_TRY_CATCH_HPP
10 #define PHOENIX_STATEMENT_TRY_CATCH_HPP
11
12 #include <boost/spirit/home/phoenix/core/actor.hpp>
13 #include <boost/spirit/home/phoenix/core/composite.hpp>
14
15 #include <boost/fusion/include/push_back.hpp>
16 #include <boost/fusion/include/as_vector.hpp>
17
18 #include <boost/spirit/home/phoenix/statement/detail/catch_composite.hpp>
19 #include <boost/spirit/home/phoenix/statement/detail/catch_eval.hpp>
20 #include <boost/spirit/home/phoenix/statement/detail/catch_all_eval.hpp>
21
22 #if defined(BOOST_MSVC)
23 # pragma warning(push)
24 # pragma warning(disable:4355)
25 #endif
26
27 namespace boost { namespace phoenix {
28
29 template<typename Tuple> struct try_catch_composite;
30
31 namespace meta
32 {
33 template<typename Composite, typename Actor>
34 struct try_catch_composite_push_back
35 {
36 typedef typename Composite::base_type actor_tuple;
37 typedef try_catch_composite<
38 typename fusion::result_of::as_vector<
39 typename fusion::result_of::push_back<
40 actor_tuple, Actor>::type>::type> type;
41 };
42
43 template<typename Composite, typename Actor>
44 struct catch_all_composite_push_back
45 {
46 typedef typename Composite::base_type actor_tuple;
47
48 typedef composite<
49 catch_all_eval,
50 typename fusion::result_of::as_vector<
51 typename fusion::result_of::push_back<
52 actor_tuple, Actor>::type>::type> type;
53 };
54 }
55
56 namespace detail
57 {
58 struct try_catch_composite_push_back
59 {
60 template<typename Composite, typename Actor>
61 struct result
62 : meta::try_catch_composite_push_back<Composite, Actor>
63 {};
64
65 template<typename Composite, typename Actor>
66 typename result<Composite, Actor>::type
67 operator()(
68 const Composite& composite, const Actor& actor) const
69 {
70 typedef typename result<Composite, Actor>::type result;
71 return result(
72 fusion::as_vector(
73 fusion::push_back(composite, actor)));
74 }
75 };
76
77 struct catch_all_composite_push_back
78 {
79 template<typename Composite, typename Actor>
80 struct result
81 : meta::catch_all_composite_push_back<Composite, Actor>
82 {};
83
84 template<typename Composite, typename Actor>
85 typename result<Composite, Actor>::type
86 operator()(
87 const Composite& composite, const Actor& actor) const
88 {
89 typedef typename result<Composite, Actor>::type result;
90 return result(
91 fusion::as_vector(
92 fusion::push_back(composite, actor)));
93 }
94 };
95
96 }
97
98 detail::try_catch_composite_push_back const try_catch_composite_push_back
99 = detail::try_catch_composite_push_back();
100 detail::catch_all_composite_push_back const catch_all_composite_push_back
101 = detail::catch_all_composite_push_back();
102
103 template<typename Exception, typename SourceComposite>
104 struct catch_gen
105 {
106 explicit catch_gen(
107 const SourceComposite& sourceComposite)
108 : mSourceComposite(sourceComposite) { }
109
110 template<typename Actor>
111 actor<typename meta::try_catch_composite_push_back<
112 SourceComposite,
113 detail::catch_composite<Exception, Actor> >::type>
114 operator[](const Actor& actor) const
115 {
116 return try_catch_composite_push_back(
117 mSourceComposite, detail::catch_composite<Exception, Actor>(actor));
118 }
119
120 const SourceComposite& mSourceComposite;
121 };
122
123 template<typename SourceComposite>
124 struct catch_all_gen
125 {
126 explicit catch_all_gen(
127 const SourceComposite& sourceComposite)
128 : mSourceComposite(sourceComposite) { }
129
130 template<typename Actor>
131 actor<typename meta::catch_all_composite_push_back<SourceComposite, Actor>::type>
132 operator[](const Actor& actor) const
133 {
134 return catch_all_composite_push_back(
135 mSourceComposite, actor);
136 }
137
138 const SourceComposite& mSourceComposite;
139 };
140
141 template<typename Tuple>
142 struct try_catch_composite
143 : composite<catch_eval, Tuple>
144 {
145 explicit try_catch_composite(
146 const Tuple& t)
147 :
148 composite<catch_eval, Tuple>(t),
149 catch_all(*this) { }
150
151 try_catch_composite(
152 const try_catch_composite& rhs)
153 : composite<catch_eval, Tuple>(rhs),
154 catch_all(*this) { }
155
156 template<typename Exception>
157 catch_gen<Exception, try_catch_composite> catch_() const
158 {
159 return catch_gen<Exception, try_catch_composite>(
160 *this);
161 }
162
163 const catch_all_gen<try_catch_composite> catch_all;
164
165 private:
166 try_catch_composite& operator=(const try_catch_composite&);
167 };
168
169 struct try_gen
170 {
171 template<typename Try>
172 try_catch_composite<fusion::vector<Try> > operator[](
173 const Try& try_) const
174 {
175 typedef fusion::vector<Try> tuple_type;
176 return try_catch_composite<tuple_type>(
177 tuple_type(try_));
178 }
179 };
180
181 try_gen const try_ = try_gen();
182 }}
183
184 #if defined(BOOST_MSVC)
185 # pragma warning(pop)
186 #endif
187
188 #endif