Line |
Branch |
Exec |
Source |
1 |
|
|
// |
2 |
|
|
// Copyright (c) 2020-2021 INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#ifndef COAL_PYTHON_UTILS_DEPRECATION_H |
6 |
|
|
#define COAL_PYTHON_UTILS_DEPRECATION_H |
7 |
|
|
|
8 |
|
|
#include <Python.h> |
9 |
|
|
#include <boost/python.hpp> |
10 |
|
|
#include <string> |
11 |
|
|
|
12 |
|
|
namespace coal { |
13 |
|
|
namespace python { |
14 |
|
|
|
15 |
|
|
template <class Policy = boost::python::default_call_policies> |
16 |
|
|
struct deprecated_warning_policy : Policy { |
17 |
|
40 |
deprecated_warning_policy(const std::string& warning_message = "") |
18 |
|
40 |
: Policy(), m_warning_message(warning_message) {} |
19 |
|
|
|
20 |
|
|
template <class ArgumentPackage> |
21 |
|
✗ |
bool precall(ArgumentPackage const& args) const { |
22 |
|
✗ |
PyErr_WarnEx(PyExc_DeprecationWarning, m_warning_message.c_str(), 1); |
23 |
|
✗ |
return static_cast<const Policy*>(this)->precall(args); |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
typedef typename Policy::result_converter result_converter; |
27 |
|
|
typedef typename Policy::argument_package argument_package; |
28 |
|
|
|
29 |
|
|
protected: |
30 |
|
|
const std::string m_warning_message; |
31 |
|
|
}; |
32 |
|
|
|
33 |
|
|
template <class Policy = boost::python::default_call_policies> |
34 |
|
|
struct deprecated_member : deprecated_warning_policy<Policy> { |
35 |
|
10 |
deprecated_member(const std::string& warning_message = |
36 |
|
|
"This class member has been marked as deprecated and " |
37 |
|
|
"will be removed in a future release.") |
38 |
|
10 |
: deprecated_warning_policy<Policy>(warning_message) {} |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
|
template <class Policy = boost::python::default_call_policies> |
42 |
|
|
struct deprecated_function : deprecated_warning_policy<Policy> { |
43 |
|
|
deprecated_function(const std::string& warning_message = |
44 |
|
|
"This function has been marked as deprecated and " |
45 |
|
|
"will be removed in a future release.") |
46 |
|
|
: deprecated_warning_policy<Policy>(warning_message) {} |
47 |
|
|
}; |
48 |
|
|
|
49 |
|
|
} // namespace python |
50 |
|
|
} // namespace coal |
51 |
|
|
|
52 |
|
|
#endif // ifndef COAL_PYTHON_UTILS_DEPRECATION_H |
53 |
|
|
|