Nektar++
Public Member Functions | Protected Attributes | List of all members
NekFactoryRegisterHelper< T > Class Template Reference

Helper class to be used in NekFactory_Register. Stores the Python function used to call the creator function. More...

#include <NekFactory.hpp>

Public Member Functions

 NekFactoryRegisterHelper (py::object obj)
 
 ~NekFactoryRegisterHelper ()
 
template<class... Args>
std::shared_ptr< T > create (Args... args)
 Callback to Python instantiator function (typically a class constructor). Assumes that all arguments can be converted to boost.python through converter infrastructure. More...
 

Protected Attributes

py::object m_obj
 Python function that is used to construct objects. More...
 

Detailed Description

template<class T>
class NekFactoryRegisterHelper< T >

Helper class to be used in NekFactory_Register. Stores the Python function used to call the creator function.

Definition at line 73 of file Python/BasicUtils/NekFactory.hpp.

Constructor & Destructor Documentation

◆ NekFactoryRegisterHelper()

template<class T >
NekFactoryRegisterHelper< T >::NekFactoryRegisterHelper ( py::object  obj)
inline

Definition at line 76 of file Python/BasicUtils/NekFactory.hpp.

76 : m_obj(obj)
77 {
78 py::incref(obj.ptr());
79 }
py::object m_obj
Python function that is used to construct objects.

◆ ~NekFactoryRegisterHelper()

template<class T >
NekFactoryRegisterHelper< T >::~NekFactoryRegisterHelper ( )
inline

Definition at line 81 of file Python/BasicUtils/NekFactory.hpp.

82 {
83 py::decref(m_obj.ptr());
84 }

References NekFactoryRegisterHelper< T >::m_obj.

Member Function Documentation

◆ create()

template<class T >
template<class... Args>
std::shared_ptr< T > NekFactoryRegisterHelper< T >::create ( Args...  args)
inline

Callback to Python instantiator function (typically a class constructor). Assumes that all arguments can be converted to boost.python through converter infrastructure.

Definition at line 91 of file Python/BasicUtils/NekFactory.hpp.

92 {
93 // Create an object using the Python callable.
94 py::object inst = m_obj(args...);
95
96 // Assume that it returns an object of the appropriate type.
97 return py::extract<std::shared_ptr<T>>(inst);
98 }

References NekFactoryRegisterHelper< T >::m_obj.

Member Data Documentation

◆ m_obj

template<class T >
py::object NekFactoryRegisterHelper< T >::m_obj
protected

Python function that is used to construct objects.

Definition at line 102 of file Python/BasicUtils/NekFactory.hpp.

Referenced by NekFactoryRegisterHelper< T >::create(), and NekFactoryRegisterHelper< T >::~NekFactoryRegisterHelper().