Clementine
scoped_ptr.hpp
1 //
2 // detail/scoped_ptr.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2020 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>
27 {
28 public:
29  // Constructor.
30  explicit scoped_ptr(T* p = 0)
31  : p_(p)
32  {
33  }
34 
35  // Destructor.
36  ~scoped_ptr()
37  {
38  delete p_;
39  }
40 
41  // Access.
42  T* get()
43  {
44  return p_;
45  }
46 
47  // Access.
48  T* operator->()
49  {
50  return p_;
51  }
52 
53  // Dereference.
54  T& operator*()
55  {
56  return *p_;
57  }
58 
59  // Reset pointer.
60  void reset(T* p = 0)
61  {
62  delete p_;
63  p_ = p;
64  }
65 
66  // Release ownership of the pointer.
67  T* release()
68  {
69  T* tmp = p_;
70  p_ = 0;
71  return tmp;
72  }
73 
74 private:
75  // Disallow copying and assignment.
76  scoped_ptr(const scoped_ptr&);
77  scoped_ptr& operator=(const scoped_ptr&);
78 
79  T* p_;
80 };
81 
82 } // namespace detail
83 } // namespace asio
84 
85 #include "asio/detail/pop_options.hpp"
86 
87 #endif // ASIO_DETAIL_SCOPED_PTR_HPP
Definition: chrono.h:284
Definition: scoped_ptr.hpp:26
Definition: any_io_executor.hpp:28