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.
 
 
 
 
 
 

86 lines
1.8 KiB

  1. #ifndef BOOSTER_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
  2. #define BOOSTER_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED
  3. //
  4. // enable_shared_from_this.hpp
  5. //
  6. // Copyright 2002, 2009 Peter Dimov
  7. //
  8. // Distributed under the Boost Software License, Version 1.0.
  9. // See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt
  11. //
  12. // http://www.boost.org/libs/smart_ptr/enable_shared_from_this.html
  13. //
  14. #include <booster/weak_ptr.h>
  15. #include <booster/shared_ptr.h>
  16. #include <assert.h>
  17. #include <booster/config.h>
  18. namespace booster
  19. {
  20. ///
  21. /// \brief This class is borrowed from boost
  22. ///
  23. /// For details see: http://www.boost.org/doc/libs/release/libs/smart_ptr
  24. ///
  25. template<class T> class enable_shared_from_this
  26. {
  27. protected:
  28. enable_shared_from_this()
  29. {
  30. }
  31. enable_shared_from_this(enable_shared_from_this const &)
  32. {
  33. }
  34. enable_shared_from_this & operator=(enable_shared_from_this const &)
  35. {
  36. return *this;
  37. }
  38. ~enable_shared_from_this()
  39. {
  40. }
  41. public:
  42. shared_ptr<T> shared_from_this()
  43. {
  44. shared_ptr<T> p( weak_this_ );
  45. assert( p.get() == this );
  46. return p;
  47. }
  48. shared_ptr<T const> shared_from_this() const
  49. {
  50. shared_ptr<T const> p( weak_this_ );
  51. assert( p.get() == this );
  52. return p;
  53. }
  54. public: // actually private, but avoids compiler template friendship issues
  55. // Note: invoked automatically by shared_ptr; do not call
  56. template<class X, class Y> void _internal_accept_owner( shared_ptr<X> const * ppx, Y * py ) const
  57. {
  58. if( weak_this_.expired() )
  59. {
  60. weak_this_ = shared_ptr<T>( *ppx, py );
  61. }
  62. }
  63. private:
  64. mutable weak_ptr<T> weak_this_;
  65. };
  66. } // namespace boost
  67. #endif // #ifndef BOOST_SMART_PTR_ENABLE_SHARED_FROM_THIS_HPP_INCLUDED