Skip to content

Commit

Permalink
added conditional compilation to make the ret_value work even without…
Browse files Browse the repository at this point in the history
… c++20
  • Loading branch information
randaz81 committed Jan 22, 2025
1 parent ea0865a commit 11197c1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
25 changes: 19 additions & 6 deletions src/libYARP_dev/src/yarp/dev/ReturnValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


}

Expand Down
14 changes: 12 additions & 2 deletions src/libYARP_dev/tests/ReturnValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 11197c1

Please sign in to comment.