Skip to content

Commit

Permalink
Replace copy_ptr<> with templated "using"
Browse files Browse the repository at this point in the history
(cc: #66)
  • Loading branch information
jlblancoc committed Nov 3, 2017
1 parent f35a86d commit 4897470
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 124 deletions.
2 changes: 1 addition & 1 deletion libs/base/include/mrpt/bayes/CProbabilityParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef CPROBABILITYPARTICLE_H
#define CPROBABILITYPARTICLE_H

#include <mrpt/utils/copy_ptr.h>
#include <mrpt/utils/generic_copier_ptr.h>

namespace mrpt
{
Expand Down
60 changes: 0 additions & 60 deletions libs/base/include/mrpt/utils/copy_ptr.h

This file was deleted.

29 changes: 27 additions & 2 deletions libs/base/include/mrpt/utils/generic_copier_ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,24 @@ class generic_copier_ptr
o.m_ptr = nullptr;
}
/** move operator */
generic_copier_ptr<T, Copier>& operator=(
const generic_copier_ptr<T, Copier>&& o)
generic_copier_ptr<T, Copier>& operator=(generic_copier_ptr<T, Copier>&& o)
{
if (this == &o) return *this;
m_ptr = o.m_ptr;
o.m_ptr = nullptr;
return *this;
}

/** copy operator */
generic_copier_ptr<T, Copier>& operator=(
const generic_copier_ptr<T, Copier>& o)
{
if (this == &o) return *this;
this->reset();
m_ptr = Copier().copy(o.m_ptr);
return *this;
}

T* operator->()
{
if (m_ptr)
Expand Down Expand Up @@ -139,6 +148,22 @@ class generic_copier_ptr

} // end NS internal

/** Smart pointer for polymorphic classes with a `clone()` method.
* No shared copies, that is, each `poly_ptr<T>` owns a unique instance of `T`.
* Copying a `poly_ptr<T>` invokes the copy operator for `T`.
* \sa copy_ptr<T>
*/
template <typename T>
using poly_ptr = internal::generic_copier_ptr<T, internal::CopyCloner<T>>;

/** Smart pointer for non-polymorphic classes.
* No shared copies, that is, each `copy_ptr<T>` owns a unique instance of `T`.
* Copying a `copy_ptr<T>` invokes the copy operator for `T`.
* \sa poly_ptr<T>
*/
template <typename T>
using copy_ptr = internal::generic_copier_ptr<T, internal::CopyStatic<T>>;

/** @} */ // end of grouping
} // End of namespace
} // End of namespace
59 changes: 0 additions & 59 deletions libs/base/include/mrpt/utils/poly_ptr.h

This file was deleted.

3 changes: 1 addition & 2 deletions libs/base/src/utils/poly_ptr_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
| Released under BSD License. See details in http://www.mrpt.org/License |
+------------------------------------------------------------------------+ */

#include <mrpt/utils/poly_ptr.h>
#include <mrpt/utils/copy_ptr.h>
#include <mrpt/utils/generic_copier_ptr.h>

#include <mrpt/poses/CPose2D.h>
#include <gtest/gtest.h>
Expand Down

0 comments on commit 4897470

Please sign in to comment.