deprecation-policy.hpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2020 INRIA
3 // Copyright (C) 2024 LAAS-CNRS, INRIA
4 //
5 #ifndef __eigenpy_deprecation_hpp__
6 #define __eigenpy_deprecation_hpp__
7 
8 #include "eigenpy/fwd.hpp"
9 
10 namespace eigenpy {
11 
13 
14 namespace detail {
15 
16 inline PyObject *deprecationTypeToPyObj(DeprecationType dep) {
17  switch (dep) {
19  return PyExc_DeprecationWarning;
21  return PyExc_FutureWarning;
22  default: // The switch handles all cases explicitly, this should never be
23  // triggered.
24  throw std::invalid_argument(
25  "Undefined DeprecationType - this should never be triggered.");
26  }
27 }
28 
29 } // namespace detail
30 
33 template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
34  class BasePolicy = bp::default_call_policies>
35 struct deprecation_warning_policy : BasePolicy {
36  using result_converter = typename BasePolicy::result_converter;
37  using argument_package = typename BasePolicy::argument_package;
38 
39  deprecation_warning_policy(const std::string &warning_msg)
40  : BasePolicy(), m_what(warning_msg) {}
41 
42  std::string what() const { return m_what; }
43 
44  const BasePolicy *derived() const {
45  return static_cast<const BasePolicy *>(this);
46  }
47 
48  template <class ArgPackage>
49  bool precall(const ArgPackage &args) const {
50  PyErr_WarnEx(detail::deprecationTypeToPyObj(deprecation_type),
51  m_what.c_str(), 1);
52  return derived()->precall(args);
53  }
54 
55  protected:
56  const std::string m_what;
57 };
58 
59 template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
60  class BasePolicy = bp::default_call_policies>
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) {}
67 };
68 
69 template <DeprecationType deprecation_type = DeprecationType::DEPRECATION,
70  class BasePolicy = bp::default_call_policies>
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) {}
77 };
78 
79 } // namespace eigenpy
80 
81 #endif // ifndef __eigenpy_deprecation_hpp__
eigenpy::deprecation_warning_policy::m_what
const std::string m_what
Definition: deprecation-policy.hpp:56
eigenpy::detail::deprecationTypeToPyObj
PyObject * deprecationTypeToPyObj(DeprecationType dep)
Definition: deprecation-policy.hpp:16
eigenpy::DeprecationType::DEPRECATION
@ DEPRECATION
eigenpy::deprecated_member
Definition: deprecation-policy.hpp:71
fwd.hpp
eigenpy::deprecated_member::deprecated_member
deprecated_member(const std::string &msg="This attribute or method has been marked as " "deprecated, and will be removed in the future.")
Definition: deprecation-policy.hpp:73
eigenpy::DeprecationType
DeprecationType
Definition: deprecation-policy.hpp:12
eigenpy::deprecation_warning_policy::derived
const BasePolicy * derived() const
Definition: deprecation-policy.hpp:44
eigenpy
Definition: alignment.hpp:14
eigenpy::deprecation_warning_policy
A Boost.Python call policy which triggers a Python warning on precall.
Definition: deprecation-policy.hpp:35
eigenpy::deprecation_warning_policy::what
std::string what() const
Definition: deprecation-policy.hpp:42
eigenpy::deprecation_warning_policy< DeprecationType::DEPRECATION, bp::default_call_policies >::result_converter
typename bp::default_call_policies ::result_converter result_converter
Definition: deprecation-policy.hpp:36
eigenpy::deprecated_function::deprecated_function
deprecated_function(const std::string &msg="This function has been marked as deprecated, and " "will be removed in the future.")
Definition: deprecation-policy.hpp:63
eigenpy::DeprecationType::FUTURE
@ FUTURE
eigenpy::deprecation_warning_policy::precall
bool precall(const ArgPackage &args) const
Definition: deprecation-policy.hpp:49
eigenpy::deprecation_warning_policy< DeprecationType::DEPRECATION, bp::default_call_policies >::argument_package
typename bp::default_call_policies ::argument_package argument_package
Definition: deprecation-policy.hpp:37
eigenpy::deprecation_warning_policy::deprecation_warning_policy
deprecation_warning_policy(const std::string &warning_msg)
Definition: deprecation-policy.hpp:39
eigenpy::deprecated_function
Definition: deprecation-policy.hpp:61


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45