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 19namespace asio { 20namespace detail { 21 22template <typename T> 23class scoped_ptr 24{ 25public: 26 // Constructor. 27 explicit scoped_ptr(T* p = 0) 28 : p_(p) 29 { 30 } 31 32 // Destructor. 33 ~scoped_ptr() 34 { 35 delete p_; 36 } 37 38 // Access. 39 T* get() 40 { 41 return p_; 42 } 43 44 // Access. 45 T* operator->() 46 { 47 return p_; 48 } 49 50 // Dereference. 51 T& operator*() 52 { 53 return *p_; 54 } 55 56 // Reset pointer. 57 void reset(T* p = 0) 58 { 59 delete p_; 60 p_ = p; 61 } 62 63private: 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