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 11 #ifndef ASIO_DETAIL_SCOPED_PTR_HPP 12 #define ASIO_DETAIL_SCOPED_PTR_HPP 13 14 15 #include "asio/detail/config.hpp" 16 17 #include "asio/detail/push_options.hpp" 18 19 namespace asio { 20 namespace detail { 21 22 template <typename T> 23 class scoped_ptr 24 { 25 public: 26 // Constructor. scoped_ptr(T * p=0)27 explicit scoped_ptr(T* p = 0) 28 : p_(p) 29 { 30 } 31 32 // Destructor. ~scoped_ptr()33 ~scoped_ptr() 34 { 35 delete p_; 36 } 37 38 // Access. get()39 T* get() 40 { 41 return p_; 42 } 43 44 // Access. operator ->()45 T* operator->() 46 { 47 return p_; 48 } 49 50 // Dereference. operator *()51 T& operator*() 52 { 53 return *p_; 54 } 55 56 // Reset pointer. reset(T * p=0)57 void reset(T* p = 0) 58 { 59 delete p_; 60 p_ = p; 61 } 62 63 private: 64 // Disallow copying and assignment. 65 scoped_ptr(const scoped_ptr&); 66 scoped_ptr& operator=(const scoped_ptr&); 67 68 T* p_; 69 }; 70 71 } // namespace detail 72 } // namespace asio 73 74 #include "asio/detail/pop_options.hpp" 75 76 #endif // ASIO_DETAIL_SCOPED_PTR_HPP 77