From dc25c1fffd36e9badbb5cd4b273c6f30627f8d45 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Mon, 26 Apr 2021 23:47:39 +0200 Subject: [PATCH 1/9] Use BipedalLocomotion::TextLogging in YarpUtilities methods --- src/YarpUtilities/CMakeLists.txt | 2 +- .../YarpUtilities/Helper.tpp | 60 +++++++++---------- src/YarpUtilities/src/Helper.cpp | 31 ++++------ 3 files changed, 42 insertions(+), 51 deletions(-) diff --git a/src/YarpUtilities/CMakeLists.txt b/src/YarpUtilities/CMakeLists.txt index 8e0c9b42e1..c9ff638bd0 100644 --- a/src/YarpUtilities/CMakeLists.txt +++ b/src/YarpUtilities/CMakeLists.txt @@ -9,7 +9,7 @@ if(FRAMEWORK_COMPILE_YarpUtilities) NAME YarpUtilities SOURCES src/Helper.cpp src/RosPublisher.cpp PUBLIC_HEADERS include/BipedalLocomotion/YarpUtilities/Helper.h include/BipedalLocomotion/YarpUtilities/Helper.tpp include/BipedalLocomotion/YarpUtilities/RosPublisher.h - PUBLIC_LINK_LIBRARIES ${YARP_LIBRARIES} ${iDynTree_LIBRARIES} BipedalLocomotion::GenericContainer BipedalLocomotion::ParametersHandler + PUBLIC_LINK_LIBRARIES ${YARP_LIBRARIES} ${iDynTree_LIBRARIES} BipedalLocomotion::GenericContainer BipedalLocomotion::ParametersHandler BipedalLocomotion::TextLogging SUBDIRECTORIES tests) endif() diff --git a/src/YarpUtilities/include/BipedalLocomotion/YarpUtilities/Helper.tpp b/src/YarpUtilities/include/BipedalLocomotion/YarpUtilities/Helper.tpp index 01bd4da0ec..5c100d2f84 100644 --- a/src/YarpUtilities/include/BipedalLocomotion/YarpUtilities/Helper.tpp +++ b/src/YarpUtilities/include/BipedalLocomotion/YarpUtilities/Helper.tpp @@ -6,12 +6,13 @@ */ // std -#include #include + //GenericContainer #include #include +#include // clang-format off @@ -61,6 +62,7 @@ bool getElementFromSearchable(const yarp::os::Searchable& config, const std::string& key, T& element) { + constexpr auto logPrefix = "[BipedalLocomotion::YarpUtilities::getElementFromSearchable]"; static_assert(YARP_UTILITES_CHECK_ELEMENT_SUPPORT(T), "[BipedalLocomotion::YarpUtilities::getElementFromSearchable] The " @@ -70,17 +72,17 @@ bool getElementFromSearchable(const yarp::os::Searchable& config, yarp::os::Value* value; if (!config.check(key, value)) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getElementFromSearchable] " - "Missing field named " - << key << std::endl; + log()->error("{} Missing field named: {}.", logPrefix, key); return false; } if (!(value->*YARP_UTILITES_GET_CHECKER_NAME(T))()) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getElementFromSearchable] The " - "value named " - << key << " is not a " << YARP_UTILITES_GET_ELEMENT_TYPE(T) << "." << std::endl; + log()->error("{} The value named: {} is not a {}.", + logPrefix, + key, + YARP_UTILITES_GET_ELEMENT_TYPE(T)); + return false; } @@ -91,7 +93,7 @@ bool getElementFromSearchable(const yarp::os::Searchable& config, template bool getVectorFromSearchable(const yarp::os::Searchable& config, const std::string& key, T& vector) { - + constexpr auto logPrefix = "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable]"; using elementType = typename std::pointer_traits::element_type; static_assert(YARP_UTILITES_CHECK_ELEMENT_SUPPORT(elementType), @@ -102,34 +104,26 @@ bool getVectorFromSearchable(const yarp::os::Searchable& config, const std::stri yarp::os::Value* value; if (!config.check(key, value)) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] " - "Missing field " - << key << std::endl; + log()->error("{} Missing field named: {}.", logPrefix, key); return false; } if (value->isNull()) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] Empty " - "input value named " - << key << std::endl; + log()->error("{} Empty input named: {}.", logPrefix, key); return false; } if (!value->isList()) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] The " - "value named " - << key << "is not associated to a list." << std::endl; + log()->error("{} The value named: {} is not associated to a list.", logPrefix, key); return false; } yarp::os::Bottle* inputPtr = value->asList(); if (inputPtr == nullptr) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] The " - "list associated to the value named " - << key << " is empty." << std::endl; + log()->error("{} The list associated to the value named: {} is empty.", logPrefix, key); return false; } @@ -141,10 +135,11 @@ bool getVectorFromSearchable(const yarp::os::Searchable& config, const std::stri { if (!vector.resizeVector(inputPtr->size())) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] " - << "Unable to resize " << type_name() - << "List size: " - << inputPtr->size() << ". Vector size: " << vector.size() << std::endl; + log()->error("{} Unable to resize {}, List size: {}. Vector size: {}.", + logPrefix, + type_name(), + inputPtr->size(), + vector.size()); return false; } } @@ -152,10 +147,11 @@ bool getVectorFromSearchable(const yarp::os::Searchable& config, const std::stri vector.resize(inputPtr->size()); else { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] " - "The size of the vector does not match with the size of the list. List " - "size: " - << inputPtr->size() << ". Vector size: " << vector.size() << std::endl; + log()->error("{} The size of the vector does not match with the size of the list. List " + "size {}. Vector size {}.", + logPrefix, + inputPtr->size(), + vector.size()); return false; } } @@ -164,10 +160,10 @@ bool getVectorFromSearchable(const yarp::os::Searchable& config, const std::stri { if (!(inputPtr->get(i).*YARP_UTILITES_GET_CHECKER_NAME(elementType))()) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] " - "The element of the list associated to the value named " - << key << " is not a " << YARP_UTILITES_GET_ELEMENT_TYPE(elementType) << "." - << std::endl; + log()->error("{} The element of the list associated to the value named {} is not a {}.", + logPrefix, + key, + YARP_UTILITES_GET_ELEMENT_TYPE(elementType)); return false; } diff --git a/src/YarpUtilities/src/Helper.cpp b/src/YarpUtilities/src/Helper.cpp index 456c34e5a2..a67770bc98 100644 --- a/src/YarpUtilities/src/Helper.cpp +++ b/src/YarpUtilities/src/Helper.cpp @@ -5,6 +5,7 @@ * distributed under the terms of the GNU Lesser General Public License v2.1 or any later version. */ +#include #include using namespace BipedalLocomotion; @@ -15,9 +16,8 @@ bool YarpUtilities::addVectorOfStringToProperty(yarp::os::Property& prop, // check if the key already exists if (prop.check(key)) { - std::cerr << "[YarpUtilities::addVectorOfStringToProperty::addVectorOfStringToProperty] " - "The property already exist." - << std::endl; + log()->error("[YarpUtilities::addVectorOfStringToProperty::addVectorOfStringToProperty] " + "The property already exist."); return false; } @@ -61,37 +61,31 @@ bool YarpUtilities::getVectorFromSearchable>(const yarp::os::S const std::string& key, std::vector& vector) { + constexpr auto logPrefix = "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable]"; + yarp::os::Value* value; if (!config.check(key, value)) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] " - "Missing field " - << key << std::endl; + log()->error("{} Missing field {}.", logPrefix, key); return false; } if (value->isNull()) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] Empty " - "input value named " - << key << std::endl; + log()->error("{} Empty input value named: {}.", logPrefix, key); return false; } if (!value->isList()) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] The " - "value named " - << key << "is not associated to a list." << std::endl; + log()->error("{} The value named: {} is not associated to a list.", logPrefix, key); return false; } yarp::os::Bottle* inputPtr = value->asList(); if (inputPtr == nullptr) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] The " - "list associated to the value named " - << key << " is empty." << std::endl; + log()->error("{} The list associated to the value named: {} is empty.", logPrefix, key); return false; } @@ -102,9 +96,10 @@ bool YarpUtilities::getVectorFromSearchable>(const yarp::os::S { if (!(inputPtr->get(i).isBool()) && !(inputPtr->get(i).isInt())) { - std::cerr << "[BipedalLocomotion::YarpUtilities::getVectorFromSearchable] " - "The element of the list associated to the value named " - << key << " is not a boolean ." << std::endl; + log()->error("{} The element of the list associated to the value named {} is not a " + "Boolean.", + logPrefix, + key); return false; } From e4c3f94995e120eb529cfee2733857dffb60df6a Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Mon, 26 Apr 2021 23:51:32 +0200 Subject: [PATCH 2/9] Call clang_format in IParametersHandler.h --- .../ParametersHandler/IParametersHandler.h | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/IParametersHandler.h b/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/IParametersHandler.h index eba25d0097..531c67af14 100644 --- a/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/IParametersHandler.h +++ b/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/IParametersHandler.h @@ -12,8 +12,8 @@ #include #include -#include #include +#include namespace BipedalLocomotion { @@ -26,7 +26,6 @@ namespace ParametersHandler class IParametersHandler { public: - using unique_ptr = std::unique_ptr; using shared_ptr = std::shared_ptr; @@ -72,7 +71,8 @@ class IParametersHandler * @param parameter parameter * @return true/false in case of success/failure */ - virtual bool getParameter(const std::string& parameterName, std::vector& parameter) const = 0; + virtual bool getParameter(const std::string& parameterName, // + std::vector& parameter) const = 0; /** * Get a parameter [GenericContainer::Vector] @@ -80,7 +80,8 @@ class IParametersHandler * @param parameter parameter * @return true/false in case of success/failure */ - virtual bool getParameter(const std::string& parameterName, GenericContainer::Vector::Ref parameter) const = 0; + virtual bool getParameter(const std::string& parameterName, + GenericContainer::Vector::Ref parameter) const = 0; /** * Get a parameter [GenericContainer::Vector] @@ -88,7 +89,8 @@ class IParametersHandler * @param parameter parameter * @return true/false in case of success/failure */ - virtual bool getParameter(const std::string& parameterName, GenericContainer::Vector::Ref parameter) const = 0; + virtual bool getParameter(const std::string& parameterName, + GenericContainer::Vector::Ref parameter) const = 0; /** * Get a parameter [GenericContainer::Vector] @@ -96,7 +98,8 @@ class IParametersHandler * @param parameter parameter * @return true/false in case of success/failure */ - virtual bool getParameter(const std::string& parameterName, GenericContainer::Vector::Ref parameter) const = 0; + virtual bool getParameter(const std::string& parameterName, + GenericContainer::Vector::Ref parameter) const = 0; /** * Set a parameter [int] @@ -135,34 +138,40 @@ class IParametersHandler */ virtual void setParameter(const std::string& parameterName, const bool& parameter) = 0; - /** * Set a parameter [std::vector] * @param parameterName name of the parameter * @param parameter parameter */ - virtual void setParameter(const std::string& parameterName, const std::vector& parameter) = 0; + virtual void setParameter(const std::string& parameterName, const std::vector& parameter) + = 0; /** * Set a parameter [GenericContainer::Vector] * @param parameterName name of the parameter * @param parameter parameter */ - virtual void setParameter(const std::string& parameterName, const GenericContainer::Vector::Ref parameter) = 0; + virtual void setParameter(const std::string& parameterName, + const GenericContainer::Vector::Ref parameter) + = 0; /** * Set a parameter [GenericContainer::Vector] * @param parameterName name of the parameter * @param parameter parameter */ - virtual void setParameter(const std::string& parameterName, const GenericContainer::Vector::Ref parameter) = 0; + virtual void setParameter(const std::string& parameterName, + const GenericContainer::Vector::Ref parameter) + = 0; /** * Set a parameter [GenericContainer::Vector] * @param parameterName name of the parameter * @param parameter parameter */ - virtual void setParameter(const std::string& parameterName, const GenericContainer::Vector::Ref parameter) = 0; + virtual void setParameter(const std::string& parameterName, + const GenericContainer::Vector::Ref parameter) + = 0; /** * Get a Group from the handler. @@ -211,7 +220,6 @@ class IParametersHandler * Destructor */ virtual ~IParametersHandler() = default; - }; } // namespace ParametersHandler } // namespace BipedalLocomotion From e8581ad7eb9c04ebbff6a6b719237f7405c06b4c Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Mon, 26 Apr 2021 23:52:00 +0200 Subject: [PATCH 3/9] Add IParameterHandler::clone() method --- .../ParametersHandler/IParametersHandler.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/IParametersHandler.h b/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/IParametersHandler.h index 531c67af14..4139f1bb4a 100644 --- a/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/IParametersHandler.h +++ b/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/IParametersHandler.h @@ -216,6 +216,14 @@ class IParametersHandler */ virtual void clear() = 0; + /** + * Clone the content of the content. + * @return a IParametersHandler::shared_ptr clone of the current handler. + * @warning Please implement the specific version of this method in the Derived class. Please + * check YarpImplementation::clone + */ + virtual shared_ptr clone() const = 0; + /** * Destructor */ From fc647539fcbfa216c089cb67b7bb58df73630165 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Mon, 26 Apr 2021 23:52:44 +0200 Subject: [PATCH 4/9] Add StdImplementation::clone() method in ParametersHandler component --- .../ParametersHandler/StdImplementation.h | 6 ++++++ src/ParametersHandler/src/StdImplementation.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/StdImplementation.h b/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/StdImplementation.h index 05d4840d2b..63efc0ff25 100644 --- a/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/StdImplementation.h +++ b/src/ParametersHandler/include/BipedalLocomotion/ParametersHandler/StdImplementation.h @@ -231,6 +231,12 @@ class StdImplementation : public IParametersHandler */ void clear() final; + /** + * Clone the content of the content. + * @return a IParametersHandler::shared_ptr clone of the current handler. + */ + shared_ptr clone() const final; + ~StdImplementation() = default; }; } // namespace ParametersHandler diff --git a/src/ParametersHandler/src/StdImplementation.cpp b/src/ParametersHandler/src/StdImplementation.cpp index d9b1ee63d9..77647d4a60 100644 --- a/src/ParametersHandler/src/StdImplementation.cpp +++ b/src/ParametersHandler/src/StdImplementation.cpp @@ -169,3 +169,13 @@ void StdImplementation::clear() { m_map.clear(); } + +IParametersHandler::shared_ptr StdImplementation::clone() const +{ + auto handler = std::make_shared(); + + // copy the content of the parameters stored in the handler. + handler->m_map = this->m_map; + + return handler; +} From 8b1448754d640892616ce687b1b2a5bb6df471c2 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Mon, 26 Apr 2021 23:53:39 +0200 Subject: [PATCH 5/9] Add Clone section in ParametersHandlerTest.cpp --- .../tests/ParametersHandlerTest.cpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/ParametersHandler/tests/ParametersHandlerTest.cpp b/src/ParametersHandler/tests/ParametersHandlerTest.cpp index bd2acea9f2..15e05ef284 100644 --- a/src/ParametersHandler/tests/ParametersHandlerTest.cpp +++ b/src/ParametersHandler/tests/ParametersHandlerTest.cpp @@ -112,4 +112,38 @@ TEST_CASE("Get parameters") parameterHandler->clear(); REQUIRE(parameterHandler->isEmpty()); } + + SECTION("Clone") + { + auto newHandler = parameterHandler->clone(); + REQUIRE_FALSE(newHandler->isEmpty()); + + SECTION("Get integer") + { + int element; + REQUIRE(newHandler->getParameter("answer_to_the_ultimate_question_of_life", element)); + REQUIRE(element == 42); + } + + SECTION("Get Double") + { + double element; + REQUIRE(newHandler->getParameter("pi", element)); + REQUIRE(element == 3.14); + } + + SECTION("Get String") + { + std::string element; + REQUIRE(newHandler->getParameter("John", element)); + REQUIRE(element == "Smith"); + } + + SECTION("Get Vector") + { + std::vector element; + REQUIRE(newHandler->getParameter("Fibonacci Numbers", element)); + REQUIRE(element == std::vector{1, 1, 2, 3, 5, 8, 13, 21}); + } + } } From e19975332cef4cb790b4fed0288b7077d4840ea7 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Tue, 27 Apr 2021 00:01:49 +0200 Subject: [PATCH 6/9] Add YarpImplementation::clone() method in ParametersHandler component --- .../ParametersHandler/YarpImplementation.h | 14 ++++++++++++++ .../src/YarpImplementation.cpp | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/ParametersHandler/YarpImplementation/include/BipedalLocomotion/ParametersHandler/YarpImplementation.h b/src/ParametersHandler/YarpImplementation/include/BipedalLocomotion/ParametersHandler/YarpImplementation.h index e60079239d..8a331bfffb 100644 --- a/src/ParametersHandler/YarpImplementation/include/BipedalLocomotion/ParametersHandler/YarpImplementation.h +++ b/src/ParametersHandler/YarpImplementation/include/BipedalLocomotion/ParametersHandler/YarpImplementation.h @@ -54,6 +54,13 @@ class YarpImplementation : public IParametersHandler */ template void setParameterPrivate(const std::string& parameterName, const T& parameter); + + /** + * Clone the content of the handler + * @return A pointer to YarpImplementation containing the content of the handler. + */ + std::shared_ptr clonePrivate() const; + public: /** * Constructor. @@ -235,6 +242,13 @@ class YarpImplementation : public IParametersHandler */ void clear() final; + /** + * Clone the content of the content. + * @return a IParametersHandler::shared_ptr clone of the current handler. + * @warning + */ + shared_ptr clone() const final; + /** * Destructor */ diff --git a/src/ParametersHandler/YarpImplementation/src/YarpImplementation.cpp b/src/ParametersHandler/YarpImplementation/src/YarpImplementation.cpp index ec6219eb5f..2ac685b6e2 100644 --- a/src/ParametersHandler/YarpImplementation/src/YarpImplementation.cpp +++ b/src/ParametersHandler/YarpImplementation/src/YarpImplementation.cpp @@ -201,3 +201,21 @@ void YarpImplementation::clear() m_container.clear(); m_lists.clear(); } + +std::shared_ptr YarpImplementation::clonePrivate() const +{ + auto handler = std::make_shared(); + + // copy the content of the parameters stored in the handler. + handler->m_container = this->m_container; + + for (const auto& [key, value] : m_lists) + handler->m_lists[key] = value->clonePrivate(); + + return handler; +} + +IParametersHandler::shared_ptr YarpImplementation::clone() const +{ + return this->clonePrivate(); +} From da03334bba36a40ba1118df7f7ac9998fe0b0f78 Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Tue, 27 Apr 2021 00:03:21 +0200 Subject: [PATCH 7/9] Use BipedalLocomotion::TextLogging in YarpImplementation in ParametersHandler component --- src/ParametersHandler/YarpImplementation/CMakeLists.txt | 2 +- .../YarpImplementation/src/YarpImplementation.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ParametersHandler/YarpImplementation/CMakeLists.txt b/src/ParametersHandler/YarpImplementation/CMakeLists.txt index b067b9407d..85c69db4a7 100644 --- a/src/ParametersHandler/YarpImplementation/CMakeLists.txt +++ b/src/ParametersHandler/YarpImplementation/CMakeLists.txt @@ -8,7 +8,7 @@ if(FRAMEWORK_COMPILE_YarpImplementation) NAME ParametersHandlerYarpImplementation SOURCES src/YarpImplementation.cpp PUBLIC_HEADERS include/BipedalLocomotion/ParametersHandler/YarpImplementation.h include/BipedalLocomotion/ParametersHandler/YarpImplementation.tpp - PUBLIC_LINK_LIBRARIES BipedalLocomotion::ParametersHandler BipedalLocomotion::YarpUtilities YARP::YARP_os + PUBLIC_LINK_LIBRARIES BipedalLocomotion::ParametersHandler BipedalLocomotion::YarpUtilities YARP::YARP_os BipedalLocomotion::TextLogging INSTALLATION_FOLDER ParametersHandler) endif() diff --git a/src/ParametersHandler/YarpImplementation/src/YarpImplementation.cpp b/src/ParametersHandler/YarpImplementation/src/YarpImplementation.cpp index 2ac685b6e2..1da6d9eeff 100644 --- a/src/ParametersHandler/YarpImplementation/src/YarpImplementation.cpp +++ b/src/ParametersHandler/YarpImplementation/src/YarpImplementation.cpp @@ -11,6 +11,7 @@ #include #include +#include using namespace BipedalLocomotion::ParametersHandler; @@ -159,9 +160,9 @@ bool YarpImplementation::setGroup(const std::string& name, IParametersHandler::s // m_container if (downcastedPtr == nullptr) { - std::cerr << "[YarpImplementation::setGroup] Unable to downcast the pointer to " - "YarpImplementation." - << std::endl; + log()->error("[YarpImplementation::setGroup] Unable to downcast the pointer to " + "YarpImplementation."); + return false; } From 5037064318678b7559058445352b066bdd3fe6da Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Tue, 27 Apr 2021 00:08:09 +0200 Subject: [PATCH 8/9] Add Clone section in ParametersHandlerYarpTest.cpp --- .../tests/ParametersHandlerYarpTest.cpp | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/ParametersHandler/tests/ParametersHandlerYarpTest.cpp b/src/ParametersHandler/tests/ParametersHandlerYarpTest.cpp index acf966feb7..72f0ea8d82 100644 --- a/src/ParametersHandler/tests/ParametersHandlerYarpTest.cpp +++ b/src/ParametersHandler/tests/ParametersHandlerYarpTest.cpp @@ -204,4 +204,52 @@ TEST_CASE("Get parameters") } } + SECTION("Clone") + { + IParametersHandler::shared_ptr setGroup = std::make_shared(); + REQUIRE(parameterHandler->setGroup("CARTOONS", setGroup)); + auto groupHandler = parameterHandler->getGroup("CARTOONS").lock(); //now the pointer should be lockable + REQUIRE(groupHandler); + REQUIRE(groupHandler->isEmpty()); + + groupHandler->setParameter("Donald's nephews", donaldsNephews); + + auto newHandler = parameterHandler->clone(); + + SECTION("Get integer") + { + int element; + REQUIRE(newHandler->getParameter("answer_to_the_ultimate_question_of_life", element)); + REQUIRE(element == 42); + } + + SECTION("Get Double") + { + double element; + REQUIRE(newHandler->getParameter("pi", element)); + REQUIRE(element == 3.14); + } + + SECTION("Get String") + { + std::string element; + REQUIRE(newHandler->getParameter("John", element)); + REQUIRE(element == "Smith"); + } + + SECTION("Get Vector") + { + std::vector element; + REQUIRE(newHandler->getParameter("Fibonacci Numbers", element)); + REQUIRE(element == fibonacciNumbers); + } + + SECTION("Get group") + { + std::vector element; + REQUIRE(newHandler->getGroup("CARTOONS").lock()->getParameter("Donald's nephews",// + element)); + REQUIRE(element == donaldsNephews); + } + } } From 0cd62db06874b62b5ab4c87cfcbfa8e6e7bde5dc Mon Sep 17 00:00:00 2001 From: Giulio Romualdi Date: Tue, 27 Apr 2021 00:10:55 +0200 Subject: [PATCH 9/9] Update the CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b1e636af..7ebf65820f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ All notable changes to this project are documented in this file. - Implement TaskSpaceInverseDynamics interface (https://github.com/dic-iit/bipedal-locomotion-framework/pull/279) - Implement `Wrench` class (https://github.com/dic-iit/bipedal-locomotion-framework/pull/279) - Implement `SO3Task` in `TSID` component (https://github.com/dic-iit/bipedal-locomotion-framework/pull/281) +- Implement clone method in ParametersHandler classes (https://github.com/dic-iit/bipedal-locomotion-framework/pull/288) ### Changed - Move all the Contacts related classes in Contacts component (https://github.com/dic-iit/bipedal-locomotion-framework/pull/204)