cppattribute: wrap class/instance attributes

Wraps C++ class instance/static attributes.

class pybindgen.cppattribute.CppInstanceAttributeGetter(value_type, class_, attribute_name, getter=None)

Bases: pybindgen.cppattribute.PyGetter

A getter for a C++ instance attribute.

Parameters:
  • value_type – a ReturnValue object handling the value type;
  • class – the class (CppClass object)
  • attribute_name – name of attribute
  • getter – None, or name of a method of the class used to get the value
generate(code_sink)
Parameters:code_sink – a CodeSink instance that will receive the generated code
generate_call()

virtual method implementation; do not call

class pybindgen.cppattribute.CppInstanceAttributeSetter(value_type, class_, attribute_name, setter=None)

Bases: pybindgen.cppattribute.PySetter

A setter for a C++ instance attribute.

Parameters:
  • value_type – a ReturnValue object handling the value type;
  • class – the class (CppClass object)
  • attribute_name – name of attribute
  • setter – None, or name of a method of the class used to set the value
generate(code_sink)
Parameters:code_sink – a CodeSink instance that will receive the generated code
class pybindgen.cppattribute.CppStaticAttributeGetter(value_type, class_, attribute_name)

Bases: pybindgen.cppattribute.PyGetter

A getter for a C++ class static attribute.

Parameters:
  • value_type – a ReturnValue object handling the value type;
  • c_value_expression – C value expression
generate(code_sink)
Parameters:code_sink – a CodeSink instance that will receive the generated code
generate_call()

virtual method implementation; do not call

class pybindgen.cppattribute.CppStaticAttributeSetter(value_type, class_, attribute_name)

Bases: pybindgen.cppattribute.PySetter

A setter for a C++ class static attribute.

Parameters:
  • value_type – a ReturnValue object handling the value type;
  • class – the class (CppClass object)
  • attribute_name – name of attribute
generate(code_sink)
Parameters:code_sink – a CodeSink instance that will receive the generated code
class pybindgen.cppattribute.PyGetSetDef(cname)

Bases: object

Class that generates a PyGetSet table

Parameters:cname – C name of the getset table
add_attribute(name, getter, setter)

Add a new attribute :param name: attribute name :param getter: a PyGetter object, or None :param setter: a PySetter object, or None

empty()
generate(code_sink)

Generate the getset table, return the table C name or ‘0’ if the table is empty

class pybindgen.cppattribute.PyGetter(return_value, parameters, parse_error_return, error_return, force_parse=None, no_c_retval=False, unblock_threads=False)

Bases: pybindgen.typehandlers.base.ForwardWrapperBase

generates a getter, for use in a PyGetSetDef table

Base constructor

Parameters:
  • return_value – type handler for the return value
  • parameters – a list of type handlers for the parameters
  • parse_error_return – statement to return an error during parameter parsing
  • error_return – statement to return an error after parameter parsing
  • force_parse – force generation of code to parse parameters even if there are none
  • no_c_retval – force the wrapper to not have a C return value
  • unblock_threads – generate code to unblock python threads during the C function call
generate(code_sink)

Generate the code of the getter to the given code sink

generate_call()

(not actually called)

class pybindgen.cppattribute.PyMetaclass(name, parent_metaclass_expr, getsets=None)

Bases: object

Class that generates a Python metaclass

Parameters:
  • name – name of the metaclass (should normally end with Meta)
  • parent_metaclass_expr – C expression that should give a pointer to the parent metaclass (should have a C type of PyTypeObject*)
  • getsets – name of a PyGetSetDef C array variable, or None
generate(code_sink, module)

Generate the metaclass to code_sink and register it in the module.

class pybindgen.cppattribute.PySetter(return_value, parameters, error_return=None)

Bases: pybindgen.typehandlers.base.ReverseWrapperBase

generates a setter, for use in a PyGetSetDef table

Base constructor

Parameters:
  • return_value – type handler for the return value
  • parameters – a list of type handlers for the parameters
NO_GIL_LOCKING = True
generate(code_sink)

Generate the code of the setter to the given code sink

generate_python_call()

(not actually called)

Previous topic

cppmethod: wrap class methods and constructors

Next topic

cppexception: translate C++ exceptions into Python

This Page