]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // |
2 | // detail/scoped_ptr.hpp | |
3 | // ~~~~~~~~~~~~~~~~~~~~~ | |
4 | // | |
92f5a8d4 | 5 | // Copyright (c) 2003-2019 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
7c673cae FG |
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 BOOST_ASIO_DETAIL_SCOPED_PTR_HPP | |
12 | #define BOOST_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 <boost/asio/detail/config.hpp> | |
19 | ||
20 | #include <boost/asio/detail/push_options.hpp> | |
21 | ||
22 | namespace boost { | |
23 | namespace asio { | |
24 | namespace detail { | |
25 | ||
26 | template <typename T> | |
27 | class scoped_ptr | |
28 | { | |
29 | public: | |
30 | // Constructor. | |
31 | explicit scoped_ptr(T* p = 0) | |
32 | : p_(p) | |
33 | { | |
34 | } | |
35 | ||
36 | // Destructor. | |
37 | ~scoped_ptr() | |
38 | { | |
39 | delete p_; | |
40 | } | |
41 | ||
42 | // Access. | |
43 | T* get() | |
44 | { | |
45 | return p_; | |
46 | } | |
47 | ||
48 | // Access. | |
49 | T* operator->() | |
50 | { | |
51 | return p_; | |
52 | } | |
53 | ||
54 | // Dereference. | |
55 | T& operator*() | |
56 | { | |
57 | return *p_; | |
58 | } | |
59 | ||
60 | // Reset pointer. | |
61 | void reset(T* p = 0) | |
62 | { | |
63 | delete p_; | |
64 | p_ = p; | |
65 | } | |
66 | ||
b32b8144 FG |
67 | // Release ownership of the pointer. |
68 | T* release() | |
69 | { | |
70 | T* tmp = p_; | |
71 | p_ = 0; | |
72 | return tmp; | |
73 | } | |
74 | ||
7c673cae FG |
75 | private: |
76 | // Disallow copying and assignment. | |
77 | scoped_ptr(const scoped_ptr&); | |
78 | scoped_ptr& operator=(const scoped_ptr&); | |
79 | ||
80 | T* p_; | |
81 | }; | |
82 | ||
83 | } // namespace detail | |
84 | } // namespace asio | |
85 | } // namespace boost | |
86 | ||
87 | #include <boost/asio/detail/pop_options.hpp> | |
88 | ||
89 | #endif // BOOST_ASIO_DETAIL_SCOPED_PTR_HPP |