os/ossrv/ossrv_pub/boost_apis/boost/statechart/state.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#ifndef BOOST_STATECHART_STATE_HPP_INCLUDED
sl@0
     2
#define BOOST_STATECHART_STATE_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/statechart/simple_state.hpp>
sl@0
    12
sl@0
    13
#include <boost/mpl/list.hpp>
sl@0
    14
sl@0
    15
sl@0
    16
sl@0
    17
namespace boost
sl@0
    18
{
sl@0
    19
namespace statechart
sl@0
    20
{
sl@0
    21
sl@0
    22
sl@0
    23
sl@0
    24
template< class MostDerived,
sl@0
    25
          class Context,
sl@0
    26
          class InnerInitial = mpl::list<>,
sl@0
    27
          history_mode historyMode = has_no_history >
sl@0
    28
class state : public simple_state<
sl@0
    29
  MostDerived, Context, InnerInitial, historyMode >
sl@0
    30
{
sl@0
    31
  typedef simple_state< MostDerived, Context, InnerInitial, historyMode >
sl@0
    32
    base_type;
sl@0
    33
sl@0
    34
  protected:
sl@0
    35
    //////////////////////////////////////////////////////////////////////////
sl@0
    36
    struct my_context
sl@0
    37
    {
sl@0
    38
      my_context( typename base_type::context_ptr_type pContext ) :
sl@0
    39
        pContext_( pContext )
sl@0
    40
      {
sl@0
    41
      }
sl@0
    42
sl@0
    43
      typename base_type::context_ptr_type pContext_;
sl@0
    44
    };
sl@0
    45
sl@0
    46
    typedef state my_base;
sl@0
    47
sl@0
    48
    state( my_context ctx )
sl@0
    49
    {
sl@0
    50
      this->set_context( ctx.pContext_ );
sl@0
    51
    }
sl@0
    52
sl@0
    53
    ~state() {}
sl@0
    54
sl@0
    55
  public:
sl@0
    56
    //////////////////////////////////////////////////////////////////////////
sl@0
    57
    // The following declarations should be private.
sl@0
    58
    // They are only public because many compilers lack template friends.
sl@0
    59
    //////////////////////////////////////////////////////////////////////////
sl@0
    60
    // See base class for documentation
sl@0
    61
    typedef typename base_type::outermost_context_base_type
sl@0
    62
      outermost_context_base_type;
sl@0
    63
    typedef typename base_type::inner_context_ptr_type inner_context_ptr_type;
sl@0
    64
    typedef typename base_type::context_ptr_type context_ptr_type;
sl@0
    65
    typedef typename base_type::inner_initial_list inner_initial_list;
sl@0
    66
sl@0
    67
    static void initial_deep_construct(
sl@0
    68
      outermost_context_base_type & outermostContextBase )
sl@0
    69
    {
sl@0
    70
      deep_construct( &outermostContextBase, outermostContextBase );
sl@0
    71
    }
sl@0
    72
sl@0
    73
    // See base class for documentation
sl@0
    74
    static void deep_construct(
sl@0
    75
      const context_ptr_type & pContext,
sl@0
    76
      outermost_context_base_type & outermostContextBase )
sl@0
    77
    {
sl@0
    78
      const inner_context_ptr_type pInnerContext(
sl@0
    79
        shallow_construct( pContext, outermostContextBase ) );
sl@0
    80
      base_type::template deep_construct_inner< inner_initial_list >(
sl@0
    81
        pInnerContext, outermostContextBase );
sl@0
    82
    }
sl@0
    83
sl@0
    84
    static inner_context_ptr_type shallow_construct(
sl@0
    85
      const context_ptr_type & pContext,
sl@0
    86
      outermost_context_base_type & outermostContextBase )
sl@0
    87
    {
sl@0
    88
      const inner_context_ptr_type pInnerContext(
sl@0
    89
        new MostDerived( my_context( pContext ) ) );
sl@0
    90
      outermostContextBase.add( pInnerContext );
sl@0
    91
      return pInnerContext;
sl@0
    92
    }
sl@0
    93
};
sl@0
    94
sl@0
    95
sl@0
    96
sl@0
    97
} // namespace statechart
sl@0
    98
} // namespace boost
sl@0
    99
sl@0
   100
sl@0
   101
sl@0
   102
#endif