def _generate_callback_wrapper( self, m: GeneratorMethod, ): # calling_back_code ret_type = m.ret_type args = m.args arguments_signature = ",".join( [self._to_cpp_variable(i) for i in args]) arg_list = ",".join( ["this", f'"{m.alias}"', *[f"{i.name}" for i in args]]) if m.has_overload: cast_expression = f"static_cast<{m.type}>(&{m.full_name})" else: cast_expression = f"&{m.full_name}" function_code = TextHolder() function_code += ( f"{ret_type} {m.name}({arguments_signature}) override\n") function_code += "{\n" + Indent() calling_method = "call" if m.calling_type == CallingType.Async: calling_method = "async" elif m.calling_type == CallingType.Sync: calling_method = "sync" function_code += ( f"return c2py::callback_wrapper<{cast_expression}>::{calling_method}(" + Indent()) function_code += f"{arg_list}" - IndentLater() function_code += f");" function_code += "}\n" - Indent() return function_code
def _generate_calling_wrapper(m: GeneratorFunction, has_overload, append=''): code = TextHolder() if m.wrappers: has_this = False if isinstance(m, GeneratorMethod) and not m.is_static: has_this = True if len(m.wrappers) == 1: wi = m.wrappers[0] code += f'c2py::{wi.wrapper.name} < ' + Indent() code += f'c2py::function_constant<{m.address}>,' code += f'std::integral_constant<int, {wi.index}{" + 1/*self*/" if has_this else ""}>' code += f'>::value{append}' - Indent() else: # >= 2 code += f'c2py::apply_function_transform<' + Indent() code += f'c2py::function_constant<{m.address}>,' code += 'brigand::list<' + Indent() lines = [ f'c2py::indexed_transform_holder<' f'c2py::{wi.wrapper.name}, {wi.index}{" + 1/*self*/" if has_this else ""}>' for wi in m.wrappers ] code.append_lines(lines, ',') code += '>' - Indent() code += f'>::value{append}' - Indent() else: if has_overload: code += f'static_cast<{m.type}>(' + Indent() code += f"""&{m.full_name}""" code += f"""),""" - IndentLater() else: code += f"""&{m.full_name},""" return code