MCPcopy Create free account
hub / github.com/pybind/pybind11 / generate_dummy_code_boost

Function generate_dummy_code_boost

docs/benchmark.py:42–70  ·  view source on GitHub ↗
(nclasses=10)

Source from the content-addressed store, hash-verified

40
41
42def generate_dummy_code_boost(nclasses=10):
43 decl = ""
44 bindings = ""
45
46 for cl in range(nclasses):
47 decl += f"class cl{cl:03};\n"
48 decl += "\n"
49
50 for cl in range(nclasses):
51 decl += f"class cl{cl:03} {{\n"
52 decl += "public:\n"
53 bindings += f' py::class_<cl{cl:03}>("cl{cl:03}")\n'
54 for fn in range(nfns):
55 ret = random.randint(0, nclasses - 1)
56 params = [random.randint(0, nclasses - 1) for i in range(nargs)]
57 decl += f" cl{ret:03} *fn_{fn:03}("
58 decl += ", ".join(f"cl{p:03} *" for p in params)
59 decl += ");\n"
60 bindings += f' .def("fn_{fn:03}", &cl{cl:03}::fn_{fn:03}, py::return_value_policy<py::manage_new_object>())\n'
61 decl += "};\n\n"
62 bindings += " ;\n"
63
64 result = "#include <boost/python.hpp>\n\n"
65 result += "namespace py = boost::python;\n\n"
66 result += decl + "\n"
67 result += "BOOST_PYTHON_MODULE(example) {\n"
68 result += bindings
69 result += "}"
70 return result
71
72
73for codegen in [generate_dummy_code_pybind11, generate_dummy_code_boost]:

Callers

nothing calls this directly

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected