├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── InitUCMake.cmake └── Platform.cmake ├── config └── Config.cmake.in ├── doc ├── change_log.md ├── introduction_en_US.md ├── introduction_zh_CN.md ├── manual_zh_CN.md ├── overview_zh_CN.md ├── todo.md └── type_convert.md ├── include ├── UDRefl │ ├── Basic.hpp │ ├── FieldPtr.hpp │ ├── IDRegistry.hpp │ ├── Info.hpp │ ├── MethodPtr.hpp │ ├── Object.hpp │ ├── ReflMngr.hpp │ ├── UDRefl.hpp │ ├── Util.hpp │ ├── attrs │ │ ├── ContainerType.hpp │ │ └── details │ │ │ └── ContainerType.inl │ ├── config.hpp │ ├── details │ │ ├── IDRegistry.inl │ │ ├── Object.inl │ │ ├── ReflMngr.inl │ │ └── Util.inl │ └── ranges │ │ ├── FieldRange.hpp │ │ ├── MethodRange.hpp │ │ ├── ObjectTree.hpp │ │ ├── VarRange.hpp │ │ └── common.hpp └── UDRefl_ext │ └── Bootstrap.h └── src ├── core ├── CMakeLists.txt ├── FieldPtr.cpp ├── IDRegistry.cpp ├── InvokeUtil.cpp ├── InvokeUtil.hpp ├── MethodPtr.cpp ├── Object.cpp ├── ReflMngr.cpp ├── ReflMngrInitUtil │ ├── ReflMngrInitUtil.hpp │ ├── ReflMngrInitUtil_0.cpp │ ├── ReflMngrInitUtil_1.cpp │ ├── ReflMngrInitUtil_2.cpp │ ├── ReflMngrInitUtil_3.cpp │ ├── ReflMngrInitUtil_4.cpp │ ├── ReflMngrInitUtil_5.cpp │ ├── ReflMngrInitUtil_6.cpp │ └── ReflMngrInitUtil_7.cpp └── ranges │ ├── FieldRange.cpp │ ├── MethodRange.cpp │ ├── ObjectTree.cpp │ └── VarRange.cpp ├── ext └── Bootstrap │ ├── Bootstrap.cpp │ ├── Bootstrap_helper.hpp │ ├── Bootstrap_helper_basic.cpp │ ├── Bootstrap_helper_info_0.cpp │ ├── Bootstrap_helper_info_1.cpp │ ├── Bootstrap_helper_info_2.cpp │ ├── Bootstrap_helper_info_3.cpp │ ├── Bootstrap_helper_info_4.cpp │ ├── Bootstrap_helper_object.cpp │ ├── Bootstrap_helper_ptr.cpp │ ├── Bootstrap_helper_ranges_derived.cpp │ ├── Bootstrap_helper_ranges_fieldrange.cpp │ ├── Bootstrap_helper_ranges_methodrange.cpp │ ├── Bootstrap_helper_ranges_objecttree.cpp │ ├── Bootstrap_helper_ranges_span_derived.cpp │ ├── Bootstrap_helper_ranges_varrange.cpp │ ├── Bootstrap_helper_reflmngr_0.cpp │ ├── Bootstrap_helper_reflmngr_1.cpp │ ├── Bootstrap_helper_reflmngr_2.cpp │ ├── Bootstrap_helper_registry.cpp │ ├── Bootstrap_helper_utemplate.cpp │ └── CMakeLists.txt └── test ├── 00_readme ├── CMakeLists.txt └── main.cpp ├── 01_basic ├── CMakeLists.txt └── main.cpp ├── 02_const_static ├── CMakeLists.txt └── main.cpp ├── 03_method ├── CMakeLists.txt └── main.cpp ├── 04_enum ├── CMakeLists.txt └── main.cpp ├── 05_overload ├── CMakeLists.txt └── main.cpp ├── 06_inheritance ├── CMakeLists.txt └── main.cpp ├── 07_virtual ├── CMakeLists.txt └── main.cpp ├── 08_attr ├── CMakeLists.txt └── main.cpp ├── 09_lifetime ├── CMakeLists.txt └── main.cpp ├── 10_dynamic ├── CMakeLists.txt └── main.cpp ├── 11_invoke ├── CMakeLists.txt └── main.cpp ├── 12_Meta ├── CMakeLists.txt └── main.cpp ├── 13_ref ├── CMakeLists.txt └── main.cpp ├── 14_pch ├── A.cpp ├── A.hpp ├── B.cpp ├── B.hpp ├── CMakeLists.txt └── main.cpp ├── 15_serializer ├── CMakeLists.txt ├── Vector.cpp ├── Vector.hpp └── main.cpp ├── 16_container ├── CMakeLists.txt └── main.cpp ├── 17_compatible ├── CMakeLists.txt └── main.cpp ├── 18_tuple ├── CMakeLists.txt └── main.cpp ├── 19_pointer ├── CMakeLists.txt └── main.cpp ├── 20_array ├── CMakeLists.txt └── main.cpp ├── 21_string ├── CMakeLists.txt └── main.cpp ├── 22_variant ├── CMakeLists.txt └── main.cpp ├── 23_optional ├── CMakeLists.txt └── main.cpp ├── 24_dd_type ├── CMakeLists.txt └── main.cpp ├── ext └── 00_bootstrap │ ├── CMakeLists.txt │ └── main.cpp ├── gtest ├── CMakeLists.txt └── basic.cpp └── issues └── 0007 ├── CMakeLists.txt └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | resources/ 2 | build/ 3 | vs_build/ 4 | lib/ 5 | .vs/ 6 | .vscode/ 7 | bin/ 8 | _deps/ 9 | 10 | *Config.h 11 | 12 | *.obj 13 | *.uscene 14 | 15 | *.bmp 16 | *.png 17 | *.jpg 18 | *.gif 19 | *.mp4 20 | *.pdf 21 | 22 | *.html 23 | 24 | *.rar 25 | *.zip 26 | 27 | *.doc 28 | *.docx 29 | *.ppt 30 | *.pptx 31 | 32 | *.filters 33 | *.vcxproj 34 | *.log 35 | *.sln 36 | *.user 37 | *.dll 38 | *.lib 39 | *.exe 40 | *.ilk 41 | *.pdb 42 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14 FATAL_ERROR) 2 | 3 | project(UDRefl VERSION 0.11.1) 4 | message(STATUS "[Project] ${PROJECT_NAME}") 5 | 6 | include(cmake/InitUCMake.cmake) 7 | Ubpa_InitUCMake(VERSION 0.6.4) 8 | 9 | Ubpa_InitProject() 10 | 11 | Ubpa_AddDep(UTemplate 0.7.2) 12 | Ubpa_AddDep(USmallFlat 0.2.4) 13 | 14 | include(cmake/Platform.cmake) 15 | 16 | option(Ubpa_UDRefl_Build_Shared "build shared library" OFF) 17 | option(Ubpa_UDRefl_Build_ext_Bootstrap "build ext Bootstrap" OFF) 18 | option(Ubpa_UDRefl_include_all_StdName "switch UBPA_UDREFL_INCLUDE_ALL_STD_NAME" OFF) 19 | 20 | if(Ubpa_BuildTest_UDRefl) 21 | find_package(GTest QUIET) 22 | if(GTest_FOUND) 23 | message(NOTICE "GTest Found") 24 | else() 25 | message(NOTICE "GTest not Found, so we ignore some targets depending on GTest") 26 | endif() 27 | endif() 28 | 29 | Ubpa_AddSubDirsRec(include) 30 | Ubpa_AddSubDirsRec(src) 31 | 32 | Ubpa_Export( 33 | TARGET 34 | DIRECTORIES 35 | "include" 36 | ) 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ubpa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ``` 2 | 3 | __ __ _______ .______ _______ _______ __ 4 | | | | | | \ | _ \ | ____|| ____|| | 5 | | | | | | .--. || |_) | | |__ | |__ | | 6 | | | | | | | | || / | __| | __| | | 7 | | `--' | | '--' || |\ \----.| |____ | | | `----. 8 | \______/ |_______/ | _| `._____||_______||__| |_______| 9 | 10 | 11 | ``` 12 | 13 | [![repo-size](https://img.shields.io/github/languages/code-size/Ubpa/UDRefl?style=flat)](https://github.com/Ubpa/UDRefl/archive/master.zip) [![tag](https://img.shields.io/github/v/tag/Ubpa/UDRefl)](https://github.com/Ubpa/UDRefl/tags) [![license](https://img.shields.io/github/license/Ubpa/UDRefl)](LICENSE) 14 | 15 | ⭐ Star us on GitHub — it helps! 16 | 17 | # UDRefl 18 | 19 | > **U**bpa **D**ynamic **R**eflection 20 | 21 | Extremely **fast** and **powerful** C++20 dynamic reflection library 22 | 23 | ## Documentaion [->](doc/) 24 | 25 | - [to-do](doc/todo.md) 26 | - [change log](doc/change_log.md) 27 | - manual (TODO) 28 | - overview 29 | - [中文](doc/overview_zh_CN.md) 30 | - introduction 31 | - [English](doc/introduction_en_US.md) 32 | - [中文](doc/introduction_zh_CN.md) 33 | 34 | ## How to Use 35 | 36 | > the example code is [here](src/test/00_readme/main.cpp), other examples is [here](https://github.com/Ubpa/UDRefl#other-example) 37 | 38 | Suppose you need to reflect `struct Vec` 39 | 40 | ```c++ 41 | struct Vec { 42 | float x; 43 | float y; 44 | float norm() const { 45 | return std::sqrt(x * x + y * y); 46 | } 47 | }; 48 | ``` 49 | 50 | ### Manual registration 51 | 52 | ```c++ 53 | Mngr.RegisterType(); 54 | Mngr.AddField<&Vec::x>("x"); 55 | Mngr.AddField<&Vec::y>("y"); 56 | Mngr.AddMethod<&Vec::norm>("norm"); 57 | ``` 58 | 59 | ### Iterate over members 60 | 61 | ```c++ 62 | for (auto&& [name, info] : FieldRange_of) 63 | std::cout << name.GetView() << std::endl; 64 | 65 | for (auto&& [name, info] : MethodRange_of) 66 | std::cout << name.GetView() << std::endl; 67 | ``` 68 | 69 | ### Constructing types 70 | 71 | ```c++ 72 | SharedObject v = Mngr.MakeShared(Type_of); 73 | std::cout << v.GetType().GetName() << std::endl; // prints "Vec" 74 | ``` 75 | 76 | ### Set/get variables 77 | 78 | ```c++ 79 | v.Var("x") = 3; 80 | v.Var("y") = 4; 81 | std::cout << "x: " << v.Var("x") << std::endl; 82 | ``` 83 | 84 | ### Invoke Methods 85 | 86 | ```c++ 87 | std::cout << "norm: " << v.Invoke("norm") << std::endl; 88 | ``` 89 | 90 | ### Iterate over variables 91 | 92 | ```c++ 93 | for (auto&& [name, var] : v.GetVars()) 94 | std::cout << name.GetView() << ": " << var << std::endl; 95 | ``` 96 | 97 | ### other example 98 | 99 | - [const & static](src/test/02_const_static/main.cpp) 100 | - [method](src/test/03_method/main.cpp) 101 | - [enum](src/test/04_enum/main.cpp) 102 | - [overload](src/test/05_overload/main.cpp) 103 | - [inheritance](src/test/06_inheritance/main.cpp) 104 | - [virtual inheritance](src/test/07_virtual/main.cpp) 105 | - [attr](src/test/08_attr/main.cpp) 106 | - [lifetime (ctor, dtor)](src/test/09_lifecycle/main.cpp) 107 | - [dynamic field](src/test/10_dynamic/main.cpp) 108 | - [invoke](src/test/11_invoke/main.cpp) 109 | - [meta function](src/test/12_Meta/main.cpp) 110 | - [reference](src/test/13_ref/main.cpp) 111 | - [serialize](src/test/15_serializer/main.cpp) 112 | - [container](src/test/16_container/main.cpp) 113 | - [compatible](src/test/17_compatible/main.cpp) 114 | - [tuple](src/test/18_tuple/main.cpp) 115 | - [pointer](src/test/19_pointer/main.cpp) 116 | - [array](src/test/20_array/main.cpp) 117 | - [string](src/test/21_string/main.cpp) 118 | - [variant](src/test/22_variant/main.cpp) 119 | - [optional](src/test/23_optional/main.cpp) 120 | - [bootstrap](src/test/ext/00_bootstrap/main.cpp) 121 | - [[data-driven] `RegisterType`](src/test/24_dd_type/main.cpp) 122 | 123 | ## Features 124 | 125 | - global fields, methods or enums 126 | - classes with **single**-, **multiple**- and **virtual**-inheritance 127 | - constructors (arbitrary argument count) and destructors 128 | - methods (**virtual**, **abstract**, **overloaded**, arbitrary argument count) : you can pass arguments by a buffer (on stack or heap) 129 | - ability to invoke methods of classes from any arbitrary class level 130 | - argument type auto **convertion** when invoking method 131 | - no header pollution: the reflection information is created in the cpp file to minimize compile time when modifying the data 132 | - working with custom types without the need of having the declaration of the type available at compile time (useful for plugins) 133 | - possibility to add additional **attribute** to all reflection objects 134 | - reference 135 | - pointer, array 136 | - standard container, iterator 137 | - **meta** function 138 | - operations: `operator +`, `operator-`, ... 139 | - container: `begin`, `end`, `empty`, `size`, ... 140 | - bootstrap 141 | - **no** macro usage 142 | - **no** rtti required 143 | - **no** exceptions (this feature come with cost and is also regularly disabled on consoles) 144 | - **no** external compiler or tool needed, only standard ISO C++20 145 | 146 | ## Compiler compatibility 147 | 148 | - Clang/LLVM >= 10.0 149 | - GCC >= 10.0 150 | - MSVC >= 1926 151 | 152 | > Tested platforms: 153 | > 154 | > - Windows 10: VS2019 16.8.5 155 | > 156 | > - Ubuntu 20: GCC 10.2, Clang 11.0 157 | > 158 | > - MacOS 11.0 : GCC 10.2 159 | > 160 | > > AppleClang 12 and Clang 11 is not supported 161 | 162 | ## Licensing 163 | 164 | You can copy and paste the license summary from below. 165 | 166 | ``` 167 | MIT License 168 | 169 | Copyright (c) 2020 Ubpa 170 | 171 | Permission is hereby granted, free of charge, to any person obtaining a copy 172 | of this software and associated documentation files (the "Software"), to deal 173 | in the Software without restriction, including without limitation the rights 174 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 175 | copies of the Software, and to permit persons to whom the Software is 176 | furnished to do so, subject to the following conditions: 177 | 178 | The above copyright notice and this permission notice shall be included in all 179 | copies or substantial portions of the Software. 180 | 181 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 182 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 183 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 184 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 185 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 186 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 187 | SOFTWARE. 188 | ``` 189 | 190 | -------------------------------------------------------------------------------- /cmake/InitUCMake.cmake: -------------------------------------------------------------------------------- 1 | macro(Ubpa_InitUCMake) 2 | cmake_parse_arguments( 3 | "ARG" # prefix 4 | "" # # TRUE / FALSE 5 | "VERSION" # 6 | "" # # list 7 | ${ARGN} 8 | ) 9 | # 结果为 ARG_* 10 | # - ARG_