Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
gtwrap.pybind_wrapper.PybindWrapper Class Reference

Public Member Functions

def __init__ (self, module_name, top_module_namespaces='', use_boost_serialization=False, ignore_classes=(), module_template="")
 
def wrap (self, sources, main_module_name)
 
def wrap_ctors (self, my_class)
 
def wrap_dunder_methods (self, methods, cpp_class, prefix='\n'+' ' *8, suffix='')
 
def wrap_enum (self, enum, class_name='', module=None, prefix=' ' *4)
 
def wrap_enums (self, enums, instantiated_class, prefix=' ' *4)
 
def wrap_file (self, content, module_name=None, submodules=None)
 
def wrap_functions (self, functions, namespace, prefix='\n'+' ' *8, suffix='')
 
def wrap_instantiated_class (self, instantiator.InstantiatedClass instantiated_class)
 
def wrap_instantiated_declaration (self, instantiator.InstantiatedDeclaration instantiated_decl)
 
def wrap_methods (self, methods, cpp_class, prefix='\n'+' ' *8, suffix='')
 
def wrap_namespace (self, namespace)
 
def wrap_operators (self, operators,cpp_class, prefix='\n'+' ' *8)
 
def wrap_properties (self, properties, cpp_class, prefix='\n'+' ' *8)
 
def wrap_stl_class (self, stl_class)
 
def wrap_submodule (self, source)
 
def wrap_variable (self, namespace, module_var, variable, prefix='\n'+' ' *8)
 

Public Attributes

 dunder_methods
 
 ignore_classes
 
 method_indent
 
 module_name
 
 module_template
 
 python_keywords
 
 top_module_namespaces
 
 use_boost_serialization
 

Private Member Functions

def _add_namespaces (self, name, namespaces)
 
def _gen_module_var (self, namespaces)
 
def _method_args_signature (self, args)
 
def _partial_match (self, namespaces1, namespaces2)
 
def _py_args_names (self, args)
 
def _wrap_dunder (self, method, cpp_class, prefix, suffix, method_suffix="")
 
def _wrap_method (self, method, cpp_class, prefix, suffix, method_suffix="")
 
def _wrap_print (self, str ret, parser.Method method, str cpp_class, List[str] args_names, str args_signature_with_names, str py_args_names, str prefix, str suffix)
 
def _wrap_serialization (self, cpp_class)
 

Private Attributes

 _ipython_special_methods
 
 _serializing_classes
 

Detailed Description

Class to generate binding code for Pybind11 specifically.

Definition at line 23 of file pybind_wrapper.py.

Constructor & Destructor Documentation

◆ __init__()

def gtwrap.pybind_wrapper.PybindWrapper.__init__ (   self,
  module_name,
  top_module_namespaces = '',
  use_boost_serialization = False,
  ignore_classes = (),
  module_template = "" 
)

Definition at line 28 of file pybind_wrapper.py.

Member Function Documentation

◆ _add_namespaces()

def gtwrap.pybind_wrapper.PybindWrapper._add_namespaces (   self,
  name,
  namespaces 
)
private

Definition at line 585 of file pybind_wrapper.py.

◆ _gen_module_var()

def gtwrap.pybind_wrapper.PybindWrapper._gen_module_var (   self,
  namespaces 
)
private
Get the Pybind11 module name from the namespaces.

Definition at line 579 of file pybind_wrapper.py.

◆ _method_args_signature()

def gtwrap.pybind_wrapper.PybindWrapper._method_args_signature (   self,
  args 
)
private
Generate the argument types and names as per the method signature.

Definition at line 75 of file pybind_wrapper.py.

◆ _partial_match()

def gtwrap.pybind_wrapper.PybindWrapper._partial_match (   self,
  namespaces1,
  namespaces2 
)
private

Definition at line 573 of file pybind_wrapper.py.

◆ _py_args_names()

def gtwrap.pybind_wrapper.PybindWrapper._py_args_names (   self,
  args 
)
private
Set the argument names in Pybind11 format.

Definition at line 58 of file pybind_wrapper.py.

