scoped_ptr.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  scoped_ptr - a not too smart pointer for exception safe heap objects
3  -------------------------
4  begin : May 2019
5  copyright : (C) 2019 Intermodalics
6 
7  ***************************************************************************
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU Lesser General Public *
10  * License as published by the Free Software Foundation; either *
11  * version 2.1 of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * Lesser General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU Lesser General Public *
19  * License along with this library; if not, write to the Free Software *
20  * Foundation, Inc., 59 Temple Place, *
21  * Suite 330, Boston, MA 02111-1307 USA *
22  * *
23  ***************************************************************************/
24 
25 #if (__cplusplus > 199711L)
26 #include <utility>
27 #else
28 #include <algorithm>
29 #endif
30 
31 namespace KDL {
32 
33 template<typename T> class scoped_ptr;
34 
35 template<typename T> void swap(scoped_ptr<T>&, scoped_ptr<T>&);
36 
37 template<typename T>
38 class scoped_ptr {
39  public:
40  scoped_ptr() : ptr_(0) { }
41  explicit scoped_ptr(T* p) : ptr_(p) { }
42 
43  ~scoped_ptr() { delete ptr_; }
44 
45  T* operator->() { return ptr_; }
46  const T* operator->() const { return ptr_; }
47 
48  T* get() const { return ptr_; }
49 
50  void reset(T* p = 0) {
51  T* old = ptr_;
52  ptr_ = p;
53  delete old;
54  }
55 
56  T* release() {
57  T* old = ptr_;
58  ptr_ = 0;
59  return old;
60  }
61 
62  friend void swap<>(scoped_ptr<T>& a, scoped_ptr<T>& b);
63 
64  private:
65  scoped_ptr(const scoped_ptr&); // not-copyable
66  scoped_ptr& operator=(const scoped_ptr&); // not-copyable
67 
68  T* ptr_;
69 };
70 
71 template<typename T>
73  using std::swap;
74  swap(a.ptr_, b.ptr_);
75 }
76 
77 
78 } // namespace KDL
friend void swap(scoped_ptr< T > &a, scoped_ptr< T > &b)
Definition: scoped_ptr.hpp:72
const T * operator->() const
Definition: scoped_ptr.hpp:46
scoped_ptr & operator=(const scoped_ptr &)
void reset(T *p=0)
Definition: scoped_ptr.hpp:50
void swap(scoped_ptr< T > &, scoped_ptr< T > &)
Definition: scoped_ptr.hpp:72


orocos_kdl
Author(s):
autogenerated on Sat Jun 15 2019 19:07:36