eigenpy
3.13.0
Bindings between Numpy and Eigen using Boost.Python
Toggle main menu visibility
Loading...
Searching...
No Matches
deprecation-policy.hpp
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
12
enum class
DeprecationType { DEPRECATION, FUTURE };
13
14
namespace
detail {
15
16
inline
PyObject* deprecationTypeToPyObj(DeprecationType dep) {
17
switch
(dep) {
18
case
DeprecationType::DEPRECATION:
19
return
PyExc_DeprecationWarning;
20
case
DeprecationType::FUTURE:
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>
61
struct
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) {}
67
};
68
69
template
<DeprecationType deprecation_type = DeprecationType::DEPRECATION,
70
class
BasePolicy = bp::default_call_policies>
71
struct
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) {}
77
};
78
79
}
// namespace eigenpy
80
81
#endif
// ifndef __eigenpy_deprecation_hpp__
eigenpy
Definition
alignment.hpp:14
include
eigenpy
deprecation-policy.hpp
Generated by
1.17.0