Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
pybindaliases.hpp File Reference

Pybind11 include and definitions. More...

#include <pybind11/pybind11.h>
+ Include dependency graph for pybindaliases.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PyBindStaticInit
 Utility struct to register python modules through static init. More...
 

Macros

#define Register_pymod(placeholdername)
 Register a python module init function using static initialisation.
 

Typedefs

using fct_sig = std::function< void(py::module &)>
 alias to pybind11 namespace
 

Functions

void register_pybind_init_func (fct_sig)
 Register a python module init function to be ran on init.
 

Detailed Description

Pybind11 include and definitions.

Author
Timothée David–Cléris (tim.s.nosp@m.hamr.nosp@m.ock@p.nosp@m.roto.nosp@m.n.me)

If we build shamrock executable we embed python in Shamrock hence the include pybind11/embed.h. If we build shamrock as python lib we import pybind11/pybind11.h. Both options defines a similar syntax for the python module definition, we can then wrap them conveniently in a single macro call.

Definition in file pybindaliases.hpp.

Macro Definition Documentation

◆ Register_pymod

#define Register_pymod (   placeholdername)
Value:
void pymod_##placeholdername(py::module &m); \
void (*pymod_ptr_##placeholdername)(py::module & m) = pymod_##placeholdername; \
PyBindStaticInit pymod_class_obj_##placeholdername(pymod_ptr_##placeholdername); \
void pymod_##placeholdername(py::module &m)
Utility struct to register python modules through static init.

Register a python module init function using static initialisation.

Usage (in any source files) :

Register_pymod(<python init module name>){
// You can define stuff in the python module object `m` like so :
py::class_<ShamrockCtx>(m, "Context")
.def(py::init<>())
}
#define Register_pymod(placeholdername)
Register a python module init function using static initialisation.

Definition at line 56 of file pybindaliases.hpp.

Typedef Documentation

◆ fct_sig

using fct_sig = std::function<void(py::module &)>

alias to pybind11 namespace

function signature used to register python modules

Definition at line 30 of file pybindaliases.hpp.

Function Documentation

◆ register_pybind_init_func()

void register_pybind_init_func ( fct_sig  fct)

Register a python module init function to be ran on init.

Register a python module init function to be ran on init.

Definition at line 59 of file pybindings.cpp.