From 0d934b0fcbc025f833f6218bdd9a3c11d772b4d4 Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Fri, 30 Apr 2021 17:27:28 +0200 Subject: [PATCH] Remove unnecessary overrides of copy(), add tests for checking whether copy() exists --- .../libraries/armem/core/base/EntityBase.h | 27 ---------- .../armem/core/base/EntityInstanceBase.h | 15 +++--- .../libraries/armem/test/ArMemMemoryTest.cpp | 50 +++++++++++++++++++ 3 files changed, 57 insertions(+), 35 deletions(-) diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h index 6d2a3a8de..39dcc12c9 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h @@ -268,33 +268,6 @@ namespace armarx::armem::base return "entity"; } - virtual _Derived copy() const override - { - _Derived d; - this->_copySelf(d); - return d; - } - - virtual _Derived copyEmpty() const override - { - _Derived d; - this->_copySelfEmpty(d); - return d; - } - - - protected: - - virtual void _copySelf(DerivedT& other) const override - { - Base::_copySelf(other); - } - - virtual void _copySelfEmpty(DerivedT& other) const override - { - Base::_copySelfEmpty(other); - } - private: diff --git a/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h b/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h index 4e2471f3d..aab701934 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityInstanceBase.h @@ -46,14 +46,6 @@ namespace armarx::armem::base return id().instanceIndex; } - // Copying - virtual DerivedT copy() const - { - DerivedT d; - this->_copySelf(d); - return d; - } - /** * @brief Fill `*this` with the update's values. * @param update The update. @@ -64,6 +56,13 @@ namespace armarx::armem::base virtual bool equalsDeep(const DerivedT& other) const = 0; + virtual DerivedT copy() const + { + DerivedT d; + this->_copySelf(d); + return d; + } + std::string getLevelName() const override { diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp index b7fffdbff..5eabdd345 100644 --- a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp +++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp @@ -766,3 +766,53 @@ BOOST_AUTO_TEST_CASE(test_history_size_in_provider_segment) } } + + +template <class T> +struct CopyTest +{ + CopyTest() + { + } + + void test() + { + // At least check whether they can be called. + T t; + T t2 = t.copy(); + + if constexpr (std::is_base_of_v<armem::base::EntityInstanceBase<T>, T>) + { + t2 = t.copyEmpty(); + } + } +}; + + +BOOST_AUTO_TEST_CASE(test_copy) +{ + { + CopyTest<armem::wm::EntityInstance>().test(); + CopyTest<armem::wm::EntitySnapshot>().test(); + CopyTest<armem::wm::Entity>().test(); + CopyTest<armem::wm::ProviderSegment>().test(); + CopyTest<armem::wm::CoreSegment>().test(); + CopyTest<armem::wm::Memory>().test(); + } + { + CopyTest<armem::ltm::EntityInstance>().test(); + CopyTest<armem::ltm::EntitySnapshot>().test(); + CopyTest<armem::ltm::Entity>().test(); + CopyTest<armem::ltm::ProviderSegment>().test(); + CopyTest<armem::ltm::CoreSegment>().test(); + CopyTest<armem::ltm::Memory>().test(); + } + { + CopyTest<armem::d_ltm::EntityInstance>().test(); + CopyTest<armem::d_ltm::EntitySnapshot>().test(); + CopyTest<armem::d_ltm::Entity>().test(); + CopyTest<armem::d_ltm::ProviderSegment>().test(); + CopyTest<armem::d_ltm::CoreSegment>().test(); + CopyTest<armem::d_ltm::Memory>().test(); + } +} -- GitLab