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