From 11197c1d3690679f4fd223b6c3efa6585a56884c Mon Sep 17 00:00:00 2001 From: Marco Randazzo Date: Wed, 22 Jan 2025 12:35:18 +0100 Subject: [PATCH] added conditional compilation to make the ret_value work even without c++20 --- src/libYARP_dev/src/yarp/dev/ReturnValue.h | 25 ++++++++++++++++------ src/libYARP_dev/tests/ReturnValueTest.cpp | 14 ++++++++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/libYARP_dev/src/yarp/dev/ReturnValue.h b/src/libYARP_dev/src/yarp/dev/ReturnValue.h index 8be242c9d56..6c536e9b43f 100644 --- a/src/libYARP_dev/src/yarp/dev/ReturnValue.h +++ b/src/libYARP_dev/src/yarp/dev/ReturnValue.h @@ -71,19 +71,32 @@ class YARP_dev_API yarp_ret_value : public yarp::os::Portable #define yarp_ret_value_ok yarp_ret_value(yarp::dev::yarp_ret_value::return_code::return_value_ok) -inline yarp_ret_value YARP_METHOD_NOT_YET_IMPLEMENTED() +#if __cplusplus >= 202002L +inline yarp_ret_value YARP_METHOD_NOT_YET_IMPLEMENTED(const std::source_location& location = std::source_location::current()) { - const std::source_location& location = std::source_location::current(); yError("Method %s not yet implemented\n", location.function_name()); return yarp_ret_value(yarp::dev::yarp_ret_value::return_code::return_value_error_not_implemented_by_device); } - -inline yarp_ret_value YARP_METHOD_DEPRECATED() +inline yarp_ret_value YARP_METHOD_DEPRECATED(const std::source_location& location = std::source_location::current()) +{ + yError("Method %s has been deprecated\n", location.function_name()); + return yarp_ret_value(yarp::dev::yarp_ret_value::return_code::return_value_error_deprecated); +} +#else +inline yarp_ret_value yarp_method_not_implemented(const char* location) { - const std::source_location& location = std::source_location::current(); - yError("Method %s has been deprecated!\n", location.function_name()); + yError("Method %s not yet implemented\n", location); + return yarp_ret_value(yarp::dev::yarp_ret_value::return_code::return_value_error_not_implemented_by_device); +} +#define YARP_METHOD_NOT_YET_IMPLEMENTED() yarp_method_not_implemented(__func__) +inline yarp_ret_value yarp_method_deprecated(const char* location) +{ + yError("Method %s has been deprecated\n", location); return yarp_ret_value(yarp::dev::yarp_ret_value::return_code::return_value_error_deprecated); } +#define YARP_METHOD_DEPRECATED() yarp_method_deprecated(__func__) +#endif + } diff --git a/src/libYARP_dev/tests/ReturnValueTest.cpp b/src/libYARP_dev/tests/ReturnValueTest.cpp index 402161f6c95..491e5473980 100644 --- a/src/libYARP_dev/tests/ReturnValueTest.cpp +++ b/src/libYARP_dev/tests/ReturnValueTest.cpp @@ -11,6 +11,16 @@ using namespace yarp::dev; +yarp_ret_value test_method1() +{ + return YARP_METHOD_NOT_YET_IMPLEMENTED(); +} + +yarp_ret_value test_method2() +{ + return YARP_METHOD_DEPRECATED(); +} + TEST_CASE("dev::ReturnValue", "[yarp::dev]") { #ifndef DISABLE_BOOL_INPUT @@ -188,11 +198,11 @@ TEST_CASE("dev::ReturnValue", "[yarp::dev]") SECTION("test block 7") { - auto ret1 = YARP_METHOD_NOT_YET_IMPLEMENTED(); + auto ret1 = test_method1(); CHECK(ret1 == yarp_ret_value::return_code::return_value_error_not_implemented_by_device); CHECK(!(ret1 == yarp_ret_value::return_code::return_value_ok)); - auto ret2 = YARP_METHOD_DEPRECATED(); + auto ret2 = test_method2(); CHECK(ret2 == yarp_ret_value::return_code::return_value_error_deprecated); CHECK(!(ret2 == yarp_ret_value::return_code::return_value_ok)); }