def _process_caster(self, ns: GeneratorNamespace, cpp_scope_variable: str,
                        body: TextHolder, pfm: FunctionManager):
        if self.options.caster_class_name:
            function_name = slugify(f"generate_caster_{ns.full_name}")
            function_body, fm = self._generate_caster_body(ns)
            body += f'{function_name}({cpp_scope_variable});'

            pfm.add(function_name, "pybind11::object &", function_body)
            pfm.extend(fm)
    def _process_classes(self, ns: GeneratorNamespace, cpp_scope_variable: str,
                         body: TextHolder, pfm: FunctionManager):
        if ns.classes:
            for c in ns.classes.values():
                function_name = slugify(f"generate_class_{c.full_name}")
                function_body, fm = self._generate_class_body(c)
                body += f'{function_name}({cpp_scope_variable});'
                # todo: generate alias ...

                pfm.add(function_name, "pybind11::object &", function_body)
                pfm.extend(fm)
Exemple #3
0
    def _process_sub_namespace(self, ns: GeneratorNamespace, cpp_scope_variable: str,
                               body: TextHolder, pfm: FunctionManager):
        for n in ns.namespaces.values():
            assert n.name, "sub Namespace has no name, someting wrong in Parser or preprocessor"
            function_name = slugify(f"generate_sub_namespace_{n.full_name}")
            function_body, fm = self._generate_namespace_body(n)
            body += '{' + Indent()
            body += f'auto m = {cpp_scope_variable}.def_submodule("{n.name}");'
            body += f'{function_name}(m);'
            body += '}' - Indent()
            # todo: generate alias (namespace alias)

            pfm.add(function_name, "pybind11::module &", function_body)
            pfm.extend(fm)
Exemple #4
0
    def _output_module(self):
        function_name = slugify(f'generate_{self.module_name}')
        function_body, fm = self._generate_namespace_body(self.options.g)

        module_body = TextHolder()
        module_body += 1
        module_body += f'{function_name}(m);'
        self._save_template(
            "module.cpp",
            "module.cpp",
            module_body=module_body,
            module_tag=self.module_tag,
        )
        self.function_manager.add(function_name, "pybind11::module &", function_body)
        self.function_manager.extend(fm)