◆ _wrap_dunder()

def gtwrap.pybind_wrapper.PybindWrapper._wrap_dunder (   self,
  method,
  cpp_class,
  prefix,
  suffix,
  method_suffix = "" 
)
private
Wrap a Python double-underscore (dunder) method.

E.g. __len__() gets wrapped as `.def("__len__", [](gtsam::KeySet* self) {return self->size();})`

Supported methods are:
- __contains__(T x)
- __len__()
- __iter__()

Definition at line 158 of file pybind_wrapper.py.

◆ _wrap_method()

def gtwrap.pybind_wrapper.PybindWrapper._wrap_method (   self,
  method,
  cpp_class,
  prefix,
  suffix,
  method_suffix = "" 
)
private
Wrap the `method` for the class specified by `cpp_class`.

Args:
    method: The method to wrap.
    cpp_class: The C++ name of the class to which the method belongs.
    prefix: Prefix to add to the wrapped method when writing to the cpp file.
    suffix: Suffix to add to the wrapped method when writing to the cpp file.
    method_suffix: A string to append to the wrapped method name.

Definition at line 203 of file pybind_wrapper.py.

◆ _wrap_print()

def gtwrap.pybind_wrapper.PybindWrapper._wrap_print (   self,
str  ret,
parser.Method  method,
str  cpp_class,
List[str args_names,
str  args_signature_with_names,
str  py_args_names,
str  prefix,
str  suffix 
)
private
Update the print method to print to the output stream and append a __repr__ method.

Args:
    ret (str): The result of the parser.
    method (parser.Method): The method to be wrapped.
    cpp_class (str): The C++ name of the class to which the method belongs.
    args_names (List[str]): List of argument variable names passed to the method.
    args_signature_with_names (str): C++ arguments containing their names and type signatures.
    py_args_names (str): The pybind11 formatted version of the argument list.
    prefix (str): Prefix to add to the wrapped method when writing to the cpp file.
    suffix (str): Suffix to add to the wrapped method when writing to the cpp file.

Returns:
    str: The wrapped print method.

Definition at line 117 of file pybind_wrapper.py.

◆ _wrap_serialization()

def gtwrap.pybind_wrapper.PybindWrapper._wrap_serialization (   self,
  cpp_class 
)
private
Helper method to add serialize, deserialize and pickle methods to the wrapped class.

Definition at line 97 of file pybind_wrapper.py.

◆ wrap()

def gtwrap.pybind_wrapper.PybindWrapper.wrap (   self,
  sources,
  main_module_name 
)
Wrap all the main interface file.

Args:
    sources: List of all interface files.
The first file should be the main module.
    main_module_name: The name for the main module.

Definition at line 761 of file pybind_wrapper.py.

◆ wrap_ctors()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_ctors (   self,
  my_class 
)
Wrap the constructors.

Definition at line 86 of file pybind_wrapper.py.

◆ wrap_dunder_methods()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_dunder_methods (   self,
  methods,
  cpp_class,
  prefix = '\n' + ' ' * 8,
  suffix = '' 
)

Definition at line 285 of file pybind_wrapper.py.

◆ wrap_enum()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_enum (   self,
  enum,
  class_name = '',
  module = None,
  prefix = ' ' * 4 
)
Wrap an enum.

Args:
    enum: The parsed enum to wrap.
    class_name: The class under which the enum is defined.
    prefix: The amount of indentation.

Definition at line 385 of file pybind_wrapper.py.

◆ wrap_enums()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_enums (   self,
  enums,
  instantiated_class,
  prefix = ' ' * 4 
)
Wrap multiple enums defined in a class.

Definition at line 410 of file pybind_wrapper.py.

◆ wrap_file()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_file (   self,
  content,
  module_name = None,
  submodules = None 
)
Wrap the code in the interface file.

Args:
    content: The contents of the interface file.
    module_name: The name of the module.
    submodules: List of other interface file names that should be linked to.

Definition at line 676 of file pybind_wrapper.py.

◆ wrap_functions()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_functions (   self,
  functions,
  namespace,
  prefix = '\n' + ' ' * 8,
  suffix = '' 
)
Wrap all the global functions.

Definition at line 520 of file pybind_wrapper.py.

◆ wrap_instantiated_class()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_instantiated_class (   self,
instantiator.InstantiatedClass  instantiated_class 
)
Wrap the class.

Definition at line 421 of file pybind_wrapper.py.

◆ wrap_instantiated_declaration()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_instantiated_declaration (   self,
instantiator.InstantiatedDeclaration  instantiated_decl 
)
Wrap the forward declaration.

Definition at line 478 of file pybind_wrapper.py.

◆ wrap_methods()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_methods (   self,
  methods,
  cpp_class,
  prefix = '\n' + ' ' * 8,
  suffix = '' 
)
Wrap all the methods in the `cpp_class`.

Definition at line 299 of file pybind_wrapper.py.

◆ wrap_namespace()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_namespace (   self,
  namespace 
)
Wrap the complete `namespace`.

Definition at line 593 of file pybind_wrapper.py.

◆ wrap_operators()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_operators (   self,
  operators,
  cpp_class,
  prefix = '\n' + ' ' * 8 
)
Wrap all the overloaded operators in the `cpp_class`.

Definition at line 367 of file pybind_wrapper.py.

◆ wrap_properties()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_properties (   self,
  properties,
  cpp_class,
  prefix = '\n' + ' ' * 8 
)
Wrap all the properties in the `cpp_class`.

Definition at line 353 of file pybind_wrapper.py.

◆ wrap_stl_class()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_stl_class (   self,
  stl_class 
)
Wrap STL containers.

Definition at line 493 of file pybind_wrapper.py.

◆ wrap_submodule()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_submodule (   self,
  source 
)
Wrap a list of submodule files, i.e. a set of interface files which are
in support of a larger wrapping project.

E.g. This is used in GTSAM where we have a main gtsam.i, but various smaller .i files
which are the submodules.
The benefit of this scheme is that it reduces compute and memory usage during compilation.

Args:
    source: Interface file which forms the submodule.

Definition at line 736 of file pybind_wrapper.py.

◆ wrap_variable()

def gtwrap.pybind_wrapper.PybindWrapper.wrap_variable (   self,
  namespace,
  module_var,
  variable,
  prefix = '\n' + ' ' * 8 
)
Wrap a variable that's not part of a class (i.e. global)

Definition at line 332 of file pybind_wrapper.py.

Member Data Documentation

◆ _ipython_special_methods

gtwrap.pybind_wrapper.PybindWrapper._ipython_special_methods
private

Definition at line 49 of file pybind_wrapper.py.

◆ _serializing_classes

gtwrap.pybind_wrapper.PybindWrapper._serializing_classes
private

Definition at line 33 of file pybind_wrapper.py.

◆ dunder_methods

gtwrap.pybind_wrapper.PybindWrapper.dunder_methods

Definition at line 43 of file pybind_wrapper.py.

◆ ignore_classes

gtwrap.pybind_wrapper.PybindWrapper.ignore_classes

Definition at line 32 of file pybind_wrapper.py.

◆ method_indent

gtwrap.pybind_wrapper.PybindWrapper.method_indent

Definition at line 46 of file pybind_wrapper.py.

◆ module_name

gtwrap.pybind_wrapper.PybindWrapper.module_name

Definition at line 29 of file pybind_wrapper.py.

◆ module_template

gtwrap.pybind_wrapper.PybindWrapper.module_template

Definition at line 34 of file pybind_wrapper.py.

◆ python_keywords

gtwrap.pybind_wrapper.PybindWrapper.python_keywords

Definition at line 35 of file pybind_wrapper.py.

◆ top_module_namespaces

gtwrap.pybind_wrapper.PybindWrapper.top_module_namespaces

Definition at line 30 of file pybind_wrapper.py.

◆ use_boost_serialization

gtwrap.pybind_wrapper.PybindWrapper.use_boost_serialization

Definition at line 31 of file pybind_wrapper.py.


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


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:53:09