File indexing completed on 2025-01-18 09:52:31
0001 #ifndef BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED
0002 #define BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <boost/statechart/detail/avoid_unused_warning.hpp>
0012
0013 #include <boost/assert.hpp>
0014 #include <boost/detail/allocator_utilities.hpp>
0015
0016 #include <cstddef> // std::size_t
0017 #include <memory> // std::allocator_traits
0018
0019
0020 namespace boost
0021 {
0022 namespace statechart
0023 {
0024
0025 #ifdef BOOST_NO_CXX11_ALLOCATOR
0026 typedef void none;
0027 #else
0028
0029
0030
0031
0032 struct none {};
0033 #endif
0034
0035 namespace detail
0036 {
0037
0038
0039
0040
0041
0042 template< class MostDerived, class Allocator >
0043 void * allocate( std::size_t size )
0044 {
0045 avoid_unused_warning( size );
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 BOOST_ASSERT( size == sizeof( MostDerived ) );
0064 typedef typename boost::detail::allocator::rebind_to<
0065 Allocator, MostDerived
0066 >::type md_allocator;
0067 md_allocator alloc;
0068 #ifdef BOOST_NO_CXX11_ALLOCATOR
0069 return alloc.allocate( 1, static_cast< MostDerived * >( 0 ) );
0070 #else
0071 typedef std::allocator_traits<md_allocator> md_traits;
0072 return md_traits::allocate( alloc, 1, static_cast< MostDerived * >( 0 ) );
0073 #endif
0074 }
0075
0076 template< class MostDerived, class Allocator >
0077 void deallocate( void * pObject )
0078 {
0079 typedef typename boost::detail::allocator::rebind_to<
0080 Allocator, MostDerived
0081 >::type md_allocator;
0082 md_allocator alloc;
0083 #ifdef BOOST_NO_CXX11_ALLOCATOR
0084 alloc.deallocate( static_cast< MostDerived * >( pObject ), 1 );
0085 #else
0086 typedef std::allocator_traits<md_allocator> md_traits;
0087 md_traits::deallocate( alloc, static_cast< MostDerived * >( pObject ), 1 );
0088 #endif
0089 }
0090
0091
0092
0093 }
0094 }
0095 }
0096
0097
0098
0099 #endif