state.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef BOOST_STATECHART_STATE_HPP_INCLUDED
  2. #define BOOST_STATECHART_STATE_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. #include <boost/statechart/simple_state.hpp>
  9. #include <boost/mpl/list.hpp>
  10. namespace boost
  11. {
  12. namespace statechart
  13. {
  14. template< class MostDerived,
  15. class Context,
  16. class InnerInitial = mpl::list<>,
  17. history_mode historyMode = has_no_history >
  18. class state : public simple_state<
  19. MostDerived, Context, InnerInitial, historyMode >
  20. {
  21. typedef simple_state< MostDerived, Context, InnerInitial, historyMode >
  22. base_type;
  23. protected:
  24. //////////////////////////////////////////////////////////////////////////
  25. struct my_context
  26. {
  27. my_context( typename base_type::context_ptr_type pContext ) :
  28. pContext_( pContext )
  29. {
  30. }
  31. typename base_type::context_ptr_type pContext_;
  32. };
  33. typedef state my_base;
  34. state( my_context ctx )
  35. {
  36. this->set_context( ctx.pContext_ );
  37. }
  38. ~state() {}
  39. public:
  40. //////////////////////////////////////////////////////////////////////////
  41. // The following declarations should be private.
  42. // They are only public because many compilers lack template friends.
  43. //////////////////////////////////////////////////////////////////////////
  44. // See base class for documentation
  45. typedef typename base_type::outermost_context_base_type
  46. outermost_context_base_type;
  47. typedef typename base_type::inner_context_ptr_type inner_context_ptr_type;
  48. typedef typename base_type::context_ptr_type context_ptr_type;
  49. typedef typename base_type::inner_initial_list inner_initial_list;
  50. static void initial_deep_construct(
  51. outermost_context_base_type & outermostContextBase )
  52. {
  53. deep_construct( &outermostContextBase, outermostContextBase );
  54. }
  55. // See base class for documentation
  56. static void deep_construct(
  57. const context_ptr_type & pContext,
  58. outermost_context_base_type & outermostContextBase )
  59. {
  60. const inner_context_ptr_type pInnerContext(
  61. shallow_construct( pContext, outermostContextBase ) );
  62. base_type::template deep_construct_inner< inner_initial_list >(
  63. pInnerContext, outermostContextBase );
  64. }
  65. static inner_context_ptr_type shallow_construct(
  66. const context_ptr_type & pContext,
  67. outermost_context_base_type & outermostContextBase )
  68. {
  69. const inner_context_ptr_type pInnerContext(
  70. new MostDerived( my_context( pContext ) ) );
  71. outermostContextBase.add( pInnerContext );
  72. return pInnerContext;
  73. }
  74. };
  75. } // namespace statechart
  76. } // namespace boost
  77. #endif