• Stars
    star
    335
  • Rank 121,734 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created almost 4 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ubpa Dynamic Reflection

 __    __   _______  .______       _______  _______  __      
|  |  |  | |       \ |   _  \     |   ____||   ____||  |     
|  |  |  | |  .--.  ||  |_)  |    |  |__   |  |__   |  |     
|  |  |  | |  |  |  ||      /     |   __|  |   __|  |  |     
|  `--'  | |  '--'  ||  |\  \----.|  |____ |  |     |  `----.
 \______/  |_______/ | _| `._____||_______||__|     |_______|
                                                             

repo-size tag license

⭐ Star us on GitHub β€” it helps!

UDRefl

Ubpa Dynamic Reflection

Extremely fast and powerful C++20 dynamic reflection library

Documentaion ->

How to Use

the example code is here, other examples is here

Suppose you need to reflect struct Vec

struct Vec {
  float x;
  float y;
  float norm() const {
    return std::sqrt(x * x + y * y);
  }
};

Manual registration

Mngr.RegisterType<Vec>();
Mngr.AddField<&Vec::x>("x");
Mngr.AddField<&Vec::y>("y");
Mngr.AddMethod<&Vec::norm>("norm");

Iterate over members

for (auto&& [name, info] : FieldRange_of<Vec>)
  std::cout << name.GetView() << std::endl;

for (auto&& [name, info] : MethodRange_of<Vec>)
  std::cout << name.GetView() << std::endl;

Constructing types

SharedObject v = Mngr.MakeShared(Type_of<Vec>);
std::cout << v.GetType().GetName() << std::endl; // prints "Vec"

Set/get variables

v.Var("x") = 3;
v.Var("y") = 4;
std::cout << "x: " << v.Var("x") << std::endl;

Invoke Methods

std::cout << "norm: " << v.Invoke("norm") << std::endl;

Iterate over variables

for (auto&& [name, var] : v.GetVars())
  std::cout << name.GetView() << ": " << var << std::endl;

other example

Features

  • global fields, methods or enums
  • classes with single-, multiple- and virtual-inheritance
  • constructors (arbitrary argument count) and destructors
  • methods (virtual, abstract, overloaded, arbitrary argument count) : you can pass arguments by a buffer (on stack or heap)
  • ability to invoke methods of classes from any arbitrary class level
  • argument type auto convertion when invoking method
  • no header pollution: the reflection information is created in the cpp file to minimize compile time when modifying the data
  • working with custom types without the need of having the declaration of the type available at compile time (useful for plugins)
  • possibility to add additional attribute to all reflection objects
  • reference
  • pointer, array
  • standard container, iterator
  • meta function
    • operations: operator +, operator-, ...
    • container: begin, end, empty, size, ...
  • bootstrap
  • no macro usage
  • no rtti required
  • no exceptions (this feature come with cost and is also regularly disabled on consoles)
  • no external compiler or tool needed, only standard ISO C++20

Compiler compatibility

  • Clang/LLVM >= 10.0
  • GCC >= 10.0
  • MSVC >= 1926

Tested platforms:

  • Windows 10: VS2019 16.8.5

  • Ubuntu 20: GCC 10.2, Clang 11.0

  • MacOS 11.0 : GCC 10.2

    AppleClang 12 and Clang 11 is not supported

Licensing

You can copy and paste the license summary from below.

MIT License

Copyright (c) 2020 Ubpa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

More Repositories

1

RenderLab

App of RTR, PTR and Editor
C++
747
star
2

USRefl

Header-only, tiny (99 lines) and powerful C++20 static reflection library.
C++
586
star
3

Utopia

Utopia Game Engine ζ— ε’ƒζΈΈζˆεΌ•ζ“Ž
C++
477
star
4

USTC_CG

00106501: Computer Graphics (Spring-Summer 2020)
C++
408
star
5

ToyRTX

CPU & GPU RTX based on OpenGL
C++
380
star
6

UECS

Ubpa Entity-Component-System (U ECS) in Unity3D-style
C++
361
star
7

UGM

Ubpa Graphics Mathematics
C++
313
star
8

GAMES102

GAMES 102
C++
267
star
9

CMU_15_462

notes and assignments of CG (CMU 15-462/662)
C++
86
star
10

UHEMesh

an elegant, high-performance and user-friendly halfedge data structure
C++
77
star
11

UFG

Ubpa Frame Graph
C++
42
star
12

UGraphviz

Ubpa Graphviz C++ wrapper
C++
37
star
13

ULuaPP

Ubpa Lua++ (Lua & C++)
C++
31
star
14

UDP

Ubpa Design Pattern
C++
27
star
15

USmallFlat

Ubpa small flat containers based on C++20
C++
27
star
16

ExponentialHeightFog

[ Unreal to Unity ] Exponential Height Fog
HLSL
24
star
17

UCMake

Ubpa CMake
CMake
22
star
18

UTemplate

C++
22
star
19

CG_LGLiu

exercises of CG class teached by Prof LiGang Liu in 2018
C++
19
star
20

LearnOpenGL

OpenGL Exercise
C++
18
star
21

UDXRenderer

Ubpa DirectX 12 Renderer
C++
17
star
22

UDLua

Ubpa Lua base on UDRefl
C++
16
star
23

RayTracingInOneWeekend

rewrite Ray Tracing in a Weekend
C++
15
star
24

Project-GAMES101

Project-GAMES101
15
star
25

UDX12

Ubpa DirectX 12 C++ Wrapper
C++
10
star
26

MasterCourses

Master Courses
C++
4
star
27

best-cpp-reflection

best cpp reflection
3
star
28

DoubleConeRain

Double Cone Rain
C#
3
star
29

UScene

Ubpa Scene
C++
3
star
30

LearnVulkan

Learn Vulkan
2
star
31

ULua

Ubpa Lua
CMake
2
star
32

LearnRust

Rust
2
star
33

UData

Ubpa Data
C
2
star
34

GAMES102_Data

GAMES_102_Data
2
star
35

RenderLab_bk_20200303

C++
2
star
36

UANTLR

Ubpa ANTLR4
ANTLR
1
star
37

USTL

Ubpa stl extension
C++
1
star
38

UGit

CMake
1
star
39

OSG_Exercise

C++
1
star
40

UContainer

Ubpa Container
C++
1
star
41

UEngine

Ubpa Engine
C++
1
star
42

UThreadPool

Ubpa Thread Pool
C++
1
star
43

LearnCompiler

Learn Compiler
ANTLR
1
star
44

SecretCode

Encrypt / Decode codes by DES and Base64
C++
1
star
45

UVisitor

Visitor
C++
1
star
46

LearnQt

C++
1
star