Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:32

0001 #ifndef BOOST_STATECHART_RESULT_HPP_INCLUDED
0002 #define BOOST_STATECHART_RESULT_HPP_INCLUDED
0003 //////////////////////////////////////////////////////////////////////////////
0004 // Copyright 2002-2010 Andreas Huber Doenni
0005 // Distributed under the Boost Software License, Version 1.0. (See accompany-
0006 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 //////////////////////////////////////////////////////////////////////////////
0008 
0009 
0010 
0011 #include <boost/assert.hpp>
0012 
0013 
0014 
0015 namespace boost
0016 {
0017 namespace statechart
0018 {
0019 namespace detail
0020 {
0021 
0022 
0023 
0024 //////////////////////////////////////////////////////////////////////////////
0025 enum reaction_result
0026 {
0027   no_reaction,
0028   do_forward_event,
0029   do_discard_event,
0030   do_defer_event,
0031   consumed
0032 };
0033 
0034 struct result_utility;
0035 
0036 //////////////////////////////////////////////////////////////////////////////
0037 class safe_reaction_result
0038 {
0039   public:
0040     //////////////////////////////////////////////////////////////////////////
0041     safe_reaction_result( const safe_reaction_result & other ) :
0042       reactionResult_( other.reactionResult_ )
0043     {
0044       // This assert fails when an attempt is made to make multiple copies of
0045       // a result value. This makes little sense, given the requirement that
0046       // an obtained result value must be returned out of the react function.
0047       BOOST_ASSERT( reactionResult_ != consumed );
0048       other.reactionResult_ = consumed;
0049     }
0050 
0051     ~safe_reaction_result()
0052     {
0053       // This assert fails when an obtained result value is not returned out
0054       // of the react() function. This can happen if the user accidentally
0055       // makes more than one call to reaction functions inside react() or
0056       // accidentally makes one or more calls to reaction functions outside
0057       // react()
0058       BOOST_ASSERT( reactionResult_ == consumed );
0059     }
0060 
0061   private:
0062     //////////////////////////////////////////////////////////////////////////
0063     safe_reaction_result( reaction_result reactionResult ) :
0064       reactionResult_( reactionResult )
0065     {
0066     }
0067 
0068     operator reaction_result() const
0069     {
0070       const reaction_result val = reactionResult_;
0071       reactionResult_ = consumed;
0072       return val;
0073     }
0074 
0075     safe_reaction_result & operator=( const safe_reaction_result & );
0076 
0077     mutable reaction_result reactionResult_;
0078 
0079     friend struct result_utility;
0080 };
0081 
0082 
0083 
0084 } // namespace detail
0085 
0086 
0087 
0088 #ifdef NDEBUG
0089   typedef detail::reaction_result result;
0090 #else
0091   typedef detail::safe_reaction_result result;
0092 #endif
0093 
0094 
0095 namespace detail
0096 {
0097 
0098 
0099 
0100 //////////////////////////////////////////////////////////////////////////////
0101 struct result_utility
0102 {
0103   static ::boost::statechart::result make_result( reaction_result value )
0104   {
0105     return value;
0106   }
0107 
0108   static reaction_result get_result( ::boost::statechart::result value )
0109   {
0110     return value;
0111   }
0112 };
0113 
0114 
0115 
0116 } // namespace detail
0117 } // namespace statechart
0118 } // namespace boost
0119 
0120 
0121 
0122 #endif