event.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef BOOST_STATECHART_EVENT_HPP_INCLUDED
  2. #define BOOST_STATECHART_EVENT_HPP_INCLUDED
  3. //////////////////////////////////////////////////////////////////////////////
  4. // Copyright 2002-2007 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/event_base.hpp>
  9. #include <boost/statechart/detail/rtti_policy.hpp>
  10. #include <boost/statechart/detail/memory.hpp>
  11. #include <boost/polymorphic_cast.hpp> // boost::polymorphic_downcast
  12. #include <memory> // std::allocator
  13. namespace boost
  14. {
  15. namespace statechart
  16. {
  17. //////////////////////////////////////////////////////////////////////////////
  18. template< class MostDerived, class Allocator = std::allocator< none > >
  19. class event : public detail::rtti_policy::rtti_derived_type<
  20. MostDerived, event_base >
  21. {
  22. public:
  23. //////////////////////////////////////////////////////////////////////////
  24. // Compiler-generated copy constructor and copy assignment operator are
  25. // fine
  26. void * operator new( std::size_t size )
  27. {
  28. return detail::allocate< MostDerived, Allocator >( size );
  29. }
  30. void * operator new( std::size_t, void * p )
  31. {
  32. return p;
  33. }
  34. void operator delete( void * pEvent )
  35. {
  36. detail::deallocate< MostDerived, Allocator >( pEvent );
  37. }
  38. void operator delete( void * pEvent, void * p )
  39. {
  40. }
  41. protected:
  42. //////////////////////////////////////////////////////////////////////////
  43. event() {}
  44. virtual ~event() {}
  45. private:
  46. //////////////////////////////////////////////////////////////////////////
  47. virtual intrusive_ptr< const event_base > clone() const
  48. {
  49. return intrusive_ptr< const event_base >( new MostDerived(
  50. *polymorphic_downcast< const MostDerived * >( this ) ) );
  51. }
  52. };
  53. } // namespace statechart
  54. } // namespace boost
  55. #endif