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

welder nanobind rod (header-only). More...

#include <array>
#include <cstddef>
#include <cstdint>
#include <meta>
#include <string>
#include <type_traits>
#include <utility>
#include <welder/welder.hpp>
#include <welder/rods/python/doc_style.hpp>
#include <welder/rods/python/operators.hpp>
#include <welder/rods/python/trampoline.hpp>
#include <welder/bind_traits.hpp>
#include <welder/doc.hpp>
#include <nanobind/nanobind.h>
#include <nanobind/ndarray.h>
#include <nanobind/stl/bind_vector.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/bind_map.h>
#include <welder/containers.hpp>
#include <welder/rods/python/array_interface.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::nanobind::rod< DocStyle >
 The nanobind rod: a stateless policy type satisfying welder::rod. More...

Namespaces

namespace  welder
namespace  welder::rods
namespace  welder::rods::nanobind

Macros

#define WELDER_OPAQUE(...)
 Declare a container type opaque so nanobind binds it by reference (via weld-an-alias + bind_vector/bind_map) instead of copy-converting it through <nanobind/stl/…>.

Detailed Description

welder nanobind rod (header-only).

This is a thin rod: it implements welder's rod contract (<welder/welder.hpp>) for nanobind and hands the traversal/resolution off to welder's generic driver. All the language-agnostic work — deciding which members bind, gating bindability, folding docstrings, walking bases and namespaces — lives in the core; only the nanobind emission primitives are here. It is a near-mirror of the pybind11 backend (same class-handle model), differing only where nanobind's API does: def_rw/def_ro instead of def_readwrite/def_readonly, a placement-__init__ factory, module docstrings set through __doc__, and the is_base_caster bindability probe.

Requires the welder vocabulary first (#include <welder/vocabulary.hpp>). This header exposes exactly one thing: the rod template welder::rods::nanobind::rod<DocStyle = google_style>, to plug into welder::welder (rod<> for the default Google docstring style; rod<numpy_style> / rod<sphinx_style> for the other dialects):

#include <nanobind/nanobind.h>
NB_MODULE(mymod, m) {
}
welder nanobind rod (header-only).
welder's binding entry point, parameterized on a rod.
Definition welder.hpp:85

(For the WELDER_MODULE entry-point macro, include this directory's module.hpp instead.)

Note
nanobind supports only single inheritance at the binding level (one C++ base per nb::class_). welder's driver may hand this backend more than one welded base (e.g. a multiple-inheritance diamond); those cases bind under pybind11 but not nanobind, and trip nanobind's own single-base static assertion.

Definition in file rod.hpp.

Macro Definition Documentation

◆ WELDER_OPAQUE

#define WELDER_OPAQUE ( ...)
Value:
NB_MAKE_OPAQUE(__VA_ARGS__)

Declare a container type opaque so nanobind binds it by reference (via weld-an-alias + bind_vector/bind_map) instead of copy-converting it through <nanobind/stl/…>.

A thin, backend-neutral spelling of NB_MAKE_OPAQUE; place it at namespace scope, before the module. (nanobind also hard-errors at compile time if a container is bind_vector-bound while its stl caster is included without this — the error names NB_MAKE_OPAQUE as the fix.) In a translation unit with more than one Python rod, use the framework-native macros directly (this resolves to whichever rod header was included first).

See also
welder/containers.hpp

Definition at line 68 of file rod.hpp.