leaf_state.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef BOOST_STATECHART_DETAIL_LEAF_STATE_HPP_INCLUDED
  2. #define BOOST_STATECHART_DETAIL_LEAF_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/detail/state_base.hpp>
  9. namespace boost
  10. {
  11. namespace statechart
  12. {
  13. namespace detail
  14. {
  15. //////////////////////////////////////////////////////////////////////////////
  16. template< class Allocator, class RttiPolicy >
  17. class leaf_state : public state_base< Allocator, RttiPolicy >
  18. {
  19. typedef state_base< Allocator, RttiPolicy > base_type;
  20. protected:
  21. //////////////////////////////////////////////////////////////////////////
  22. leaf_state( typename RttiPolicy::id_provider_type idProvider ) :
  23. base_type( idProvider )
  24. {
  25. }
  26. ~leaf_state() {}
  27. public:
  28. //////////////////////////////////////////////////////////////////////////
  29. // The following declarations should be private.
  30. // They are only public because many compilers lack template friends.
  31. //////////////////////////////////////////////////////////////////////////
  32. void set_list_position(
  33. typename base_type::state_list_type::iterator listPosition )
  34. {
  35. listPosition_ = listPosition;
  36. }
  37. typedef typename base_type::leaf_state_ptr_type
  38. direct_state_base_ptr_type;
  39. virtual void remove_from_state_list(
  40. typename base_type::state_list_type::iterator & statesEnd,
  41. typename base_type::node_state_base_ptr_type & pOutermostUnstableState,
  42. bool performFullExit )
  43. {
  44. --statesEnd;
  45. swap( *listPosition_, *statesEnd );
  46. ( *listPosition_ )->set_list_position( listPosition_ );
  47. direct_state_base_ptr_type & pState = *statesEnd;
  48. // Because the list owns the leaf_state, this leads to the immediate
  49. // termination of this state.
  50. pState->exit_impl( pState, pOutermostUnstableState, performFullExit );
  51. }
  52. virtual void exit_impl(
  53. direct_state_base_ptr_type & pSelf,
  54. typename base_type::node_state_base_ptr_type & pOutermostUnstableState,
  55. bool performFullExit ) = 0;
  56. private:
  57. //////////////////////////////////////////////////////////////////////////
  58. typename base_type::state_list_type::iterator listPosition_;
  59. };
  60. } // namespace detail
  61. } // namespace statechart
  62. } // namespace boost
  63. #endif