welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
rod.hpp File Reference

welder trampoline-generator rod (header-only, text-emitting). More...

#include <cstddef>
#include <meta>
#include <ostream>
#include <string>
#include <utility>
#include <welder/welder.hpp>
#include <welder/rods/python/trampolines/document.hpp>
Include dependency graph for rod.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  welder::rods::trampolines::rod
 The trampoline-generator rod: a stateless welder::rod that, instead of registering a live module, appends a compilable trampoline struct (plus its trampoline_for registration) for every welded virtual type it visits. More...
struct  welder::rods::trampolines::rod::module_handle
 A copyable handle onto the growing document that the driver threads through every emission primitive (the rod's module_type). More...
struct  welder::rods::trampolines::rod::class_handle
 The class handle the driver threads to the per-member hooks. More...
struct  welder::rods::trampolines::rod::enum_handle
 The enum handle. More...
struct  welder::rods::trampolines::rod::session
 No deferred module state. More...

Namespaces

namespace  welder
namespace  welder::rods
namespace  welder::rods::trampolines

Detailed Description

welder trampoline-generator rod (header-only, text-emitting).

A Python subclass can only override a welded type's virtual methods when the type is bound with a trampoline — a hand-written C++ subclass that captures each virtual call and forwards it to Python (see the guide's inheritance chapter and <welder/rods/python/trampoline.hpp>). welder cannot synthesize that subclass as a live class (P2996 has no member-declaration injection), but it can emit one as source text** and let the consuming translation unit compile it. This rod does exactly that: it reflects a welded namespace and writes a .hpp of ready-to-compile trampolines — the Python analogue of the LuaCATS stub rod, and it plugs the same generic driver (<welder/welder.hpp>) so type discovery, weld/policy resolution and inheritance handling are reused verbatim.

The generated trampolines are backend-neutral — they use welder's neutral WELDER_PY_TRAMPOLINE / WELDER_PY_OVERRIDE macros, so one generated header compiles under either Python rod (pybind11 or nanobind); the consuming TU includes the active backend's trampoline.hpp first. Each override splices the base virtual's own reflected return/parameter types, so signatures match by construction (see <welder/rods/python/trampolines/document.hpp> for the rendering core and its one limitation, C-variadic virtuals).

Requires the welder vocabulary first (#include <welder/vocabulary.hpp>). Drive it by hand:

welder trampoline-generator rod (header-only, text-emitting).
static void generate(std::ostream &os)
Emit the trampoline header for the welded types in namespace Ns to os.
Definition rod.hpp:178

or through the generator-main() macro (module.hpp):

WELDER_TRAMPOLINES_MAIN(mymod) // main(): print the trampoline header for ^^mymod
Full-automation entry point for the trampoline-generator rod: the WELDER_TRAMPOLINES_MAIN generator-m...
#define WELDER_TRAMPOLINES_MAIN(ns)
Define a main() that emits the trampoline header for namespace ns.
Definition module.hpp:23

Definition in file rod.hpp.