From 934abc9ee97cfaffc9ab43f004007c1a94edc2b4 Mon Sep 17 00:00:00 2001 From: Louise Poubel Date: Thu, 1 Apr 2021 18:08:59 -0700 Subject: [PATCH 1/7] Bump main to 2.0.0~pre1 (#20) Signed-off-by: Louise Poubel --- CMakeLists.txt | 4 ++-- Changelog.md | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f17f99..7d0b5f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) #============================================================================ # Initialize the project #============================================================================ -project(ignition-utils1 VERSION 1.0.0) +project(ignition-utils2 VERSION 2.0.0) #============================================================================ # Find ignition-cmake @@ -15,7 +15,7 @@ find_package(ignition-cmake2 2.0.0 REQUIRED) # Configure the project #============================================================================ set(c++standard 17) -ign_configure_project(VERSION_SUFFIX pre2) +ign_configure_project(VERSION_SUFFIX pre1) #============================================================================ # Set project-specific options diff --git a/Changelog.md b/Changelog.md index 4fc4558..27dfbbb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +## Ignition Utils 2.x + +## Ignition Utils 2.0.0 (20XX-XX-XX) + ## Ignition Utils 1.x ## Ignition Utils 1.x.x (20XX-XX-XX) From 9c702859cce6dce65af2c7d0c9a8a6eba98552d0 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Tue, 5 Oct 2021 10:35:59 -0700 Subject: [PATCH 2/7] Added Get accessor to ImplPtr Signed-off-by: Nate Koenig --- include/ignition/utils/ImplPtr.hh | 12 ++++++++++++ include/ignition/utils/detail/ImplPtr.hh | 14 ++++++++++++++ test/integration/implptr/ImplPtr_TEST.cc | 16 ++++++++++++++++ .../integration/implptr/implptr_test_classes.cc | 17 +++++++++++++++++ .../integration/implptr/implptr_test_classes.hh | 13 +++++++++++++ 5 files changed, 72 insertions(+) diff --git a/include/ignition/utils/ImplPtr.hh b/include/ignition/utils/ImplPtr.hh index e895d1f..59306f7 100644 --- a/include/ignition/utils/ImplPtr.hh +++ b/include/ignition/utils/ImplPtr.hh @@ -128,6 +128,18 @@ namespace ignition /// \return Immutable access to the contained object's members. public: const T *operator->() const; + /// \brief Non-const member access function. This const-unqualified + /// operator ensures that logical const-correctness is followed by the + /// consumer class. + /// \return Mutable access to the contained object's members. + public: T *Get(); + + /// \brief Const member access function. This const-qualified operator + /// ensures that logical const-correctness is followed by the consumer + /// class. + /// \return Immutable access to the contained object's members. + public: const T *Get() const; + /// \internal \brief Create a clone of this ImplPtr's contents. This is /// for internal use only. The copy constructor and copy assignment /// operators should suffice for consumers. diff --git a/include/ignition/utils/detail/ImplPtr.hh b/include/ignition/utils/detail/ImplPtr.hh index 474d3ef..b256cc4 100644 --- a/include/ignition/utils/detail/ImplPtr.hh +++ b/include/ignition/utils/detail/ImplPtr.hh @@ -110,6 +110,20 @@ namespace ignition return ptr.get(); } + ////////////////////////////////////////////////// + template + T *ImplPtr::Get() + { + return ptr.get(); + } + + ////////////////////////////////////////////////// + template + const T *ImplPtr::Get() const + { + return ptr.get(); + } + ////////////////////////////////////////////////// template ImplPtr MakeImpl(Args &&..._args) diff --git a/test/integration/implptr/ImplPtr_TEST.cc b/test/integration/implptr/ImplPtr_TEST.cc index a09208c..f2274f1 100644 --- a/test/integration/implptr/ImplPtr_TEST.cc +++ b/test/integration/implptr/ImplPtr_TEST.cc @@ -41,6 +41,14 @@ TEST(ImplPtr, CopyConstruct) EXPECT_EQ(object.GetString(), other.GetString()); } +///////////////////////////////////////////////// +TEST(ImplPtr, GetAccessor) +{ + CopyableObject object(28, "golden_string"); + auto func = object.CreateFuncPointer(); + EXPECT_EQ(func(), 1); +} + ///////////////////////////////////////////////// TEST(ImplPtr, CopyAssign) { @@ -111,6 +119,14 @@ TEST(UniqueImplPtr, MoveConstruct) EXPECT_EQ(other.GetString(), moved.GetString()); } +///////////////////////////////////////////////// +TEST(UniqueImplPtr, GetAccessor) +{ + MovableObject object(28, "golden_string"); + auto func = object.CreateFuncPointer(); + EXPECT_EQ(func(), 1); +} + ///////////////////////////////////////////////// TEST(UniqueImplPtr, MoveAssign) { diff --git a/test/integration/implptr/implptr_test_classes.cc b/test/integration/implptr/implptr_test_classes.cc index 241dba5..626c4c6 100644 --- a/test/integration/implptr/implptr_test_classes.cc +++ b/test/integration/implptr/implptr_test_classes.cc @@ -24,6 +24,11 @@ using namespace ignition::implptr_test_classes; class ignition::implptr_test_classes::ObjectPrivate { + public: int TestFunc() + { + return 1; + } + public: int ivalue; public: std::string svalue; }; @@ -60,6 +65,12 @@ void CopyableObject::SetString(const std::string &_value) (*dataPtr).svalue = _value; } +////////////////////////////////////////////////// +std::function CopyableObject::CreateFuncPointer() +{ + return std::bind(&ObjectPrivate::TestFunc, this->dataPtr.Get()); +} + ////////////////////////////////////////////////// MovableObject::MovableObject(const int _ivalue, const std::string &_svalue) : dataPtr(utils::MakeUniqueImpl(_ivalue, _svalue)) @@ -91,6 +102,12 @@ void MovableObject::SetString(const std::string &_value) (*dataPtr).svalue = _value; } +////////////////////////////////////////////////// +std::function MovableObject::CreateFuncPointer() const +{ + return std::bind(&ObjectPrivate::TestFunc, this->dataPtr.get()); +} + ////////////////////////////////////////////////// class CopyableObjectAlt::Implementation { diff --git a/test/integration/implptr/implptr_test_classes.hh b/test/integration/implptr/implptr_test_classes.hh index 3fbd668..f4be639 100644 --- a/test/integration/implptr/implptr_test_classes.hh +++ b/test/integration/implptr/implptr_test_classes.hh @@ -21,6 +21,7 @@ #include #include +#include #include namespace ignition @@ -49,6 +50,12 @@ namespace ignition /// \brief Set the string value held by the pimpl public: void SetString(const std::string &_value); + /// \brief Create a pointer to a function within the private data + /// class. + /// \return The function pointer. The function should return a value + /// of 1. + public:std::function CreateFuncPointer(); + /// \brief Pointer to implementation /// This demonstrates using an implementation class that is /// forward-declared outside of this class. @@ -74,6 +81,12 @@ namespace ignition /// \brief Set the string value held by the pimpl public: void SetString(const std::string &_value); + /// \brief Create a pointer to a function within the private data + /// class. + /// \return The function pointer. The function should return a value + /// of 1. + public: std::function CreateFuncPointer() const; + /// \brief Pointer to implementation /// This demonstrates using an implementation class that is /// forward-declared outside of this class. From c41c628a25c9223523eca0e80a45e809d235b025 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Tue, 5 Oct 2021 10:38:26 -0700 Subject: [PATCH 3/7] Merged with main Signed-off-by: Nate Koenig --- CMakeLists.txt | 4 ++-- Changelog.md | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d79faf..c869cf2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) #============================================================================ # Initialize the project #============================================================================ -project(ignition-utils1 VERSION 1.1.0) +project(ignition-utils2 VERSION 2.0.0) #============================================================================ # Find ignition-cmake @@ -15,7 +15,7 @@ find_package(ignition-cmake2 2.0.0 REQUIRED) # Configure the project #============================================================================ set(c++standard 17) -ign_configure_project(VERSION_SUFFIX) +ign_configure_project(VERSION_SUFFIX pre1) #============================================================================ # Set project-specific options diff --git a/Changelog.md b/Changelog.md index 12ef2d5..9836294 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,7 @@ +## Ignition Utils 2.x + +## Ignition Utils 2.0.0 (20XX-XX-XX) + ## Ignition Utils 1.x ## Ignition Utils 1.1.0 (2021-09-02) From 5d406e3a116f155c8d8aa716963c0f06cbbc8124 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Tue, 5 Oct 2021 10:47:47 -0700 Subject: [PATCH 4/7] Update BUILD.bazel Co-authored-by: Louise Poubel --- BUILD.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD.bazel b/BUILD.bazel index bc8e1ba..ff4b5fe 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -18,7 +18,7 @@ exports_files(["LICENSE"]) PROJECT_NAME = "ignition-utils" -PROJECT_MAJOR = 1 +PROJECT_MAJOR = 2 PROJECT_MINOR = 0 From e395452381403fba99c559573cd94eeb0e42c8d3 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Tue, 5 Oct 2021 16:22:24 -0700 Subject: [PATCH 5/7] Update test Signed-off-by: Nate Koenig --- test/integration/implptr/ImplPtr_TEST.cc | 10 ++++++---- .../implptr/implptr_test_classes.cc | 20 +++++++++++++------ .../implptr/implptr_test_classes.hh | 18 ++++++++--------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/test/integration/implptr/ImplPtr_TEST.cc b/test/integration/implptr/ImplPtr_TEST.cc index f2274f1..cbbf49e 100644 --- a/test/integration/implptr/ImplPtr_TEST.cc +++ b/test/integration/implptr/ImplPtr_TEST.cc @@ -45,8 +45,9 @@ TEST(ImplPtr, CopyConstruct) TEST(ImplPtr, GetAccessor) { CopyableObject object(28, "golden_string"); - auto func = object.CreateFuncPointer(); - EXPECT_EQ(func(), 1); + int value = object.ThreadIncrementInt(); + EXPECT_EQ(value, 1); + EXPECT_EQ(object.GetInt(), 1); } ///////////////////////////////////////////////// @@ -123,8 +124,9 @@ TEST(UniqueImplPtr, MoveConstruct) TEST(UniqueImplPtr, GetAccessor) { MovableObject object(28, "golden_string"); - auto func = object.CreateFuncPointer(); - EXPECT_EQ(func(), 1); + int value = object.ThreadIncrementInt(); + EXPECT_EQ(value, 1); + EXPECT_EQ(object.GetInt(), 1); } ///////////////////////////////////////////////// diff --git a/test/integration/implptr/implptr_test_classes.cc b/test/integration/implptr/implptr_test_classes.cc index 626c4c6..030b6d0 100644 --- a/test/integration/implptr/implptr_test_classes.cc +++ b/test/integration/implptr/implptr_test_classes.cc @@ -17,16 +17,18 @@ #include "implptr_test_classes.hh" +#include #include +#include using namespace ignition; using namespace ignition::implptr_test_classes; class ignition::implptr_test_classes::ObjectPrivate { - public: int TestFunc() + public: void TestFunc() { - return 1; + this->ivalue += 1; } public: int ivalue; @@ -66,9 +68,12 @@ void CopyableObject::SetString(const std::string &_value) } ////////////////////////////////////////////////// -std::function CopyableObject::CreateFuncPointer() +int CopyableObject::ThreadIncrementInt() { - return std::bind(&ObjectPrivate::TestFunc, this->dataPtr.Get()); + this->SetInt(0); + auto thread = std::thread(&ObjectPrivate::TestFunc, this->dataPtr.Get()); + thread.join(); + return this->GetInt(); } ////////////////////////////////////////////////// @@ -103,9 +108,12 @@ void MovableObject::SetString(const std::string &_value) } ////////////////////////////////////////////////// -std::function MovableObject::CreateFuncPointer() const +int MovableObject::ThreadIncrementInt() { - return std::bind(&ObjectPrivate::TestFunc, this->dataPtr.get()); + this->SetInt(0); + auto thread = std::thread(&ObjectPrivate::TestFunc, this->dataPtr.get()); + thread.join(); + return this->GetInt(); } ////////////////////////////////////////////////// diff --git a/test/integration/implptr/implptr_test_classes.hh b/test/integration/implptr/implptr_test_classes.hh index f4be639..bfe88ca 100644 --- a/test/integration/implptr/implptr_test_classes.hh +++ b/test/integration/implptr/implptr_test_classes.hh @@ -50,11 +50,10 @@ namespace ignition /// \brief Set the string value held by the pimpl public: void SetString(const std::string &_value); - /// \brief Create a pointer to a function within the private data - /// class. - /// \return The function pointer. The function should return a value - /// of 1. - public:std::function CreateFuncPointer(); + /// \brief Uses a thread to increment the internal integer value from + /// 0 to 1. + /// \return The final internal integer value, which should be 1. + public: int ThreadIncrementInt(); /// \brief Pointer to implementation /// This demonstrates using an implementation class that is @@ -81,11 +80,10 @@ namespace ignition /// \brief Set the string value held by the pimpl public: void SetString(const std::string &_value); - /// \brief Create a pointer to a function within the private data - /// class. - /// \return The function pointer. The function should return a value - /// of 1. - public: std::function CreateFuncPointer() const; + /// \brief Uses a thread to increment the internal integer value from + /// 0 to 1. + /// \return The final internal integer value, which should be 1. + public: int ThreadIncrementInt(); /// \brief Pointer to implementation /// This demonstrates using an implementation class that is From 30e69972aff4a956124aa469f02f9c06c2d62091 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Wed, 6 Oct 2021 12:55:03 -0700 Subject: [PATCH 6/7] 1.0 update Signed-off-by: Nate Koenig --- BUILD.bazel | 2 +- CMakeLists.txt | 4 ++-- Changelog.md | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index ff4b5fe..bc8e1ba 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -18,7 +18,7 @@ exports_files(["LICENSE"]) PROJECT_NAME = "ignition-utils" -PROJECT_MAJOR = 2 +PROJECT_MAJOR = 1 PROJECT_MINOR = 0 diff --git a/CMakeLists.txt b/CMakeLists.txt index c869cf2..8d79faf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10.2 FATAL_ERROR) #============================================================================ # Initialize the project #============================================================================ -project(ignition-utils2 VERSION 2.0.0) +project(ignition-utils1 VERSION 1.1.0) #============================================================================ # Find ignition-cmake @@ -15,7 +15,7 @@ find_package(ignition-cmake2 2.0.0 REQUIRED) # Configure the project #============================================================================ set(c++standard 17) -ign_configure_project(VERSION_SUFFIX pre1) +ign_configure_project(VERSION_SUFFIX) #============================================================================ # Set project-specific options diff --git a/Changelog.md b/Changelog.md index 9836294..12ef2d5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,7 +1,3 @@ -## Ignition Utils 2.x - -## Ignition Utils 2.0.0 (20XX-XX-XX) - ## Ignition Utils 1.x ## Ignition Utils 1.1.0 (2021-09-02) From 6419a1bb9259a36b7ba859f3950179b67a4e9861 Mon Sep 17 00:00:00 2001 From: Nate Koenig Date: Mon, 22 Nov 2021 11:45:04 -0800 Subject: [PATCH 7/7] Updated test, and fixed codecheck Signed-off-by: Nate Koenig --- include/ignition/utils/detail/ImplPtr.hh | 1 + test/integration/implptr/ImplPtr_TEST.cc | 16 ++++++++++++++++ test/integration/implptr/implptr_test_classes.cc | 1 - 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/ignition/utils/detail/ImplPtr.hh b/include/ignition/utils/detail/ImplPtr.hh index b256cc4..0926f29 100644 --- a/include/ignition/utils/detail/ImplPtr.hh +++ b/include/ignition/utils/detail/ImplPtr.hh @@ -30,6 +30,7 @@ namespace ignition { ////////////////////////////////////////////////// template + // cppcheck-suppress syntaxError template CopyMoveDeleteOperations:: CopyMoveDeleteOperations(C &&_construct, A &&_assign) diff --git a/test/integration/implptr/ImplPtr_TEST.cc b/test/integration/implptr/ImplPtr_TEST.cc index cbbf49e..777ca00 100644 --- a/test/integration/implptr/ImplPtr_TEST.cc +++ b/test/integration/implptr/ImplPtr_TEST.cc @@ -48,6 +48,16 @@ TEST(ImplPtr, GetAccessor) int value = object.ThreadIncrementInt(); EXPECT_EQ(value, 1); EXPECT_EQ(object.GetInt(), 1); + + CopyableObject copied; + copied = object; + value = copied.ThreadIncrementInt(); + EXPECT_EQ(value, 1); + EXPECT_EQ(copied.GetInt(), 1); + + EXPECT_EQ(copied.ThreadIncrementInt(), object.ThreadIncrementInt()); + EXPECT_EQ(copied.GetInt(), 1); + EXPECT_EQ(object.GetInt(), 1); } ///////////////////////////////////////////////// @@ -127,6 +137,12 @@ TEST(UniqueImplPtr, GetAccessor) int value = object.ThreadIncrementInt(); EXPECT_EQ(value, 1); EXPECT_EQ(object.GetInt(), 1); + + MovableObject moved; + moved = std::move(object); + value = moved.ThreadIncrementInt(); + EXPECT_EQ(value, 1); + EXPECT_EQ(moved.GetInt(), 1); } ///////////////////////////////////////////////// diff --git a/test/integration/implptr/implptr_test_classes.cc b/test/integration/implptr/implptr_test_classes.cc index 030b6d0..fa4672e 100644 --- a/test/integration/implptr/implptr_test_classes.cc +++ b/test/integration/implptr/implptr_test_classes.cc @@ -17,7 +17,6 @@ #include "implptr_test_classes.hh" -#include #include #include