Main MRPT website > C++ reference for MRPT 1.5.7
poly_ptr.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #pragma once
10 
12 
13 namespace mrpt
14 {
15  namespace utils
16  {
17  /** \addtogroup stlext_grp
18  * @{ */
19 
20  /** Smart pointer for polymorphic classes with a `clone()` method.
21  * No shared copies, that is, each `poly_ptr<T>` owns a unique instance of `T`.
22  * Copying a `poly_ptr<T>` invokes the copy operator for `T`.
23  * \sa copy_ptr<T>
24  */
25  template <typename T>
26  class poly_ptr : public internal::generic_copier_ptr<T, internal::CopyCloner<T> >
27  {
28  private:
30  public:
31  /** Ctor from a pointer; takes ownership. */
32  explicit poly_ptr(T * ptr) : ptr_base_t(ptr) {}
33  /** Default ctor; init to nullptr. */
35  /** copy ctor: makes a copy of the object via `clone()` */
36  poly_ptr(const poly_ptr<T> & o) : ptr_base_t(o) {}
37  /** copy operator */
39  if (this == &o) return *this;
40  this->reset();
41  ptr_base_t::m_ptr = typename ptr_base_t::copier_t().copy(o.m_ptr);
42  return *this;
43  }
44 #if (__cplusplus>199711L)
45  /** move ctor */
46  poly_ptr(poly_ptr<T> && o) : ptr_base_t(o) {}
47  /** move operator */
48  poly_ptr<T> &operator =(const poly_ptr<T> && o) {
49  if (this == &o) return *this;
50  ptr_base_t::operator =(o);
51  return *this;
52  }
53 #endif
54  };
55 
56  /** @} */ // end of grouping
57  } // End of namespace
58 } // End of namespace
poly_ptr< T > & operator=(const poly_ptr< T > &o)
copy operator
Definition: poly_ptr.h:38
poly_ptr(const poly_ptr< T > &o)
copy ctor: makes a copy of the object via clone()
Definition: poly_ptr.h:36
poly_ptr(T *ptr)
Ctor from a pointer; takes ownership.
Definition: poly_ptr.h:32
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
poly_ptr()
Default ctor; init to nullptr.
Definition: poly_ptr.h:34
internal::generic_copier_ptr< T, internal::CopyCloner< T > > ptr_base_t
Definition: poly_ptr.h:29
Smart pointer for polymorphic classes with a clone() method.
Definition: poly_ptr.h:26



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019