fix doc example typo
[boost.git] / boost / statechart / result.hpp
blob35dd023de29dc325139f230f9061bbeca2849419
1 #ifndef BOOST_STATECHART_RESULT_HPP_INCLUDED
2 #define BOOST_STATECHART_RESULT_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 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/assert.hpp>
15 namespace boost
17 namespace statechart
19 namespace detail
24 //////////////////////////////////////////////////////////////////////////////
25 enum reaction_result
27 no_reaction,
28 do_forward_event,
29 do_discard_event,
30 do_defer_event,
31 consumed
34 struct result_utility;
36 //////////////////////////////////////////////////////////////////////////////
37 class safe_reaction_result
39 public:
40 //////////////////////////////////////////////////////////////////////////
41 safe_reaction_result( const safe_reaction_result & other ) :
42 reactionResult( other.reactionResult )
44 // This assert fails when an attempt is made to make multiple copies of
45 // a result value. This makes little sense, given the requirement that
46 // an obtained result value must be returned out of the react function.
47 BOOST_ASSERT( reactionResult != consumed );
48 other.reactionResult = consumed;
51 ~safe_reaction_result()
53 // This assert fails when an obtained result value is not returned out
54 // of the react() function. This can happen if the user accidentally
55 // makes more than one call to reaction functions inside react() or
56 // accidentally makes one or more calls to reaction functions outside
57 // react()
58 BOOST_ASSERT( reactionResult == consumed );
61 private:
62 //////////////////////////////////////////////////////////////////////////
63 safe_reaction_result( reaction_result reactionResult ) :
64 reactionResult( reactionResult )
68 operator reaction_result() const
70 const reaction_result val = reactionResult;
71 reactionResult = consumed;
72 return val;
75 safe_reaction_result & operator=( const safe_reaction_result & );
77 mutable reaction_result reactionResult;
79 friend struct result_utility;
84 } // namespace detail
88 #ifdef NDEBUG
89 typedef detail::reaction_result result;
90 #else
91 typedef detail::safe_reaction_result result;
92 #endif
95 namespace detail
100 //////////////////////////////////////////////////////////////////////////////
101 struct result_utility
103 static ::boost::statechart::result make_result( reaction_result value )
105 return value;
108 static reaction_result get_result( ::boost::statechart::result value )
110 return value;
116 } // namespace detail
117 } // namespace statechart
118 } // namespace boost
122 #endif