Chris@16: #ifndef BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED Chris@16: #define BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: // Copyright 2005-2006 Andreas Huber Doenni Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompany- Chris@16: // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: ////////////////////////////////////////////////////////////////////////////// Chris@16: Chris@16: Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include // std::size_t Chris@16: Chris@16: Chris@16: Chris@16: namespace boost Chris@16: { Chris@16: namespace statechart Chris@16: { Chris@16: namespace detail Chris@16: { Chris@16: Chris@16: Chris@16: Chris@16: template< class MostDerived, class Allocator > Chris@16: void * allocate( std::size_t size ) Chris@16: { Chris@16: avoid_unused_warning( size ); Chris@16: // The assert below fails when memory is allocated for an event<>, Chris@16: // simple_state<> or state<> subtype object, *and* the first template Chris@16: // parameter passed to one of these templates is not equal to the most- Chris@16: // derived object being constructed. Chris@16: // The following examples apply to all these subtypes: Chris@16: // // Example 1 Chris@16: // struct A {}; Chris@16: // struct B : sc::simple_state< A, /* ... */ > Chris@16: // // Above, the first template parameter must be equal to the most- Chris@16: // // derived type Chris@16: // Chris@16: // // Example 2 Chris@16: // struct A : sc::event< A > Chris@16: // struct B : A { /* ... */ }; Chris@16: // void f() { delete new B(); } Chris@16: // // Above the most-derived type being constructed is B, but A was passed Chris@16: // // as the most-derived type to event<>. Chris@16: BOOST_ASSERT( size == sizeof( MostDerived ) ); Chris@16: return typename boost::detail::allocator::rebind_to< Chris@16: Allocator, MostDerived Chris@16: >::type().allocate( 1, static_cast< MostDerived * >( 0 ) ); Chris@16: } Chris@16: Chris@16: template< class MostDerived, class Allocator > Chris@16: void deallocate( void * pObject ) Chris@16: { Chris@16: return typename boost::detail::allocator::rebind_to< Chris@16: Allocator, MostDerived Chris@16: >::type().deallocate( static_cast< MostDerived * >( pObject ), 1 ); Chris@16: } Chris@16: Chris@16: Chris@16: Chris@16: } // namespace detail Chris@16: } // namespace statechart Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: Chris@16: #endif