-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc2c335
commit 82aa3f7
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
projects/utilities/public/SIREN/utilities/Pybind11Trampoline.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef SIREN_Pybind11Trampoline_H | ||
#define SIREN_Pybind11Trampoline_H | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#define SELF_OVERRIDE_PURE(selfname, BaseType, returnType, cfuncname, pyfuncname, ...) \ | ||
const BaseType * ref; \ | ||
if(selfname) { \ | ||
ref = selfname.cast<BaseType *>(); \ | ||
} else { \ | ||
ref = this; \ | ||
} \ | ||
do { \ | ||
do { \ | ||
pybind11::gil_scoped_acquire gil; \ | ||
pybind11::function override \ | ||
= pybind11::get_override(static_cast<const BaseType *>(ref), pyfuncname); \ | ||
if (override) { \ | ||
auto o = override(__VA_ARGS__); \ | ||
if (pybind11::detail::cast_is_temporary_value_reference<returnType>::value) { \ | ||
static pybind11::detail::override_caster_t<returnType> caster; \ | ||
return pybind11::detail::cast_ref<returnType>(std::move(o), caster); \ | ||
} \ | ||
return pybind11::detail::cast_safe<returnType>(std::move(o)); \ | ||
} \ | ||
} while (false); \ | ||
pybind11::pybind11_fail( \ | ||
"Tried to call pure virtual function \"" PYBIND11_STRINGIFY(BaseType) "::" #cfuncname "\""); \ | ||
} while (false); | ||
|
||
#define SELF_OVERRIDE(selfname, BaseType, returnType, cfuncname, pyfuncname, ...) \ | ||
const BaseType * ref; \ | ||
if(selfname) { \ | ||
ref = selfname.cast<BaseType *>(); \ | ||
} else { \ | ||
ref = this; \ | ||
} \ | ||
do { \ | ||
do { \ | ||
pybind11::gil_scoped_acquire gil; \ | ||
pybind11::function override \ | ||
= pybind11::get_override(static_cast<const BaseType *>(ref), pyfuncname); \ | ||
if (override) { \ | ||
auto o = override(__VA_ARGS__); \ | ||
if (pybind11::detail::cast_is_temporary_value_reference<returnType>::value) { \ | ||
static pybind11::detail::override_caster_t<returnType> caster; \ | ||
return pybind11::detail::cast_ref<returnType>(std::move(o), caster); \ | ||
} \ | ||
return pybind11::detail::cast_safe<returnType>(std::move(o)); \ | ||
} \ | ||
} while (false); \ | ||
return BaseType::cfuncname(__VA_ARGS__); \ | ||
} while (false); | ||
|
||
#endif // SIREN_Pybind11Trampoline_H |