1 | #ifndef BOOST_STATECHART_EXCEPTION_TRANSLATOR_HPP_INCLUDED |
---|
2 | #define BOOST_STATECHART_EXCEPTION_TRANSLATOR_HPP_INCLUDED |
---|
3 | ////////////////////////////////////////////////////////////////////////////// |
---|
4 | // Copyright 2002-2006 Andreas Huber Doenni |
---|
5 | // Distributed under the Boost Software License, Version 1.0. (See accompany- |
---|
6 | // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | ////////////////////////////////////////////////////////////////////////////// |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | #include <boost/statechart/event.hpp> |
---|
12 | #include <boost/statechart/result.hpp> |
---|
13 | |
---|
14 | |
---|
15 | |
---|
16 | namespace boost |
---|
17 | { |
---|
18 | namespace statechart |
---|
19 | { |
---|
20 | |
---|
21 | |
---|
22 | |
---|
23 | ////////////////////////////////////////////////////////////////////////////// |
---|
24 | class exception_thrown : public event< exception_thrown > {}; |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | ////////////////////////////////////////////////////////////////////////////// |
---|
29 | template< class ExceptionEvent = exception_thrown > |
---|
30 | class exception_translator |
---|
31 | { |
---|
32 | public: |
---|
33 | ////////////////////////////////////////////////////////////////////////// |
---|
34 | // The following declarations should be private. |
---|
35 | // They are only public because many compilers lack template friends. |
---|
36 | ////////////////////////////////////////////////////////////////////////// |
---|
37 | template< class Action, class ExceptionEventHandler > |
---|
38 | result operator()( Action action, ExceptionEventHandler eventHandler ) |
---|
39 | { |
---|
40 | try |
---|
41 | { |
---|
42 | return action(); |
---|
43 | } |
---|
44 | catch ( ... ) |
---|
45 | { |
---|
46 | return eventHandler( ExceptionEvent() ); |
---|
47 | } |
---|
48 | } |
---|
49 | }; |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | } // namespace statechart |
---|
54 | } // namespace boost |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | #endif |
---|