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