scoped_ptr.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // detail/scoped_ptr.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_SCOPED_PTR_HPP
  11. #define BOOST_ASIO_DETAIL_SCOPED_PTR_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/push_options.hpp>
  17. namespace boost {
  18. namespace asio {
  19. namespace detail {
  20. template <typename T>
  21. class scoped_ptr
  22. {
  23. public:
  24. // Constructor.
  25. explicit scoped_ptr(T* p = 0)
  26. : p_(p)
  27. {
  28. }
  29. // Destructor.
  30. ~scoped_ptr()
  31. {
  32. delete p_;
  33. }
  34. // Access.
  35. T* get()
  36. {
  37. return p_;
  38. }
  39. // Access.
  40. T* operator->()
  41. {
  42. return p_;
  43. }
  44. // Dereference.
  45. T& operator*()
  46. {
  47. return *p_;
  48. }
  49. // Reset pointer.
  50. void reset(T* p = 0)
  51. {
  52. delete p_;
  53. p_ = p;
  54. }
  55. private:
  56. // Disallow copying and assignment.
  57. scoped_ptr(const scoped_ptr&);
  58. scoped_ptr& operator=(const scoped_ptr&);
  59. T* p_;
  60. };
  61. } // namespace detail
  62. } // namespace asio
  63. } // namespace boost
  64. #include <boost/asio/detail/pop_options.hpp>
  65. #endif // BOOST_ASIO_DETAIL_SCOPED_PTR_HPP