35#ifndef NEKTAR_LIBUTILITIES_PYTHON_BASICUTILS_NEKFACTORY_HPP
36#define NEKTAR_LIBUTILITIES_PYTHON_BASICUTILS_NEKFACTORY_HPP
60template <std::
size_t N>
62 : integral_constant<std::size_t, N + 1>
71#pragma GCC visibility push(hidden)
86 template <
class... Args> std::shared_ptr<T>
create(Args... args)
89 py::object inst =
m_obj(args...);
92 return py::cast<std::shared_ptr<T>>(inst);
99#pragma GCC visibility pop
127template <
template <
typename,
typename,
typename...>
typename tFac,
128 typename tBase,
typename tKey,
typename... tParam>
146 DoRegister(
name, helper, std::index_sequence_for<tParam...>{});
151 std::string key =
"_" + nameKey;
155 py::capsule capsule(helper, [](
void *ptr) {
162 py::globals()[key.c_str()] = capsule;
170 template <std::size_t... Is>
172 std::integer_sequence<std::size_t, Is...>)
174 m_fac.RegisterCreatorFunction(
182 tFac<tKey, tBase, tParam...> &
m_fac;
void operator()(tKey &name, py::object &obj, std::string const &nameKey)
NekFactory_Register(tFac< tKey, tBase, tParam... > &fac)
void DoRegister(tKey &name, NekFactoryRegisterHelper< tBase > *helper, std::integer_sequence< std::size_t, Is... >)
Helper function to unpack parameter arguments into the factory's register creation function using the...
tFac< tKey, tBase, tParam... > & m_fac
Reference to the NekFactory.
Helper class to be used in NekFactory_Register. Stores the Python function used to call the creator f...
~NekFactoryRegisterHelper()=default
std::shared_ptr< T > create(Args... args)
Callback to Python instantiator function (typically a class constructor). Assumes that all arguments ...
NekFactoryRegisterHelper(py::object obj)
py::object m_obj
Python function that is used to construct objects.