annotate DEPENDENCIES/generic/include/boost/statechart/detail/memory.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 #ifndef BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED
Chris@16 2 #define BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED
Chris@16 3 //////////////////////////////////////////////////////////////////////////////
Chris@16 4 // Copyright 2005-2006 Andreas Huber Doenni
Chris@16 5 // Distributed under the Boost Software License, Version 1.0. (See accompany-
Chris@16 6 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 7 //////////////////////////////////////////////////////////////////////////////
Chris@16 8
Chris@16 9
Chris@16 10
Chris@16 11 #include <boost/statechart/detail/avoid_unused_warning.hpp>
Chris@16 12
Chris@16 13 #include <boost/assert.hpp>
Chris@16 14 #include <boost/detail/allocator_utilities.hpp>
Chris@16 15
Chris@16 16 #include <cstddef> // std::size_t
Chris@16 17
Chris@16 18
Chris@16 19
Chris@16 20 namespace boost
Chris@16 21 {
Chris@16 22 namespace statechart
Chris@16 23 {
Chris@16 24 namespace detail
Chris@16 25 {
Chris@16 26
Chris@16 27
Chris@16 28
Chris@16 29 template< class MostDerived, class Allocator >
Chris@16 30 void * allocate( std::size_t size )
Chris@16 31 {
Chris@16 32 avoid_unused_warning( size );
Chris@16 33 // The assert below fails when memory is allocated for an event<>,
Chris@16 34 // simple_state<> or state<> subtype object, *and* the first template
Chris@16 35 // parameter passed to one of these templates is not equal to the most-
Chris@16 36 // derived object being constructed.
Chris@16 37 // The following examples apply to all these subtypes:
Chris@16 38 // // Example 1
Chris@16 39 // struct A {};
Chris@16 40 // struct B : sc::simple_state< A, /* ... */ >
Chris@16 41 // // Above, the first template parameter must be equal to the most-
Chris@16 42 // // derived type
Chris@16 43 //
Chris@16 44 // // Example 2
Chris@16 45 // struct A : sc::event< A >
Chris@16 46 // struct B : A { /* ... */ };
Chris@16 47 // void f() { delete new B(); }
Chris@16 48 // // Above the most-derived type being constructed is B, but A was passed
Chris@16 49 // // as the most-derived type to event<>.
Chris@16 50 BOOST_ASSERT( size == sizeof( MostDerived ) );
Chris@16 51 return typename boost::detail::allocator::rebind_to<
Chris@16 52 Allocator, MostDerived
Chris@16 53 >::type().allocate( 1, static_cast< MostDerived * >( 0 ) );
Chris@16 54 }
Chris@16 55
Chris@16 56 template< class MostDerived, class Allocator >
Chris@16 57 void deallocate( void * pObject )
Chris@16 58 {
Chris@16 59 return typename boost::detail::allocator::rebind_to<
Chris@16 60 Allocator, MostDerived
Chris@16 61 >::type().deallocate( static_cast< MostDerived * >( pObject ), 1 );
Chris@16 62 }
Chris@16 63
Chris@16 64
Chris@16 65
Chris@16 66 } // namespace detail
Chris@16 67 } // namespace statechart
Chris@16 68 } // namespace boost
Chris@16 69
Chris@16 70
Chris@16 71
Chris@16 72 #endif