5#ifndef __eigenpy_deprecation_hpp__ 6#define __eigenpy_deprecation_hpp__ 8#include "eigenpy/fwd.hpp" 12enum class DeprecationType { DEPRECATION, FUTURE };
16inline PyObject *deprecationTypeToPyObj(DeprecationType dep) {
18 case DeprecationType::DEPRECATION:
19 return PyExc_DeprecationWarning;
20 case DeprecationType::FUTURE:
21 return PyExc_FutureWarning;
24 throw std::invalid_argument(
25 "Undefined DeprecationType - this should never be triggered.");
33template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
34 class BasePolicy = bp::default_call_policies>
35struct deprecation_warning_policy : BasePolicy {
36 using result_converter =
typename BasePolicy::result_converter;
37 using argument_package =
typename BasePolicy::argument_package;
39 deprecation_warning_policy(
const std::string &warning_msg)
40 : BasePolicy(), m_what(warning_msg) {}
42 std::string what()
const {
return m_what; }
44 const BasePolicy *derived()
const {
45 return static_cast<const BasePolicy *
>(
this);
48 template <
class ArgPackage>
49 bool precall(
const ArgPackage &args)
const {
50 PyErr_WarnEx(detail::deprecationTypeToPyObj(deprecation_type),
52 return derived()->precall(args);
56 const std::string m_what;
59template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
60 class BasePolicy = bp::default_call_policies>
61struct deprecated_function
62 : deprecation_warning_policy<deprecation_type, BasePolicy> {
63 deprecated_function(
const std::string &msg =
64 "This function has been marked as deprecated, and " 65 "will be removed in the future.")
66 : deprecation_warning_policy<deprecation_type, BasePolicy>(msg) {}
69template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
70 class BasePolicy = bp::default_call_policies>
71struct deprecated_member
72 : deprecation_warning_policy<deprecation_type, BasePolicy> {
73 deprecated_member(
const std::string &msg =
74 "This attribute or method has been marked as " 75 "deprecated, and will be removed in the future.")
76 : deprecation_warning_policy<deprecation_type, BasePolicy>(msg) {}