autoptr.h
Go to the documentation of this file.
1 #ifndef AUTOPTR_H
2 #define AUTOPTR_H
3 #include <assert.h>
4 
5 namespace GMapping{
6 
7 template <class X>
8 class autoptr{
9  protected:
10 
11  public:
12  struct reference{
13  X* data;
14  unsigned int shares;
15  };
16  inline autoptr(X* p=(X*)(0));
17  inline autoptr(const autoptr<X>& ap);
18  inline autoptr& operator=(const autoptr<X>& ap);
19  inline ~autoptr();
20  inline operator int() const;
21  inline X& operator*();
22  inline const X& operator*() const;
23  //p
24  reference * m_reference;
25  protected:
26 };
27 
28 template <class X>
30  m_reference=0;
31  if (p){
33  m_reference->data=p;
35  }
36 }
37 
38 template <class X>
40  m_reference=0;
41  reference* ref=ap.m_reference;
42  if (ap.m_reference){
43  m_reference=ref;
45  }
46 }
47 
48 template <class X>
50  reference* ref=ap.m_reference;
51  if (m_reference==ref){
52  return *this;
53  }
54  if (m_reference && !(--m_reference->shares)){
55  delete m_reference->data;
56  delete m_reference;
57  m_reference=0;
58  }
59  if (ref){
60  m_reference=ref;
62  }
63 //20050802 nasty changes begin
64  else
65  m_reference=0;
66 //20050802 nasty changes end
67  return *this;
68 }
69 
70 template <class X>
72  if (m_reference && !(--m_reference->shares)){
73  delete m_reference->data;
74  delete m_reference;
75  m_reference=0;
76  }
77 }
78 
79 template <class X>
82 }
83 
84 template <class X>
87  return *(m_reference->data);
88 }
89 
90 template <class X>
91 const X& autoptr<X>::operator*() const{
93  return *(m_reference->data);
94 }
95 
96 };
97 #endif
reference * m_reference
Definition: autoptr.h:24
autoptr & operator=(const autoptr< X > &ap)
Definition: autoptr.h:49
autoptr(X *p=(X *)(0))
Definition: autoptr.h:29
X & operator*()
Definition: autoptr.h:85


openslam_gmapping
Author(s): Giorgio Grisetti, Cyrill Stachniss, Wolfram Burgard
autogenerated on Mon Jun 10 2019 14:04:22