HepMC3 event record library
Data Structures | Public Member Functions | Static Public Member Functions | Data Fields | Protected Attributes
module_ Class Reference

Wrapper for Python extension modules. More...

#include <pybind11.h>

+ Inheritance diagram for module_:
+ Collaboration diagram for module_:

Data Structures

struct  module_def
 

Public Member Functions

 module_ (const char *name, const char *doc=nullptr)
 Create a new top-level Python module with the given name and docstring. More...
 
template<typename Func , typename... Extra>
module_def (const char *name_, Func &&f, const Extra &... extra)
 
module_ def_submodule (const char *name, const char *doc=nullptr)
 
void reload ()
 Reload the module or throws error_already_set. More...
 
PYBIND11_NOINLINE void add_object (const char *name, handle obj, bool overwrite=false)
 
 PYBIND11_DEPRECATED ("Use reinterpret_borrow<object>() or reinterpret_steal<object>()") object(handle h
 
handle release ()
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
template<typename T >
cast () const &
 
template<typename T >
cast () &&
 
template<>
void cast () const &
 
template<>
void cast () &&
 
template<typename T >
cast () const
 
PyObject * ptr () const
 Return the underlying PyObject * pointer. More...
 
PyObject *& ptr ()
 
const handleinc_ref () const &
 
const handledec_ref () const &
 
 operator bool () const
 Return true when the handle wraps a valid Python object. More...
 
bool operator== (const handle &h) const
 
bool operator!= (const handle &h) const
 
bool check () const
 

Static Public Member Functions

static module_ import (const char *name)
 Import and return a module or throws error_already_set. More...
 
static module_ create_extension_module (const char *name, const char *doc, module_def *def)
 

Data Fields

bool is_borrowed: handle(h) { if (is_borrowed) inc_ref()
 

Protected Attributes

PyObject * m_ptr = nullptr
 

Detailed Description

Wrapper for Python extension modules.

Definition at line 891 of file pybind11.h.

Constructor & Destructor Documentation

◆ module_()

module_ ( const char *  name,
const char *  doc = nullptr 
)
inlineexplicit

Create a new top-level Python module with the given name and docstring.

Definition at line 897 of file pybind11.h.

References create_extension_module().

Member Function Documentation

◆ add_object()

PYBIND11_NOINLINE void add_object ( const char *  name,
handle  obj,
bool  overwrite = false 
)
inline

\rst Adds an object to the module using the given name. Throws if an object with the given name already exists.

overwrite should almost always be false: attempting to overwrite objects that pybind11 has established will, in most cases, break things. \endrst

Definition at line 963 of file pybind11.h.

◆ cast()

T cast
inherited

\rst Attempt to cast the Python object into the given C++ type. A cast_error will be throw upon failure. \endrst

Definition at line 1743 of file cast.h.

◆ create_extension_module()

static module_ create_extension_module ( const char *  name,
const char *  doc,
module_def def 
)
inlinestatic

\rst Create a new top-level module that can be used as the main module of a C extension.

For Python 3, def should point to a staticly allocated module_def. For Python 2, def can be a nullptr and is completely ignored. \endrst

Definition at line 983 of file pybind11.h.

References def().

◆ dec_ref()

const handle& dec_ref ( ) const &
inlineinherited

\rst Manually decrease the reference count of the Python object. Usually, it is preferable to use the object class which derives from handle and calls this function automatically. Returns a reference to itself. \endrst

Definition at line 199 of file pytypes.h.

◆ def()

module_& def ( const char *  name_,
Func &&  f,
const Extra &...  extra 
)
inline

\rst Create Python binding for a new function within the module scope. Func can be a plain C++ function, a function pointer, or a lambda function. For details on the Extra&& ... extra argument, see section :ref:extras. \endrst

Definition at line 911 of file pybind11.h.

◆ def_submodule()

module_ def_submodule ( const char *  name,
const char *  doc = nullptr 
)
inline

\rst Create and return a new Python submodule with the given name and docstring. This also works recursively, i.e.

.. code-block:: cpp

py::module_ m("example", "pybind11 example plugin");
py::module_ m2 = m.def_submodule("sub", "A submodule of 'example'");
py::module_ m3 = m2.def_submodule("subsub", "A submodule of 'example.sub'");

\endrst

Definition at line 930 of file pybind11.h.

◆ import()

static module_ import ( const char *  name)
inlinestatic

Import and return a module or throws error_already_set.

Definition at line 941 of file pybind11.h.

◆ inc_ref()

const handle& inc_ref ( ) const &
inlineinherited

\rst Manually increase the reference count of the Python object. Usually, it is preferable to use the object class which derives from handle and calls this function automatically. Returns a reference to itself. \endrst

Definition at line 192 of file pytypes.h.

◆ operator bool()

operator bool ( ) const
inlineexplicitinherited

Return true when the handle wraps a valid Python object.

Definition at line 207 of file pytypes.h.

◆ operator==()

bool operator== ( const handle h) const
inlineinherited

\rst Deprecated: Check that the underlying pointers are the same. Equivalent to obj1 is obj2 in Python. \endrst

Definition at line 213 of file pytypes.h.

◆ ptr()

PyObject* ptr ( ) const
inlineinherited

Return the underlying PyObject * pointer.

Definition at line 184 of file pytypes.h.

◆ release()

handle release ( )
inlineinherited

\rst Resets the internal pointer to nullptr without decreasing the object's reference count. The function returns a raw handle to the original Python object. \endrst

Definition at line 249 of file pytypes.h.

References handle::handle().

◆ reload()

void reload ( )
inline

Reload the module or throws error_already_set.

Definition at line 949 of file pybind11.h.

References handle::ptr().


The documentation for this class was generated from the following file: