Main MRPT website > C++ reference for MRPT 1.5.6
copy_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 non-polymorphic classes.
21  * No shared copies, that is, each `copy_ptr<T>` owns a unique instance of `T`.
22  * Copying a `copy_ptr<T>` invokes the copy operator for `T`.
23  * \sa poly_ptr<T>
24  */
25  template <typename T>
26  class copy_ptr : public internal::generic_copier_ptr<T, internal::CopyStatic<T> >
27  {
28  private:
30  public:
31  /** Ctor from a pointer; takes ownership. */
32  explicit copy_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  copy_ptr(const copy_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  copy_ptr(copy_ptr<T> && o) : ptr_base_t(o) {}
47  /** move operator */
48  copy_ptr<T> &operator =(copy_ptr<T> && o) {
49  if (this == &o) return *this;
50  ptr_base_t::m_ptr = o.m_ptr;
51  o.m_ptr = nullptr;
52  return *this;
53  }
54 #endif
55  };
56 
57  /** @} */ // end of grouping
58  } // End of namespace
59 } // End of namespace
copy_ptr(const copy_ptr< T > &o)
copy ctor: makes a copy of the object via clone()
Definition: copy_ptr.h:36
internal::generic_copier_ptr< T, internal::CopyStatic< T > > ptr_base_t
Definition: copy_ptr.h:29
Smart pointer for non-polymorphic classes.
Definition: copy_ptr.h:26
copy_ptr< T > & operator=(const copy_ptr< T > &o)
copy operator
Definition: copy_ptr.h:38
copy_ptr(T *ptr)
Ctor from a pointer; takes ownership.
Definition: copy_ptr.h:32
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
copy_ptr()
Default ctor; init to nullptr.
Definition: copy_ptr.h:34



Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019