| 1 |
// |
| 2 |
// SPDX-License-Identifier: BSD-3-Clause |
| 3 |
// Copyright Contributors to the OpenEXR Project. |
| 4 |
// |
| 5 |
|
| 6 |
// clang-format off |
| 7 |
|
| 8 |
#ifndef INCLUDED_PYIMATH_DECORATORS_H |
| 9 |
#define INCLUDED_PYIMATH_DECORATORS_H |
| 10 |
|
| 11 |
#define BOOST_BIND_GLOBAL_PLACEHOLDERS |
| 12 |
#include <boost/python.hpp> |
| 13 |
|
| 14 |
namespace PyImath |
| 15 |
{ |
| 16 |
|
| 17 |
// These function add __copy__ and __deepcopy__ methods |
| 18 |
// to python classes by simply wrapping the copy constructors |
| 19 |
// This interface is needed for using these classes with |
| 20 |
// the python copy module. |
| 21 |
|
| 22 |
template <class T> |
| 23 |
static T |
| 24 |
copy(const T& x) |
| 25 |
{ |
| 26 |
return T(x); |
| 27 |
} |
| 28 |
|
| 29 |
template <class T> |
| 30 |
static T |
| 31 |
deepcopy(const T& x, boost::python::dict&) |
| 32 |
{ |
| 33 |
return copy(x); |
| 34 |
} |
| 35 |
|
| 36 |
template <class T, class X1, class X2, class X3> |
| 37 |
boost::python::class_<T,X1,X2,X3>& |
| 38 |
decoratecopy(boost::python::class_<T,X1,X2,X3>& cls) |
| 39 |
{ |
| 40 |
cls.def("__copy__",©<T>); |
| 41 |
cls.def("__deepcopy__",&deepcopy<T>); |
| 42 |
return cls; |
| 43 |
} |
| 44 |
|
| 45 |
} // namespace PyImath |
| 46 |
|
| 47 |
#endif // INCLUDED_PYIMATH_DECORATORS_H |
| 48 |
|