gen_rfl is a C++ reflection code generation tool that automatically generates reflection functions for C++ classes when executed. With these reflection functions, you can quickly get or set the member variables of structures.
gen_rfl is designed for extreme performance, while also ensuring safety, ease of use, and non-intrusive integration, providing developers with a convenient and reliable reflection capability.
The reflection code generated by gen_rfl operates at O(1) time complexity.
- All metadata generated and initialized at compile time. Compile-time Reflection with Zero Runtime Overhead。
static meta<base> g_base_meta[] = {
{
.m_variant = "a",
.m_type = "signed char",
.m_flags = 0x80001,
.m_field = e__base__a,
.m_member = [](const base *c) -> const void * {
return std::addressof(static_cast<const base*>(c)->a);
},
},
};- Stores all metadata in contiguous memory with a cache-friendly memory layout.
static meta<base> g_base_meta[] = {
{ /* a */ },
{ /* b */ },
{ /* c */ },
...
};- Direct jump, no function call overhead, o(1) time complexity for field lookup.
constexpr void *__meta_label[] = { &&label_0_0, &&label_0_1, ... };
auto value = tag();
auto index = value % count;
goto *__meta_label[index];
label_0_0:
return ...;- Runtime type checking, prevents type mismatch access
void *get_value(const base *cls, const std::string &_tag, const char *expected_type)
{
return (strcmp(expected_type, _meta.m_type) == 0) ? ... : nullptr;
}- Support for Complex Data Structures, native support for STL containers and custom types
{
.m_variant = "n",
.m_type = "std::map<int, int>",
.m_flags = 0x80001,
.m_field = e__base__n,
.m_member = [](const base *c) -> const void * {
return std::addressof(static_cast<const base*>(c)->n);
},
}- High-performance serialization/deserialization
- Game engine property systems
- Database ORM mapping
- Network protocol processing
- Configuration systems
| lib | version |
|---|---|
| libctemplate-dev | 2.4-1 |
| libctemplate3 | 2.4-1 |
| llvm-15-dev | 1:15.0.7 |
| llvm-15 | 1:15.0.7 |
execute ./build.sh