Skip to content

Commit

Permalink
Merge pull request #1721 from ApexAI/iox-1391-move-unique-ptr
Browse files Browse the repository at this point in the history
iox-1391 Move `unique_ptr`
  • Loading branch information
mossmaurice authored Oct 25, 2022
2 parents 5ba595f + 31f2581 commit 8f6af2f
Show file tree
Hide file tree
Showing 34 changed files with 161 additions and 108 deletions.
6 changes: 4 additions & 2 deletions .clang-tidy-diff-scans.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
./iceoryx_hoofs/test/moduletests/test_unit*
./iceoryx_hoofs/source/units/*

./iceoryx_hoofs/include/iceoryx_hoofs/internal/relocatable_pointer/*
./iceoryx_hoofs/include/iceoryx_hoofs/internal/memory/*
./iceoryx_hoofs/include/iceoryx_hoofs/memory/*
./iceoryx_hoofs/test/moduletests/test_relative_pointer*
./iceoryx_hoofs/source/relocatable_pointer/*
./iceoryx_hoofs/source/memory/*
./iceoryx_hoofs/memory/*

./iceoryx_hoofs/include/iceoryx_hoofs/internal/concurrent/*
./iceoryx_hoofs/include/iceoryx_hoofs/concurrent/*
Expand Down
5 changes: 5 additions & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,8 @@
```

Have a look at the logger design document for more details on how to setup the testing logger.

40. Changed the include path and namespace of several classes in `iceoryx_hoofs`:

* `iox::bar::foo` to `iox::foo`
* `iceoryx_hoofs/bar/foo.hpp` to `iox/foo.hpp`
1 change: 1 addition & 0 deletions iceoryx_binding_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ iox_add_library(
BUILD_INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/generated/iceoryx/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
PUBLIC_LIBS_LINUX stdc++ pthread
PUBLIC_LIBS_UNIX stdc++ pthread
PUBLIC_LIBS_APPLE stdc++ pthread
Expand Down
1 change: 1 addition & 0 deletions iceoryx_dust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ iox_add_library(
PUBLIC_LIBS iceoryx_hoofs::iceoryx_hoofs
BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
FILES
source/cxx/file_reader.cpp
source/posix_wrapper/named_pipe.cpp
Expand Down
8 changes: 6 additions & 2 deletions iceoryx_hoofs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ cc_library(
"source/**/*.cpp",
"source/**/*.hpp",
]),
hdrs = glob(["include/**"]) + [
hdrs = glob(["include/**"]) + glob(["legacy/**"]) + glob(["memory/**"]) + [
":iceoryx_hoofs_deployment_hpp",
],
includes = [
"include/",
"legacy/include/",
"memory/include/",
],
linkopts = select({
"//iceoryx_platform:linux-clang": [
"-latomic",
Expand All @@ -48,7 +53,6 @@ cc_library(
"//iceoryx_platform:win": [],
"//conditions:default": ["-lacl"],
}),
strip_include_prefix = "include",
visibility = ["//visibility:public"],
deps = ["//iceoryx_platform"],
)
Expand Down
7 changes: 6 additions & 1 deletion iceoryx_hoofs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ iox_add_library(
PRIVATE_LIBS ${ICEORYX_SANITIZER_FLAGS}
PRIVATE_LIBS_LINUX acl atomic ${CODE_COVERAGE_LIBS}
BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/legacy/include
${PROJECT_SOURCE_DIR}/memory/include
${CMAKE_BINARY_DIR}/generated/iceoryx_hoofs/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
legacy/include/
memory/include/
FILES
source/concurrent/loffli.cpp
source/cxx/adaptive_wait.cpp
Expand Down Expand Up @@ -80,7 +85,7 @@ iox_add_library(
source/posix_wrapper/types.cpp
source/posix_wrapper/unnamed_semaphore.cpp
source/posix_wrapper/unix_domain_socket.cpp
source/relocatable_pointer/relative_pointer_data.cpp
source/memory/relative_pointer_data.cpp
source/units/duration.cpp
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

#include "iceoryx_hoofs/cxx/expected.hpp"
#include "iceoryx_hoofs/cxx/string.hpp"
#include "iceoryx_hoofs/cxx/unique_ptr.hpp"
#include "iceoryx_hoofs/cxx/vector.hpp"
#include "iceoryx_hoofs/posix_wrapper/posix_access_rights.hpp"
#include "iceoryx_platform/acl.hpp"
#include "iox/unique_ptr.hpp"

#include <cstdint>
#include <iostream>
Expand Down Expand Up @@ -112,7 +112,7 @@ class AccessController
bool writePermissionsToFile(const int32_t fileDescriptor) const noexcept;

private:
using smartAclPointer_t = cxx::unique_ptr<std::remove_pointer<acl_t>::type>;
using smartAclPointer_t = iox::unique_ptr<std::remove_pointer<acl_t>::type>;

struct PermissionEntry
{
Expand Down
33 changes: 33 additions & 0 deletions iceoryx_hoofs/legacy/include/iceoryx_hoofs/cxx/unique_ptr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2022 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_CXX_UNIQUE_PTR_HPP
#define IOX_HOOFS_CXX_UNIQUE_PTR_HPP

#include "iox/unique_ptr.hpp"

namespace iox
{
/// @todo iox-#1593 Deprecate include
/// [[deprecated("Deprecated in 3.0, removed in 4.0, please include 'iox/unique_ptr.hpp' instead")]]
namespace cxx
{
/// @deprecated
using memory::unique_ptr;
} // namespace cxx
} // namespace iox

#endif // IOX_HOOFS_CXX_UNIQUE_PTR_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,20 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_CXX_UNIQUE_PTR_INL
#define IOX_HOOFS_CXX_UNIQUE_PTR_INL
#ifndef IOX_HOOFS_MEMORY_UNIQUE_PTR_INL
#define IOX_HOOFS_MEMORY_UNIQUE_PTR_INL

#include "iceoryx_hoofs/cxx/unique_ptr.hpp"
#include "iox/unique_ptr.hpp"

namespace iox
{
namespace cxx
{
// AXIVION Next Construct AutosarC++19_03-A12.1.5 : False positive, the class doesn't require a delegating ctor
template <typename T>
inline unique_ptr<T>::unique_ptr(T* const object, const function<DeleterType>& deleter) noexcept
inline unique_ptr<T>::unique_ptr(T* const object, const cxx::function<DeleterType>& deleter) noexcept
: m_ptr(object)
, m_deleter(deleter)
{
Ensures(object != nullptr);
cxx::Ensures(object != nullptr);
}

template <typename T>
Expand Down Expand Up @@ -129,7 +127,6 @@ inline bool operator!=(const unique_ptr<T>& lhs, const unique_ptr<U>& rhs) noexc
}

// AXIVION ENABLE STYLE AutosarC++19_03-A13.5.5 : See header
} // namespace cxx
} // namespace iox

#endif // IOX_HOOFS_CXX_UNIQUE_PTR_INL
#endif // IOX_HOOFS_MEMORY_UNIQUE_PTR_INL
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
//
// SPDX-License-Identifier: Apache-2.0

#ifndef IOX_HOOFS_CXX_UNIQUE_PTR_HPP
#define IOX_HOOFS_CXX_UNIQUE_PTR_HPP
#ifndef IOX_HOOFS_MEMORY_UNIQUE_PTR_HPP
#define IOX_HOOFS_MEMORY_UNIQUE_PTR_HPP

#include "iceoryx_hoofs/cxx/function.hpp"
#include "iceoryx_hoofs/cxx/requires.hpp"
#include <memory>

namespace iox
{
namespace cxx
{
///
/// @brief The unique_ptr class is a heap-less unique ptr implementation, unlike the STL.
/// @tparam[in] T Type to which the unique_ptr is pointing to
Expand All @@ -33,10 +32,10 @@ namespace cxx
/// instances with different deleters to be stored in the same containers.
///
/// @code
/// #include "iceoryx_hoofs/cxx/unique_ptr.hpp"
/// #include "iox/unique_ptr.hpp"
///
/// {
/// cxx::unique_ptr<MyClass> myPtr(ptrToInt, [&](MyClass* const ptr) {
/// iox::unique_ptr<MyClass> myPtr(ptrToInt, [&](MyClass* const ptr) {
/// customAllocator.delete(ptr);
/// });
///
Expand Down Expand Up @@ -64,7 +63,7 @@ class unique_ptr final
/// @param object The pointer to the object to be managed.
/// @param deleter The deleter function for cleaning up the managed object.
///
unique_ptr(T* const object, const function<DeleterType>& deleter) noexcept;
unique_ptr(T* const object, const cxx::function<DeleterType>& deleter) noexcept;

unique_ptr(const unique_ptr& other) = delete;
unique_ptr& operator=(const unique_ptr&) = delete;
Expand Down Expand Up @@ -120,7 +119,7 @@ class unique_ptr final

private:
T* m_ptr{nullptr};
function<DeleterType> m_deleter;
cxx::function<DeleterType> m_deleter;
};

// AXIVION DISABLE STYLE AutosarC++19_03-A13.5.5: Parameters are explicitly not identical to compare two unique_ptr's
Expand All @@ -145,9 +144,8 @@ template <typename T, typename U>
bool operator!=(const unique_ptr<T>& lhs, const unique_ptr<U>& rhs) noexcept;

// AXIVION ENABLE STYLE AutosarC++19_03-A13.5.5: See above
} // namespace cxx
} // namespace iox

#include "iceoryx_hoofs/internal/cxx/unique_ptr.inl"
#include "iox/detail/unique_ptr.inl"

#endif // IOX_HOOFS_CXX_UNIQUE_PTR_HPP
#endif // IOX_HOOFS_MEMORY_UNIQUE_PTR_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_hoofs/cxx/function.hpp"
#include "iceoryx_hoofs/cxx/unique_ptr.hpp"
#include "iox/unique_ptr.hpp"
#include "test.hpp"

#include <iostream>
Expand Down Expand Up @@ -60,7 +60,7 @@ TEST_F(UniquePtrTest, CtorWithObjectPtrAndDeleterSetsPtrToObjectAndCallsDeleter)
{
::testing::Test::RecordProperty("TEST_ID", "85a90fc3-e8b1-4c3d-a15c-ee7f64070b57");
{
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);
EXPECT_EQ(sut.get(), &object);
}
// SUT is out of scope and should have called deleter
Expand All @@ -71,7 +71,7 @@ TEST_F(UniquePtrTest, CtorUsingMoveWithObjectPtrAndDeleterSetsPtrToObjectAndCall
{
::testing::Test::RecordProperty("TEST_ID", "88ae1d4c-d893-4633-9256-766d7e42bcc6");
{
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);
{
auto anotherSut = std::move(sut);

Expand All @@ -93,7 +93,7 @@ TEST_F(UniquePtrTest, MoveAssignmentUniquePtrsSetsPtrToObjectAndCallsDeleter)
{
::testing::Test::RecordProperty("TEST_ID", "b3b67548-bd69-4a6f-a867-f9aaa6d869b1");
{
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);
{
auto anotherSut = std::move(sut);

Expand All @@ -115,9 +115,9 @@ TEST_F(UniquePtrTest, MoveAssignmentOverwriteAUniquePtrWithAnotherOneAndCallsAno
{
::testing::Test::RecordProperty("TEST_ID", "75a853ef-fd0e-41bd-9ce7-af63e0f67fa9");
{
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);
{
auto anotherSut = iox::cxx::unique_ptr<Position>(&anotherObject, anotherDeleter);
auto anotherSut = iox::unique_ptr<Position>(&anotherObject, anotherDeleter);

anotherSut = std::move(sut);

Expand All @@ -140,15 +140,15 @@ TEST_F(UniquePtrTest, MoveAssignmentOverwriteAUniquePtrWithAnotherOneAndCallsAno
TEST_F(UniquePtrTest, AccessUnderlyingObjectResultsInCorrectValue)
{
::testing::Test::RecordProperty("TEST_ID", "5a3cc8f1-0744-4e79-85cf-02eb6c5cab9b");
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);

EXPECT_EQ(sut->x, X_POS);
}

TEST_F(UniquePtrTest, AccessUnderlyingObjectViaGetResultsInCorrectValue)
{
::testing::Test::RecordProperty("TEST_ID", "b795fa9d-b980-4987-8b94-9ea752a4e71e");
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);

auto* objectPtr = sut.get();

Expand All @@ -158,9 +158,9 @@ TEST_F(UniquePtrTest, AccessUnderlyingObjectViaGetResultsInCorrectValue)
TEST_F(UniquePtrTest, ReleaseAnObjectResultsInDeleterNotBeingCalled)
{
::testing::Test::RecordProperty("TEST_ID", "8a1413a5-15cd-42ff-a05e-9dff158aa047");
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);

auto* ptr = iox::cxx::unique_ptr<Position>::release(std::move(sut));
auto* ptr = iox::unique_ptr<Position>::release(std::move(sut));

EXPECT_EQ(ptr, &object);
EXPECT_FALSE(m_deleterCalled);
Expand All @@ -170,9 +170,9 @@ TEST_F(UniquePtrTest, SwapTwoValidUniquePtrsWithDifferentDeletersSucceeds)
{
::testing::Test::RecordProperty("TEST_ID", "c4d5ed18-2d92-44f3-93d9-753bd09f5c1b");
{
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);
{
auto anotherSut = iox::cxx::unique_ptr<Position>(&anotherObject, anotherDeleter);
auto anotherSut = iox::unique_ptr<Position>(&anotherObject, anotherDeleter);

sut.swap(anotherSut);

Expand All @@ -193,9 +193,9 @@ TEST_F(UniquePtrTest, SwapUniquePtrWithUniquePtrLeadsToCleanupOfBothInReverseOrd
{
::testing::Test::RecordProperty("TEST_ID", "9017ba22-ff18-41d4-8590-ccb0d7729435");
{
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);
{
auto anotherSut = iox::cxx::unique_ptr<Position>(&anotherObject, anotherDeleter);
auto anotherSut = iox::unique_ptr<Position>(&anotherObject, anotherDeleter);

sut.swap(anotherSut);

Expand All @@ -214,16 +214,16 @@ TEST_F(UniquePtrTest, SwapUniquePtrWithUniquePtrLeadsToCleanupOfBothInReverseOrd
TEST_F(UniquePtrTest, CompareAUniquePtrWithItselfIsTrue)
{
::testing::Test::RecordProperty("TEST_ID", "d12f8cf6-e37e-424a-9ed5-aea580b8bdc9");
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);

EXPECT_TRUE(sut == sut);
}

TEST_F(UniquePtrTest, CompareAUniquePtrWithAnotherOneOfAnotherObjectIsFalse)
{
::testing::Test::RecordProperty("TEST_ID", "6a6135d2-1a79-49fa-a142-7e19327b6a9f");
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto anotherSut = iox::cxx::unique_ptr<Position>(&anotherObject, anotherDeleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);
auto anotherSut = iox::unique_ptr<Position>(&anotherObject, anotherDeleter);

EXPECT_FALSE(sut == anotherSut);
EXPECT_FALSE(anotherSut == sut);
Expand All @@ -232,16 +232,16 @@ TEST_F(UniquePtrTest, CompareAUniquePtrWithAnotherOneOfAnotherObjectIsFalse)
TEST_F(UniquePtrTest, NotEqualCompareOfAUniquePtrWithItselfIsFalse)
{
::testing::Test::RecordProperty("TEST_ID", "6305a2d9-28d7-41a0-bb0b-866912a39205");
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);

EXPECT_FALSE(sut != sut);
}

TEST_F(UniquePtrTest, NotEqualCompareOfAUniquePtrWithAnotherOneOfAnotherObjectIsTrue)
{
::testing::Test::RecordProperty("TEST_ID", "58b9cd12-82f9-4e3a-b033-8c57afbd31d7");
auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
auto anotherSut = iox::cxx::unique_ptr<Position>(&anotherObject, anotherDeleter);
auto sut = iox::unique_ptr<Position>(&object, deleter);
auto anotherSut = iox::unique_ptr<Position>(&anotherObject, anotherDeleter);

EXPECT_TRUE(sut != anotherSut);
EXPECT_TRUE(anotherSut != sut);
Expand All @@ -250,14 +250,14 @@ TEST_F(UniquePtrTest, NotEqualCompareOfAUniquePtrWithAnotherOneOfAnotherObjectIs
TEST_F(UniquePtrTest, CanGetUnderlyingPtrFromConstUniquePtr)
{
::testing::Test::RecordProperty("TEST_ID", "75727c11-f721-4a52-816a-a9a3a61e2b43");
const auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
const auto sut = iox::unique_ptr<Position>(&object, deleter);
EXPECT_EQ(sut.get(), &object);
}

TEST_F(UniquePtrTest, CanUseArrowOperatorToAccessObjectInConstUniquePtr)
{
::testing::Test::RecordProperty("TEST_ID", "045a9026-74f5-41ad-9881-14c2502527c4");
const auto sut = iox::cxx::unique_ptr<Position>(&object, deleter);
const auto sut = iox::unique_ptr<Position>(&object, deleter);
EXPECT_EQ(X_POS, sut->x);
EXPECT_EQ(Y_POS, sut->y);
EXPECT_EQ(Z_POS, sut->z);
Expand Down
Loading

0 comments on commit 8f6af2f

Please sign in to comment.