Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pcl::make_shared instead of new for boost::shared_ptr #3146

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d78d6f9
add pcl::make_shared
Jun 10, 2019
60e3415
apps: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
d1645f1
common: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
f064253
examples: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
b1dd375
filters: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
de35496
io: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
09ab759
keypoints: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
953f326
outofcore: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
7d4c3b9
people: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
a57430a
recognition: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
164e12d
registration: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
d0faeea
search: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
2bebc87
segmentation: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
9d12094
simulation: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
44a38dd
surface: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
37b9d6d
test: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
189fe23
tools: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
31f1c31
tracking: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
b7cb3f4
visualization: clang-tidy from new boost::shared_ptr to pcl::make_shared
Jun 12, 2019
0172407
move pcl::make_shared implementation back in header
Jun 12, 2019
7eaf1e6
minor things
Jun 12, 2019
7f17b19
move has_custom_allocator to traits header
Jun 12, 2019
6767316
move PCL_MAKE_ALIGNED_OPERATOR_NEW in pcl_macros.h and rename all ins…
Jun 13, 2019
e360687
fix include statements to have <> instead of double quotes
Jun 13, 2019
f29e39a
Merge branch 'master' into pcl_make_shared
aPonza Jun 13, 2019
9c968f1
amend commit f29e39a5412a7182b474a2f9ab03759a0a11ff8a
Jun 13, 2019
9d50535
fix inclusion in wrong place
Jun 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ set(incs
include/pcl/PointIndices.h
include/pcl/register_point_struct.h
include/pcl/conversions.h
include/pcl/make_shared.h
)

set(common_incs
Expand Down Expand Up @@ -147,6 +148,7 @@ set(impl_incs
include/pcl/impl/instantiate.hpp
include/pcl/impl/point_types.hpp
include/pcl/impl/cloud_iterator.hpp
include/pcl/impl/make_shared.hpp
)

set(tools_incs
Expand Down
86 changes: 86 additions & 0 deletions common/include/pcl/impl/make_shared.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
aPonza marked this conversation as resolved.
Show resolved Hide resolved
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#ifndef INCLUDE_PCL_MAKE_SHARED_HPP_
#define INCLUDE_PCL_MAKE_SHARED_HPP_
aPonza marked this conversation as resolved.
Show resolved Hide resolved


#include <type_traits>
#include <utility>

#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>

#include <eigen3/Eigen/Core>


#define PCL_MAKE_ALIGNED_OPERATOR_NEW \
EIGEN_MAKE_ALIGNED_OPERATOR_NEW \
using custom_allocator = void;
aPonza marked this conversation as resolved.
Show resolved Hide resolved


namespace pcl
{

template<typename T>
class has_custom_allocator
{
template<typename U, typename = typename U::custom_allocator> static char test(unsigned);
template<typename U> static int32_t test(...);
public:
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
aPonza marked this conversation as resolved.
Show resolved Hide resolved
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class should likely be placed in https://github.com/PointCloudLibrary/pcl/blob/master/common/include/pcl/point_traits.h . My issue with that is that the file is named point_traits. @taketwo, proposal to rename to type_traits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also propose to make the size difference more explicit by using a int8_t instead of char.


template<typename T, typename ... Args>
std::enable_if_t<has_custom_allocator<T>::value, boost::shared_ptr<T>> make_shared(Args&&... args)
{
return boost::allocate_shared<T>(Eigen::aligned_allocator<T>(), std::forward<Args> (args)...);
}

template<typename T, typename ... Args>
std::enable_if_t<!has_custom_allocator<T>::value, boost::shared_ptr<T>> make_shared(Args&&... args)
{
return boost::make_shared<T>(std::forward<Args> (args)...);
}

} // namespace pcl


#endif /* INCLUDE_PCL_MAKE_SHARED_HPP_ */



aPonza marked this conversation as resolved.
Show resolved Hide resolved
60 changes: 60 additions & 0 deletions common/include/pcl/make_shared.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2014-, Open Perception, Inc.
aPonza marked this conversation as resolved.
Show resolved Hide resolved
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#pragma once


#include <type_traits>
#include <boost/shared_ptr.hpp>


namespace pcl
{

template<typename T>
class has_custom_allocator;

template<typename T, typename ... Args>
std::enable_if_t<has_custom_allocator<T>::value, boost::shared_ptr<T>> make_shared(Args&&... args);

template<typename T, typename ... Args>
std::enable_if_t<!has_custom_allocator<T>::value, boost::shared_ptr<T>> make_shared(Args&&... args);

} // namespace pcl


#include <pcl/impl/make_shared.hpp>