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 9 10 11 #include <boost/statechart/event_base.hpp> 12 #include <boost/statechart/detail/rtti_policy.hpp> 13 #include <boost/statechart/detail/memory.hpp> 14 15 #include <boost/polymorphic_cast.hpp> // boost::polymorphic_downcast 16 17 #include <memory> // std::allocator 18 19 20 21 namespace boost 22 { 23 namespace statechart 24 { 25 26 27 28 ////////////////////////////////////////////////////////////////////////////// 29 template< class MostDerived, class Allocator = std::allocator< none > > 30 class event : public detail::rtti_policy::rtti_derived_type< 31 MostDerived, event_base > 32 { 33 public: 34 ////////////////////////////////////////////////////////////////////////// 35 // Compiler-generated copy constructor and copy assignment operator are 36 // fine 37 operator new(std::size_t size)38 void * operator new( std::size_t size ) 39 { 40 return detail::allocate< MostDerived, Allocator >( size ); 41 } 42 operator new(std::size_t,void * p)43 void * operator new( std::size_t, void * p ) 44 { 45 return p; 46 } 47 operator delete(void * pEvent)48 void operator delete( void * pEvent ) 49 { 50 detail::deallocate< MostDerived, Allocator >( pEvent ); 51 } 52 operator delete(void * pEvent,void * p)53 void operator delete( void * pEvent, void * p ) 54 { 55 } 56 57 protected: 58 ////////////////////////////////////////////////////////////////////////// event()59 event() {} ~event()60 virtual ~event() {} 61 62 private: 63 ////////////////////////////////////////////////////////////////////////// clone() const64 virtual intrusive_ptr< const event_base > clone() const 65 { 66 return intrusive_ptr< const event_base >( new MostDerived( 67 *polymorphic_downcast< const MostDerived * >( this ) ) ); 68 } 69 }; 70 71 72 73 } // namespace statechart 74 } // namespace boost 75 76 77 78 #endif 79