welder 0.1.0
Bindings for annotated C++ types, from C++26 reflection
Loading...
Searching...
No Matches
welder.hpp
Go to the documentation of this file.
1#pragma once
2#include <meta>
3#include <type_traits>
4
5#include <welder/carriage.hpp> // the traversal driver + stitch/tack carriage aliases
6#include <welder/concepts.hpp> // the welder::rod contract
7#include <welder/naming.hpp> // naming::none (the default name style)
8
31
32namespace welder::inline v0 {
33
84template <rod B, class Style = naming::none, class Carriage = carriage>
85struct welder {
87 using rod_type = B;
89 using name_style = Style;
91 using carriage_type = Carriage;
93 using module_type = typename B::module_type;
94
96 static constexpr auto noop{[](module_type&) {}};
97
110 template <class T>
111 static auto weld_type(module_type& m, const char* name = nullptr) {
112 if constexpr (std::is_enum_v<T>)
113 return Carriage::template bind_enum<B, T, Style>(m, name);
114 else
115 return Carriage::template bind_type<B, T, Style>(m, name);
116 }
117
141 template <std::meta::info Fn>
142 static auto weld_function(module_type& m, const char* name = nullptr) {
143 return Carriage::template bind_function<B, Fn, Style>(m, name);
144 }
145
163 template <std::meta::info Var>
164 static auto weld_variable(module_type& m, const char* name = nullptr) {
165 return Carriage::template bind_variable<B, Var, Style>(m, name);
166 }
167
178 template <std::meta::info Ns>
180 Carriage::template bind_namespace<B, Ns, Style>(m);
181 return m;
182 }
183
192 template <std::meta::info Ns>
194 const char* name = nullptr) {
195 return Carriage::template bind_namespace_as_submodule<B, Ns, Style>(m, name);
196 }
197
215 template <std::meta::info Ns, class Pre = decltype(noop),
216 class Post = decltype(noop)>
218 Post post = noop) {
219 Carriage::template build_module<B, Ns, Style>(m, pre, post);
220 return m;
221 }
222};
223
224} // namespace welder
The carriage: welder's reflection-driven traversal driver, kept separate from the welder::welder<> en...
The core interface concepts welder's static polymorphism rests on, gathered in one catalogue: the cus...
Language-agnostic name styling: reshape a C++ identifier into a target language's naming convention,...
static module_type weld_namespace_as_submodule(module_type &m, const char *name=nullptr)
Define a submodule of m (via the backend) and weld_namespace() Ns into it.
Definition welder.hpp:193
typename B::module_type module_type
The rod's module handle (py::module_, sol::table, …).
Definition welder.hpp:93
static module_type & weld_module(module_type &m, Pre pre=noop, Post post=noop)
Build a whole module out of top-level namespace Ns: run pre, weld the namespace into m (adopting a na...
Definition welder.hpp:217
static auto weld_variable(module_type &m, const char *name=nullptr)
Reflect over global/namespace variable Var and register it on module m.
Definition welder.hpp:164
static constexpr auto noop
A do-nothing module hook; the default for weld_module()'s pre/post.
Definition welder.hpp:96
Carriage carriage_type
The traversal driver (carriage) this instantiation drives through.
Definition welder.hpp:91
static auto weld_type(module_type &m, const char *name=nullptr)
Reflect over T and register it on module m.
Definition welder.hpp:111
static module_type & weld_namespace(module_type &m)
Reflect over namespace Ns and expose its members on module m.
Definition welder.hpp:179
static auto weld_function(module_type &m, const char *name=nullptr)
Reflect over free function Fn and register it on module m.
Definition welder.hpp:142
B rod_type
The rod this instantiation emits through.
Definition welder.hpp:87
Style name_style
The name style this instantiation renames through.
Definition welder.hpp:89