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
137 template <std::meta::info Alias>
138 static auto weld_type(module_type& m, const char* name = nullptr) {
139 using T = [:Alias:];
140 static_assert(!std::is_enum_v<T>,
141 "welder: weld_type<Alias>: enums are never alias-welded — "
142 "call weld_type<E>() with the enum type itself");
143 return Carriage::template bind_type<B, T, Style, Alias>(m, name);
144 }
145
169 template <std::meta::info Fn>
170 static auto weld_function(module_type& m, const char* name = nullptr) {
171 return Carriage::template bind_function<B, Fn, Style>(m, name);
172 }
173
191 template <std::meta::info Var>
192 static auto weld_variable(module_type& m, const char* name = nullptr) {
193 return Carriage::template bind_variable<B, Var, Style>(m, name);
194 }
195
206 template <std::meta::info Ns>
208 Carriage::template bind_namespace<B, Ns, Style>(m);
209 return m;
210 }
211
220 template <std::meta::info Ns>
222 const char* name = nullptr) {
223 return Carriage::template bind_namespace_as_submodule<B, Ns, Style>(m, name);
224 }
225
243 template <std::meta::info Ns, class Pre = decltype(noop),
244 class Post = decltype(noop)>
246 Post post = noop) {
247 Carriage::template build_module<B, Ns, Style>(m, pre, post);
248 return m;
249 }
250};
251
252} // 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:221
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:245
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:192
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:207
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:170
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