35 #if __GNUC__ > 3 && __GNUC_MINOR__ > 6
36 #pragma GCC diagnostic push
37 #pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
41 #pragma clang diagnostic push
42 #pragma clang diagnostic ignored "-Wdelete-non-virtual-dtor"
77 :
public std::exception
80 inline virtual char const *
what()
const throw();
87 return "bad_weak_ptr";
112 virtual void *
get_deleter( std::type_info
const & ti ) = 0;
115 virtual void dispose()
throw() = 0;
116 inline virtual void destroy()
throw();
131 assert( n_shared_ptrs == 0 || n_weak_ptrs >= 1 );
157 return n_shared_ptrs ? ++n_shared_ptrs :
false;
171 if( 0 == --n_shared_ptrs )
179 if( 0 == --n_weak_ptrs )
186 assert( n_weak_ptrs == 0 );
194 return n_shared_ptrs;
205 template<
typename P >
216 inline void *
operator new ( std::size_t );
217 inline void operator delete (
void * );
220 inline virtual void *
get_deleter( std::type_info
const & );
221 inline virtual void dispose()
throw();
229 template<
typename P >
235 template<
typename P >
239 template<
typename P >
246 template<
typename P >
253 template<
typename P >
257 return std::allocator<this_type>().allocate( 1 );
260 template<
typename P >
264 std::allocator<this_type>().deallocate( static_cast<this_type*>(
p), 1 );
280 inline void *
operator new ( std::size_t );
281 inline void operator delete (
void * );
284 inline virtual void *
get_deleter( std::type_info
const & );
285 inline virtual void dispose()
throw();
295 template<
typename P,
typename D >
302 template<
typename P,
typename D >
306 template<
typename P,
typename D >
310 deleter( owned_ptr );
313 template<
typename P,
typename D >
317 return ti ==
typeid(D) ? &reinterpret_cast<char&>( deleter ) : 0;
320 template<
typename P,
typename D >
324 return std::allocator<this_type>().allocate( 1 );
327 template<
typename P,
typename D >
331 std::allocator<this_type>().deallocate( static_cast<this_type*>(
p), 1 );
348 inline virtual void *
get_deleter( std::type_info
const & );
349 inline virtual void dispose()
throw();
350 inline virtual void destroy()
throw();
361 template<
typename P,
typename D,
typename A >
369 template<
typename P,
typename D,
typename A >
373 template<
typename P,
typename D,
typename A >
377 deleter( owned_ptr );
380 template<
typename P,
typename D,
typename A >
384 typename A::template rebind< this_type >::other this_allocator( allocator );
386 this_allocator.destroy(
this );
387 this_allocator.deallocate(
this, 1 );
390 template<
typename P,
typename D,
typename A >
394 return ti ==
typeid( D ) ? &reinterpret_cast<char&>( deleter ) : 0;
413 template< typename P >
416 template< typename P, typename D >
418 template< typename P, typename D, typename A >
420 template< typename P >
460 template<
typename P >
475 template<
typename P,
typename D >
490 template<
typename P,
typename D,
typename A >
496 typedef typename A::template rebind<ctrl_block>::other
497 ctrl_block_allocator;
498 ctrl_block_allocator cba( a );
502 acb_ptr = cba.allocate( 1 );
503 new(
static_cast<void*
>(acb_ptr) ) ctrl_block(p, d, a);
509 cba.deallocate( static_cast<ctrl_block*>( acb_ptr ), 1 );
514 template<
typename P >
531 other.acb_ptr = acb_ptr;
536 : acb_ptr( other.acb_ptr )
550 if( acb_ptr != 0 ) acb_ptr->release();
578 return acb_ptr == 0 ? 0L : acb_ptr->
use_count();
584 return lhs.acb_ptr == rhs.acb_ptr;
590 return std::less<abstract_ctrl_block*>()( lhs.acb_ptr, rhs.acb_ptr );
634 : acb_ptr( other.acb_ptr )
650 other.acb_ptr = acb_ptr;
655 : acb_ptr( other.acb_ptr )
700 return acb_ptr == 0 ? 0L : acb_ptr->
use_count();
706 return lhs.acb_ptr == rhs.acb_ptr;
712 return std::less<abstract_ctrl_block*>()( lhs.acb_ptr, rhs.acb_ptr );
716 : acb_ptr( other.acb_ptr )
724 : acb_ptr( other.acb_ptr )
745 template<
typename T >
780 template<
typename X,
typename Y,
typename T >
788 pe->_internal_accept_owner( ppx, const_cast<Y*>( py ) );
791 template<
typename X,
typename Y,
typename T >
799 pe->_internal_accept_owner( ppx, const_cast<Y*>( py ) );
813 template<
typename P >
816 typedef shared_ptr<P> this_type;
817 typedef typename sp::shared_ptr_traits<P>::reference reference;
827 template< typename P2 >
830 template< typename P2, typename D >
832 template< typename P2, typename D, typename A >
840 template< typename P2 >
843 template< typename P2 >
845 template< typename P2 >
847 template< typename P2 >
849 template< typename P2 >
851 template< typename P2 >
853 template< typename P2 >
855 template< typename P2 >
858 template< typename AP >
863 template< typename P2 >
868 template< typename P2 >
870 template< typename P2 >
872 template< typename AP >
878 template< typename P2 >
880 template< typename P2, typename D >
882 template< typename P2, typename D, typename A >
884 template< typename P2 >
888 inline operator
bool () const throw();
889 inline reference operator * () const throw();
890 inline P * operator -> () const throw();
898 template< typename P2 >
906 sp::shared_ctrl_handle
pn;
910 template< typename P, typename P2 >
912 template< typename P, typename P2 >
914 template< typename P, typename P2 >
917 template< typename P >
920 template< typename P, typename P2 >
922 template< typename P, typename P2 >
924 template< typename P, typename P2 >
927 template< typename P >
929 template< typename D, typename P >
932 template< typename C, typename T, typename P >
933 inline std::basic_ostream<C,T> & operator << ( std::basic_ostream<C,T> &
937 template< typename P >
943 template<
typename P >
944 template<
typename P2 >
952 template<
typename P >
953 template<
typename P2,
typename D >
961 template<
typename P >
962 template<
typename P2,
typename D,
typename A >
970 template<
typename P >
978 template<
typename P >
986 template<
typename P >
987 template<
typename P2 >
995 template<
typename P >
996 template<
typename P2 >
1001 ,
pn( other.
pn,
sp::sp_nothrow_tag() )
1007 template<
typename P >
1008 template<
typename P2 >
1016 template<
typename P >
1017 template<
typename P2 >
1025 template<
typename P >
1026 template<
typename P2 >
1034 template<
typename P >
1035 template<
typename P2 >
1046 template<
typename P >
1047 template<
typename P2 >
1055 throw std::bad_cast();
1058 template<
typename P >
1059 template<
typename P2 >
1064 P2 *
tmp = other.get();
1069 template<
typename P >
1070 template<
typename AP >
1077 typename AP::element_type *
tmp = other.get();
1082 template<
typename P >
1083 template<
typename P2 >
1091 template<
typename P >
1092 template<
typename P2 >
1100 template<
typename P >
1101 template<
typename P2 >
1109 template<
typename P >
1110 template<
typename AP >
1118 template<
typename P >
1125 template<
typename P >
1126 template<
typename P2 >
1130 assert( p == 0 || p != px );
1134 template<
typename P >
1135 template<
typename P2,
typename D >
1142 template<
typename P >
1143 template<
typename P2,
typename D,
typename A >
1150 template<
typename P >
1151 template<
typename P2 >
1158 template<
typename P >
1164 template<
typename P >
1173 template<
typename P >
1181 template<
typename P >
1188 template<
typename P >
1195 template<
typename P >
1199 return pn.use_count();
1202 template<
typename P >
1203 template<
typename P2 >
1210 template<
typename P >
1214 return pn.get_deleter( ti );
1217 template<
typename P >
1221 return px == other.px &&
pn == other.pn;
1224 template<
typename P,
typename P2 >
1228 return a.get() == b.get();
1231 template<
typename P,
typename P2 >
1235 return a.get() != b.get();
1238 template<
typename P,
typename P2 >
1242 return a._internal_less(
b);
1245 template<
typename P >
1252 template<
typename P,
typename P2 >
1259 template<
typename P,
typename P2 >
1266 template<
typename P,
typename P2 >
1273 template<
typename P >
1280 template<
typename D,
typename P >
1284 return static_cast<D*
>( p._internal_get_deleter(
typeid(D)) );
1287 template<
typename C,
typename T,
typename P >
1288 std::basic_ostream<C,T> &
1300 template<
typename P >
1303 typedef weak_ptr<P> this_type;
1316 template< typename P2 >
1321 template< typename P2 >
1326 template< typename P2 >
1328 template< typename P2 >
1340 template< typename P2 >
1345 sp::weak_ctrl_handle
pn;
1349 template< typename P, typename P2 >
1352 template< typename P >
1355 template< typename P >
1361 template<
typename P >
1362 template<
typename P2 >
1366 : px( r.
lock().get() )
1370 template<
typename P >
1371 template<
typename P2 >
1379 template<
typename P >
1380 template<
typename P2 >
1384 px =
r.lock().get();
1389 template<
typename P >
1390 template<
typename P2 >
1399 template<
typename P >
1406 template<
typename P >
1410 return pn.use_count();
1413 template<
typename P >
1417 return pn.use_count() == 0;
1420 template<
typename P >
1427 template<
typename P >
1434 template<
typename P >
1442 template<
typename P >
1450 template<
typename P >
1451 template<
typename P2 >
1458 template<
typename P,
typename P2 >
1462 return a._internal_less(
b);
1465 template<
typename P >
1478 inline void operator () (
void const * )
const;
1491 #endif // CLHEP_MEMORY_H
1500 template<
typename T >
1501 class enable_shared_from_this
1504 enable_shared_from_this()
1507 ~enable_shared_from_this()
1510 enable_shared_from_this( enable_shared_from_this
const & )
1513 enable_shared_from_this &
1514 operator = ( enable_shared_from_this
const & )
1523 shared_ptr<T>
p( weak_this_ );
1524 assert(
p.get() == this );
1529 shared_from_this()
const
1531 shared_ptr<T const>
p( weak_this_ );
1532 assert(
p.get() == this );
1539 template<
typename X,
typename Y >
1541 _internal_accept_owner( shared_ptr<X>
const * ppx,
Y * py )
const
1543 if( weak_this_.expired() )
1544 weak_this_ = shared_ptr<T>( *ppx, py );
1548 mutable weak_ptr<T> weak_this_;
1557 class esft2_deleter_wrapper
1560 shared_ptr<void> deleter_;
1563 esft2_deleter_wrapper()
1566 template<
typename T >
1568 set_deleter( shared_ptr<T>
const & deleter )
1573 template<
typename T >
1577 assert( deleter_.use_count() <= 1 );
1584 template<
typename T >
1585 class enable_shared_from_this2
1589 enable_shared_from_this2()
1592 enable_shared_from_this2( enable_shared_from_this2
const & )
1595 enable_shared_from_this2 & operator = ( enable_shared_from_this2
const & )
1600 ~enable_shared_from_this2()
1602 assert( shared_this_.use_count() <= 1 );
1606 mutable weak_ptr<T> weak_this_;
1607 mutable shared_ptr<T> shared_this_;
1615 return shared_ptr<T>( weak_this_ );
1619 shared_from_this()
const
1622 return shared_ptr<T>( weak_this_ );
1627 void init_weak_once()
const
1629 if( weak_this_._empty() )
1631 shared_this_.reset( static_cast< T* >( 0 )
1632 , detail::esft2_deleter_wrapper()
1634 weak_this_ = shared_this_;
1641 template<
typename X,
typename Y >
1643 _internal_accept_owner( shared_ptr<X> * ppx,
Y * py )
const
1647 if( weak_this_.use_count() == 0 )
1648 weak_this_ = shared_ptr<T>( *ppx, py );
1649 else if( shared_this_.use_count() != 0 )
1651 assert( ppx->unique() );
1653 detail::esft2_deleter_wrapper * pd
1654 = boost::get_deleter<detail::esft2_deleter_wrapper>( shared_this_ );
1657 pd->set_deleter( *ppx );
1659 ppx->reset( shared_this_, ppx->get() );
1660 shared_this_.reset();