asynchronous_state_machine.hpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef BOOST_STATECHART_ASYNCHRONOUS_STATE_MACHINE_HPP_INCLUDED
  2. #define BOOST_STATECHART_ASYNCHRONOUS_STATE_MACHINE_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/state_machine.hpp>
  9. #include <boost/statechart/fifo_scheduler.hpp>
  10. #include <boost/statechart/null_exception_translator.hpp>
  11. #include <boost/statechart/event_processor.hpp>
  12. #include <memory> // std::allocator
  13. namespace boost
  14. {
  15. namespace statechart
  16. {
  17. class event_base;
  18. //////////////////////////////////////////////////////////////////////////////
  19. template< class MostDerived,
  20. class InitialState,
  21. class Scheduler = fifo_scheduler<>,
  22. class Allocator = std::allocator< none >,
  23. class ExceptionTranslator = null_exception_translator >
  24. class asynchronous_state_machine : public state_machine<
  25. MostDerived, InitialState, Allocator, ExceptionTranslator >,
  26. public event_processor< Scheduler >
  27. {
  28. typedef state_machine< MostDerived,
  29. InitialState, Allocator, ExceptionTranslator > machine_base;
  30. typedef event_processor< Scheduler > processor_base;
  31. protected:
  32. //////////////////////////////////////////////////////////////////////////
  33. typedef asynchronous_state_machine my_base;
  34. asynchronous_state_machine( typename processor_base::my_context ctx ) :
  35. processor_base( ctx )
  36. {
  37. }
  38. virtual ~asynchronous_state_machine() {}
  39. public:
  40. //////////////////////////////////////////////////////////////////////////
  41. // The following declarations should be private.
  42. // They are only public because many compilers lack template friends.
  43. //////////////////////////////////////////////////////////////////////////
  44. void terminate()
  45. {
  46. processor_base::terminate();
  47. }
  48. private:
  49. //////////////////////////////////////////////////////////////////////////
  50. virtual void initiate_impl()
  51. {
  52. machine_base::initiate();
  53. }
  54. virtual void process_event_impl( const event_base & evt )
  55. {
  56. machine_base::process_event( evt );
  57. }
  58. virtual void terminate_impl()
  59. {
  60. machine_base::terminate();
  61. }
  62. };
  63. } // namespace statechart
  64. } // namespace boost
  65. #endif