The class_ class

class cpp2py.wrap_generator.class_(py_type, c_type, c_type_absolute=None, hdf5=False, arithmetic=None, serializable=None, export=True, is_printable=False, doc='', comparisons='')[source]

Representation of a wrapped type

add_call(**kw)[source]

Add the __call__ operator.

It just calls add_method, for the operator(), with name = “__call__”

Cf add_method documentation.

add_constructor(signature, calling_pattern=None, intermediate_type=None, doc='')[source]
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.

  • calling_pattern (string, expert only) –
    • Pattern to rewrite the call of the c++ constructor.
    • It is a string, argument name and defining a result of the c_type e.g., the default pattern is :: auto result = c_type (a,b,c)
  • intermediate_type (string) –
    • Name of a C++ type to be used for constructing the object which is then constructed as c_type { intermediate_type {….}} E.g. Put a regular_type here when wrapping a view.
  • doc (string) – the doc string.
add_getitem(signature, calling_pattern=None, doc='operator[]')[source]

Add a the __getitem__ operator

add_iterator(c_type='const_iterator', c_cast_type=None, begin='std::begin', end='std::end')[source]

Add an iterator, wrapping a C++ iterator.

Parameters:
  • c_type (string) – type of the C++ variable
  • c_cast_type (string) – If not None, the result of the C++ iterator dereference if converted to the cast_type.
  • end (begin,) – Functions to find begin and end.
add_len(c_name=None, calling_pattern=None, doc='Length')[source]

Add the len operator

add_member(c_name, c_type, py_name=None, read_only=False, doc='')[source]

Add a class member

Parameters:
  • c_name (string) – name of the variable in C++
  • c_type (string) – type of the C++ variable
  • py_name (string) – name of the variable in python. If None, use c_name.
  • read_only (boolean) – is a read only parameter
  • doc (string) – the doc string.
add_method(signature, name=None, calling_pattern=None, no_self_c=False, is_method=False, is_static=False, doc='', release_GIL_and_enable_signal=False, c_name=None)[source]

Add a C++ overload to a method of name name.

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
  • no_self_c (boolean.) – do not generate self_c reference in C++ code, in some rare calling_pattern. Avoid a compiler warning.
  • is_method (boolean) –
  • is_static (boolean) – Is is a static method
  • 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_method_copy(clone_function='cpp2py::make_clone')[source]

Add a method copy, that make a deep copy, using the clone function

add_method_copy_from()[source]

Add a copy_from, using C++ assignment

add_method_cpp_copy()[source]

Add a method sh_copy, that make an ordinary copy in C++

add_property(getter, setter=None, name=None, doc='')[source]

Add a property

Parameters:
  • getter (-) –
  • setter (-) –
  • name (-) –
  • doc (-) –
add_regular_type_converter()[source]
add_setitem(signature, calling_pattern=None, doc='operator[]', **d)[source]

Add a the __setitem__ operator

deduce_inplace_arithmetic()[source]

Deduce all the +=, -=, *=, /= operators from the +, -, *, / operators