Skip to content
Snippets Groups Projects
Commit 83d054ac authored by Wilson Jallet's avatar Wilson Jallet :clapper:
Browse files

Add deprecated_function/deprecated_member child classes


+ shortcut for different default messages

Co-authored-by: default avatarJustin Carpentier <justin.carpentier@inria.fr>
parent 9d235685
No related branches found
No related tags found
No related merge requests found
Pipeline #39741 failed
// //
// Copyright (C) 2020 INRIA
// Copyright (C) 2024 LAAS-CNRS, INRIA // Copyright (C) 2024 LAAS-CNRS, INRIA
// //
#ifndef __eigenpy_deprecation_hpp__ #ifndef __eigenpy_deprecation_hpp__
...@@ -23,11 +24,6 @@ constexpr PyObject *deprecationTypeToPyObj(DeprecationType dep) { ...@@ -23,11 +24,6 @@ constexpr PyObject *deprecationTypeToPyObj(DeprecationType dep) {
} // namespace detail } // namespace detail
constexpr char defaultDeprecationMessage[] =
"This function or attribute has been marked as deprecated, and will be "
"removed in the "
"future.";
/// @brief A Boost.Python call policy which triggers a Python warning on /// @brief A Boost.Python call policy which triggers a Python warning on
/// precall. /// precall.
template <DeprecationType deprecation_type = DeprecationType::DEPRECATION, template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
...@@ -36,11 +32,10 @@ struct deprecation_warning_policy : BasePolicy { ...@@ -36,11 +32,10 @@ struct deprecation_warning_policy : BasePolicy {
using result_converter = typename BasePolicy::result_converter; using result_converter = typename BasePolicy::result_converter;
using argument_package = typename BasePolicy::argument_package; using argument_package = typename BasePolicy::argument_package;
deprecation_warning_policy( deprecation_warning_policy(const std::string &warning_msg)
const std::string &warning_msg = defaultDeprecationMessage)
: BasePolicy(), m_what(warning_msg) {} : BasePolicy(), m_what(warning_msg) {}
const std::string what() const { return m_what; } std::string what() const { return m_what; }
const BasePolicy *derived() const { const BasePolicy *derived() const {
return static_cast<const BasePolicy *>(this); return static_cast<const BasePolicy *>(this);
...@@ -53,10 +48,34 @@ struct deprecation_warning_policy : BasePolicy { ...@@ -53,10 +48,34 @@ struct deprecation_warning_policy : BasePolicy {
return derived()->precall(args); return derived()->precall(args);
} }
private: protected:
const std::string m_what; const std::string m_what;
}; };
template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
class BasePolicy = bp::default_call_policies>
struct deprecated_function
: deprecation_warning_policy<deprecation_type, BasePolicy> {
static constexpr char defaultMsg[] =
"This function has been marked as deprecated, and will be "
"removed in the future.";
deprecated_function(const std::string &msg = defaultMsg)
: deprecation_warning_policy<deprecation_type, BasePolicy>(msg) {}
};
template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
class BasePolicy = bp::default_call_policies>
struct deprecated_member
: deprecation_warning_policy<deprecation_type, BasePolicy> {
static constexpr char defaultMsg[] =
"This attribute or method has been marked as deprecated, and will be "
"removed in the future.";
deprecated_member(const std::string &msg = defaultMsg)
: deprecation_warning_policy<deprecation_type, BasePolicy>(msg) {}
};
} // namespace eigenpy } // namespace eigenpy
#endif // ifndef __eigenpy_deprecation_hpp__ #endif // ifndef __eigenpy_deprecation_hpp__
...@@ -16,9 +16,18 @@ void some_future_deprecated_function() { ...@@ -16,9 +16,18 @@ void some_future_deprecated_function() {
<< std::endl; << std::endl;
} }
class X {
public:
void deprecated_member_function() {}
};
BOOST_PYTHON_MODULE(deprecation_policy) { BOOST_PYTHON_MODULE(deprecation_policy) {
bp::def("some_deprecated_function", some_deprecated_function, bp::def("some_deprecated_function", some_deprecated_function,
eigenpy::deprecation_warning_policy<DeprecationType::DEPRECATION>()); eigenpy::deprecated_function<DeprecationType::DEPRECATION>());
bp::def("some_future_deprecated_function", some_future_deprecated_function, bp::def("some_future_deprecated_function", some_future_deprecated_function,
eigenpy::deprecation_warning_policy<DeprecationType::FUTURE>()); eigenpy::deprecated_function<DeprecationType::FUTURE>());
bp::class_<X>("X", bp::init<>(bp::args("self")))
.def("deprecated_member_function", &X::deprecated_member_function,
eigenpy::deprecated_member<>());
} }
from deprecation_policy import some_deprecated_function, some_future_deprecated_function from deprecation_policy import (
X,
some_deprecated_function,
some_future_deprecated_function,
)
some_deprecated_function() some_deprecated_function()
some_future_deprecated_function() some_future_deprecated_function()
X().deprecated_member_function()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment