ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

170 lines
3.7 KiB

  1. #ifndef BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
  2. #define BOOSTER_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED
  3. //
  4. // detail/sp_counted_impl.hpp
  5. //
  6. // Copyright (c) 2001, 2002, 2003 Peter Dimov and Multi Media Ltd.
  7. // Copyright 2004-2005 Peter Dimov
  8. //
  9. // Distributed under the Boost Software License, Version 1.0. (See
  10. // accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. //
  13. #include <booster/config.h>
  14. #include <booster/checked_delete.h>
  15. #include <booster/smart_ptr/sp_counted_base.h>
  16. #if defined(BOOSTER_SP_USE_STD_ALLOCATOR)
  17. #include <booster/auto_ptr_inc.h> // std::allocator
  18. #endif
  19. #include <cstddef> // std::size_t
  20. namespace booster
  21. {
  22. namespace detail
  23. {
  24. template<class X> class sp_counted_impl_p: public sp_counted_base
  25. {
  26. private:
  27. X * px_;
  28. sp_counted_impl_p( sp_counted_impl_p const & );
  29. sp_counted_impl_p & operator= ( sp_counted_impl_p const & );
  30. typedef sp_counted_impl_p<X> this_type;
  31. public:
  32. explicit sp_counted_impl_p( X * px ): px_( px )
  33. {
  34. }
  35. virtual void dispose() // nothrow
  36. {
  37. booster::checked_delete( px_ );
  38. }
  39. virtual void * get_deleter( detail::sp_typeinfo const & )
  40. {
  41. return 0;
  42. }
  43. void * operator new( std::size_t )
  44. {
  45. return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
  46. }
  47. void operator delete( void * p )
  48. {
  49. std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
  50. }
  51. };
  52. //
  53. // Borland's Codeguard trips up over the -Vx- option here:
  54. //
  55. #ifdef __CODEGUARD__
  56. # pragma option push -Vx-
  57. #endif
  58. template<class P, class D> class sp_counted_impl_pd: public sp_counted_base
  59. {
  60. private:
  61. P ptr; // copy constructor must not throw
  62. D del; // copy constructor must not throw
  63. sp_counted_impl_pd( sp_counted_impl_pd const & );
  64. sp_counted_impl_pd & operator= ( sp_counted_impl_pd const & );
  65. typedef sp_counted_impl_pd<P, D> this_type;
  66. public:
  67. // pre: d(p) must not throw
  68. sp_counted_impl_pd( P p, D d ): ptr(p), del(d)
  69. {
  70. }
  71. virtual void dispose() // nothrow
  72. {
  73. del( ptr );
  74. }
  75. virtual void * get_deleter( detail::sp_typeinfo const & ti )
  76. {
  77. return ti == BOOSTER_SP_TYPEID(D)? &reinterpret_cast<char&>( del ): 0;
  78. }
  79. void * operator new( std::size_t )
  80. {
  81. return std::allocator<this_type>().allocate( 1, static_cast<this_type *>(0) );
  82. }
  83. void operator delete( void * p )
  84. {
  85. std::allocator<this_type>().deallocate( static_cast<this_type *>(p), 1 );
  86. }
  87. };
  88. template<class P, class D, class A> class sp_counted_impl_pda: public sp_counted_base
  89. {
  90. private:
  91. P p_; // copy constructor must not throw
  92. D d_; // copy constructor must not throw
  93. A a_; // copy constructor must not throw
  94. sp_counted_impl_pda( sp_counted_impl_pda const & );
  95. sp_counted_impl_pda & operator= ( sp_counted_impl_pda const & );
  96. typedef sp_counted_impl_pda<P, D, A> this_type;
  97. public:
  98. // pre: d( p ) must not throw
  99. sp_counted_impl_pda( P p, D d, A a ): p_( p ), d_( d ), a_( a )
  100. {
  101. }
  102. virtual void dispose() // nothrow
  103. {
  104. d_( p_ );
  105. }
  106. virtual void destroy() // nothrow
  107. {
  108. typedef typename A::template rebind< this_type >::other A2;
  109. A2 a2( a_ );
  110. this->~this_type();
  111. a2.deallocate( this, 1 );
  112. }
  113. virtual void * get_deleter( detail::sp_typeinfo const & ti )
  114. {
  115. return ti == BOOSTER_SP_TYPEID( D )? &reinterpret_cast<char&>( d_ ): 0;
  116. }
  117. };
  118. #ifdef __CODEGUARD__
  119. # pragma option pop
  120. #endif
  121. } // namespace detail
  122. } // namespace boost
  123. #endif // #ifndef BOOST_SMART_PTR_DETAIL_SP_COUNTED_IMPL_HPP_INCLUDED