os/ossrv/ossrv_pub/boost_apis/boost/statechart/result.hpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
#ifndef BOOST_STATECHART_RESULT_HPP_INCLUDED
sl@0
     2
#define BOOST_STATECHART_RESULT_HPP_INCLUDED
sl@0
     3
//////////////////////////////////////////////////////////////////////////////
sl@0
     4
// Copyright 2002-2006 Andreas Huber Doenni
sl@0
     5
// Distributed under the Boost Software License, Version 1.0. (See accompany-
sl@0
     6
// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
sl@0
     7
//////////////////////////////////////////////////////////////////////////////
sl@0
     8
sl@0
     9
sl@0
    10
sl@0
    11
#include <boost/assert.hpp>
sl@0
    12
sl@0
    13
sl@0
    14
sl@0
    15
namespace boost
sl@0
    16
{
sl@0
    17
namespace statechart
sl@0
    18
{
sl@0
    19
namespace detail
sl@0
    20
{
sl@0
    21
sl@0
    22
sl@0
    23
sl@0
    24
//////////////////////////////////////////////////////////////////////////////
sl@0
    25
enum reaction_result
sl@0
    26
{
sl@0
    27
  no_reaction,
sl@0
    28
  do_forward_event,
sl@0
    29
  do_discard_event,
sl@0
    30
  do_defer_event,
sl@0
    31
  consumed
sl@0
    32
};
sl@0
    33
sl@0
    34
struct result_utility;
sl@0
    35
sl@0
    36
//////////////////////////////////////////////////////////////////////////////
sl@0
    37
class safe_reaction_result
sl@0
    38
{
sl@0
    39
  public:
sl@0
    40
    //////////////////////////////////////////////////////////////////////////
sl@0
    41
    safe_reaction_result( const safe_reaction_result & other ) :
sl@0
    42
      reactionResult( other.reactionResult )
sl@0
    43
    {
sl@0
    44
      // This assert fails when an attempt is made to make multiple copies of
sl@0
    45
      // a result value. This makes little sense, given the requirement that
sl@0
    46
      // an obtained result value must be returned out of the react function.
sl@0
    47
      BOOST_ASSERT( reactionResult != consumed );
sl@0
    48
      other.reactionResult = consumed;
sl@0
    49
    }
sl@0
    50
sl@0
    51
    ~safe_reaction_result()
sl@0
    52
    {
sl@0
    53
      // This assert fails when an obtained result value is not returned out
sl@0
    54
      // of the react() function. This can happen if the user accidentally
sl@0
    55
      // makes more than one call to reaction functions inside react() or
sl@0
    56
      // accidentally makes one or more calls to reaction functions outside
sl@0
    57
      // react()
sl@0
    58
      BOOST_ASSERT( reactionResult == consumed );
sl@0
    59
    }
sl@0
    60
sl@0
    61
  private:
sl@0
    62
    //////////////////////////////////////////////////////////////////////////
sl@0
    63
    safe_reaction_result( reaction_result reactionResult ) :
sl@0
    64
      reactionResult( reactionResult )
sl@0
    65
    {
sl@0
    66
    }
sl@0
    67
sl@0
    68
    operator reaction_result() const
sl@0
    69
    {
sl@0
    70
      const reaction_result val = reactionResult;
sl@0
    71
      reactionResult = consumed;
sl@0
    72
      return val;
sl@0
    73
    }
sl@0
    74
sl@0
    75
    safe_reaction_result & operator=( const safe_reaction_result & );
sl@0
    76
sl@0
    77
    mutable reaction_result reactionResult;
sl@0
    78
sl@0
    79
    friend struct result_utility;
sl@0
    80
};
sl@0
    81
sl@0
    82
sl@0
    83
sl@0
    84
} // namespace detail
sl@0
    85
sl@0
    86
sl@0
    87
sl@0
    88
#ifdef NDEBUG
sl@0
    89
  typedef detail::reaction_result result;
sl@0
    90
#else
sl@0
    91
  typedef detail::safe_reaction_result result;
sl@0
    92
#endif
sl@0
    93
sl@0
    94
sl@0
    95
namespace detail
sl@0
    96
{
sl@0
    97
sl@0
    98
sl@0
    99
sl@0
   100
//////////////////////////////////////////////////////////////////////////////
sl@0
   101
struct result_utility
sl@0
   102
{
sl@0
   103
  static ::boost::statechart::result make_result( reaction_result value )
sl@0
   104
  {
sl@0
   105
    return value;
sl@0
   106
  }
sl@0
   107
sl@0
   108
  static reaction_result get_result( ::boost::statechart::result value )
sl@0
   109
  {
sl@0
   110
    return value;
sl@0
   111
  }
sl@0
   112
};
sl@0
   113
sl@0
   114
sl@0
   115
sl@0
   116
} // namespace detail
sl@0
   117
} // namespace statechart
sl@0
   118
} // namespace boost
sl@0
   119
sl@0
   120
sl@0
   121
sl@0
   122
#endif