2021-04-14 20:08:25 +00:00
|
|
|
#include "pybind11_tests.h"
|
|
|
|
|
2024-07-31 13:17:31 +00:00
|
|
|
// The main purpose of this test was to ensure that the suggested
|
|
|
|
// BOILERPLATE code block (NOW DEPRECATED!) block below is correct.
|
2021-04-14 20:08:25 +00:00
|
|
|
|
|
|
|
// Copy this block of code into your project.
|
|
|
|
// Replace FOOEXT with the name of your project.
|
2024-07-31 13:17:31 +00:00
|
|
|
// BOILERPLATE BEGIN DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED
|
2021-04-14 20:08:25 +00:00
|
|
|
#ifdef FOOEXT_USING_PYBIND11_SMART_HOLDER
|
|
|
|
# include <pybind11/smart_holder.h>
|
|
|
|
#else
|
|
|
|
# include <pybind11/pybind11.h>
|
|
|
|
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
2024-08-04 16:16:44 +00:00
|
|
|
# ifndef PYBIND11_HAS_INTERNALS_WITH_SMART_HOLDER_SUPPORT
|
2021-04-14 20:08:25 +00:00
|
|
|
template <typename type_, typename... options>
|
|
|
|
using classh = class_<type_, options...>;
|
2024-07-31 13:17:31 +00:00
|
|
|
# endif
|
2021-04-14 20:08:25 +00:00
|
|
|
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|
2021-04-19 17:54:37 +00:00
|
|
|
# ifndef PYBIND11_SH_AVL
|
|
|
|
# define PYBIND11_SH_AVL(...) std::shared_ptr<__VA_ARGS__> // "Smart_Holder if AVaiLable"
|
|
|
|
# endif
|
|
|
|
# ifndef PYBIND11_SH_DEF
|
|
|
|
# define PYBIND11_SH_DEF(...) std::shared_ptr<__VA_ARGS__> // "Smart_Holder if DEFault"
|
|
|
|
# endif
|
2021-04-14 20:08:25 +00:00
|
|
|
# ifndef PYBIND11_SMART_HOLDER_TYPE_CASTERS
|
|
|
|
# define PYBIND11_SMART_HOLDER_TYPE_CASTERS(...)
|
|
|
|
# endif
|
|
|
|
# ifndef PYBIND11_TYPE_CASTER_BASE_HOLDER
|
|
|
|
# define PYBIND11_TYPE_CASTER_BASE_HOLDER(...)
|
|
|
|
# endif
|
|
|
|
#endif
|
2024-07-31 13:17:31 +00:00
|
|
|
// BOILERPLATE END DEPRECATED DEPRECATED DEPRECATED DEPRECATED DEPRECATED
|
2021-04-14 20:08:25 +00:00
|
|
|
|
|
|
|
namespace {
|
2021-04-19 17:54:37 +00:00
|
|
|
struct FooUc {};
|
|
|
|
struct FooUp {};
|
|
|
|
struct FooSa {};
|
|
|
|
struct FooSc {};
|
|
|
|
struct FooSp {};
|
2021-04-14 20:08:25 +00:00
|
|
|
} // namespace
|
|
|
|
|
2024-07-31 13:17:31 +00:00
|
|
|
PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooUp) // DEPRECATED
|
|
|
|
PYBIND11_SMART_HOLDER_TYPE_CASTERS(FooSp) // DEPRECATED
|
2021-04-19 17:54:37 +00:00
|
|
|
|
|
|
|
PYBIND11_TYPE_CASTER_BASE_HOLDER(FooSa, std::shared_ptr<FooSa>)
|
2021-04-14 20:08:25 +00:00
|
|
|
|
|
|
|
TEST_SUBMODULE(classh_mock, m) {
|
2021-04-19 17:54:37 +00:00
|
|
|
// Please see README_smart_holder.rst, in particular section
|
|
|
|
// Classic / Conservative / Progressive cross-module compatibility
|
|
|
|
|
|
|
|
// Uses std::unique_ptr<FooUc> as holder in Classic or Conservative mode, py::smart_holder in
|
|
|
|
// Progressive mode.
|
|
|
|
py::class_<FooUc>(m, "FooUc").def(py::init<>());
|
|
|
|
|
|
|
|
// Uses std::unique_ptr<FooUp> as holder in Classic mode, py::smart_holder in Conservative or
|
|
|
|
// Progressive mode.
|
|
|
|
py::classh<FooUp>(m, "FooUp").def(py::init<>());
|
|
|
|
|
|
|
|
// Always uses std::shared_ptr<FooSa> as holder.
|
|
|
|
py::class_<FooSa, std::shared_ptr<FooSa>>(m, "FooSa").def(py::init<>());
|
2021-04-14 20:08:25 +00:00
|
|
|
|
2021-04-19 17:54:37 +00:00
|
|
|
// Uses std::shared_ptr<FooSc> as holder in Classic or Conservative mode, py::smart_holder in
|
|
|
|
// Progressive mode.
|
|
|
|
py::class_<FooSc, PYBIND11_SH_DEF(FooSc)>(m, "FooSc").def(py::init<>());
|
|
|
|
// -------------- std::shared_ptr<FooSc> -- same length by design, to not disturb the
|
|
|
|
// indentation of existing code.
|
2021-04-14 20:08:25 +00:00
|
|
|
|
2021-04-19 17:54:37 +00:00
|
|
|
// Uses std::shared_ptr<FooSp> as holder in Classic mode, py::smart_holder in Conservative or
|
|
|
|
// Progressive mode.
|
|
|
|
py::class_<FooSp, PYBIND11_SH_AVL(FooSp)>(m, "FooSp").def(py::init<>());
|
|
|
|
// -------------- std::shared_ptr<FooSp> -- same length by design, to not disturb the
|
|
|
|
// indentation of existing code.
|
2021-04-14 20:08:25 +00:00
|
|
|
}
|