The module_ class

class cpp2py.wrap_generator.module_(full_name, doc='', app_name=None)[source]

Representation of a module

add_class(cls)[source]

Add a class into the module. It should not exist in the module already.

add_converter(conv)[source]

Add a converter into the module. It should not exist in the module already.

add_enum(c_name, values, c_namespace='', doc='')[source]

Add an enum into the module.

Parameters:
  • c_name (string) – name in C++

  • c_namespace (string) – namespace of the enum

  • values (list of string) – represents the C++ enum values

  • doc (string) – the doc string.

add_function(signature, name=None, calling_pattern=None, doc='', release_GIL_and_enable_signal=False, c_name=None)[source]

Add a C++ overload to function of the module

Parameters:
  • signature (string) –

    signature of the function, with types, parameter names and defaut value rtype( arg1 name1, arg2 name2 = default2, ….) signature can be :

    • a string of 2 possible forms (i.e. c_name can be omitted) :
      • rtype (arg1 name1, arg2 name2 = default2, ….)

      • rtype c_name ( arg1 name1, arg2 name2 = default2, ….)

    • a dict : rtype -> string , args -> list of tuples [ (c_type, variable_name, default_value)]

    • rtype : the C++ type returned by the function. None for constructor

    default_value is None when there is no default.

  • name (string) – name given in Python

  • c_name (string) – name given in C++ If None, the C++ name extracted from the signature is used.

  • calling_pattern (string) –

    • Pattern to rewrite the call of the c++ function,

    • It is a string, using self_c, argument name and defining result at the end if rtype != void e.g., the default pattern is : auto result = self_c.method_name(a,b,c).

    • If None, the signature must contain c_name

  • doc (string) – the doc string.

  • release_GIL_and_enable_signal (boolean, expert only) –

    • For long functions in pure C++.

    • If True, the GIL is released in the call of the C++ function and restored after the call.

    • It also saves the signal handler of python and restores it after the call, and enables the C++ signal_handler.

    • This allows e.g. to intercept Ctrl-C during the long C++ function.

    • Requirement :

      The function wrapped MUST be pure C++, i.e. no call whatsoever to the python C API, directly or indirectly. otherwise the behaviour is undefined.

add_imports(*lst)[source]

Add a dependent import to the module.

add_include(*filenames)[source]

Add the filenames as C++ include in the generated wrapper and header.

add_preamble(preamble)[source]

Add the using statement into the generated wrapper (and NOT the header).

add_using(ns)[source]

Add the using statement into the generated wrapper (and NOT the header).

generate_code()[source]

Generate the wrapper and the header. The filenames are given in the sys.argv if self.app_name is set, generate a copy of the py_converter file with includes consistent with the installation (as opposed to the build): e.g. #include “a.hpp” in py_converter.hpp becomes

#include <app_name/a.hpp> in py_converter.hpp.app_name.install