Zurück zum Ranking

rttrorg/rttr

C++rttr.org

C++ Reflection Library

reflectionintrospectionserializationpropertiesc-plus-pluscplusplus-11cmakelibrary
Sterne-Wachstum
Sterne
3.5k
Forks
485
Wochenwachstum
Issues
124
1k2k3k
Dez. 2015Juni 2019Jan. 2023Juli 2026
README

Version Travis status Appveyor status Coverage Status CII Best Practices Codacy Badge Documentation License Donate

!New Release - 0.9.6!

RTTR

C++ Reflection Library

RTTR stands for Run Time Type Reflection. It describes the ability of a computer program to introspect and modify an object at runtime. It is also the name of the library itself, which is written in C++ and released as open source library. You can find more information on: www.rttr.org


How to Use

Manual registration

#include <rttr/registration>
using namespace rttr;

struct MyStruct { MyStruct() {}; void func(double) {}; int data; };

RTTR_REGISTRATION
{
    registration::class_<MyStruct>("MyStruct")
         .constructor<>()
         .property("data", &MyStruct::data)
         .method("func", &MyStruct::func);
}

Iterate over members

type t = type::get<MyStruct>();
for (auto& prop : t.get_properties())
    std::cout << "name: " << prop.get_name();

for (auto& meth : t.get_methods())
    std::cout << "name: " << meth.get_name();

Constructing types

type t = type::get_by_name("MyStruct");
variant var = t.create();    // will invoke the previously registered ctor

constructor ctor = t.get_constructor();  // 2nd way with the constructor class
var = ctor.invoke();
std::cout << var.get_type().get_name(); // prints 'MyStruct'

Set/get properties

MyStruct obj;

property prop = type::get(obj).get_property("data");
prop.set_value(obj, 23);

variant var_prop = prop.get_value(obj);
std::cout << var_prop.to_int(); // prints '23'

Invoke Methods:

MyStruct obj;

method meth = type::get(obj).get_method("func");
meth.invoke(obj, 42.0);

variant var = type::get(obj).create();
meth.invoke(var, 42.0);

Features

  • reflect constructors, methods, data member or enums
  • classes; with single-, multiple- and virtual-inheritance
  • constructors (arbitrary argument count)
  • methods (virtual, abstract, overloaded, arbitrary argument count)
  • arrays (incl. raw-arrays; arbitrary dimension count)
  • ability to invoke properties and methods of classes from any arbitrary class level
  • 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 metadata to all reflection objects
  • possibility to add default arguments to methods or constructors
  • adjust registration behaviour through policies
  • minimal macro usage
  • no additional 3rd party dependencies are needed
  • no rtti required; contains a faster and across shared libraries working replacement
  • no exceptions (this feature come with cost and is also regularly disabled on consoles)
  • no external compiler or tool needed, only standard ISO C++11

Portability

Tested and compiled with:

  • Microsoft Visual Studio 2015 & 2017 (2013 support till version 0.9.6)
  • GCC 4.8.1
  • Clang 3.7
  • MinGW 4.8.2

License

RTTR is released under the terms of the MIT license, so it is free to use in your free or commercial projects.

Copyright (c) 2014 - 2018 Axel Menzel info@rttr.org

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.

Installation

The installation guide can be found here.

Get Started:

Take a look at the documentation or start with the tutorial.

Donation:

When you use RTTR and you would like to say thank you for its development, I am happy to receive any donation.

paypal

Ähnliche Repositories
skypjack/entt

Gaming meets modern C++ - a fast and reliable entity component system (ECS) and much more

C++MIT Licenseheader-onlymodern-cpp
github.com/skypjack/entt/wiki
12.9k1.1k
pry/pry

A runtime developer console and IRB alternative with powerful introspection capabilities.

RubyRubyGemsOtherirbconsole
pry.github.io
6.8k609
ldqk/Masuit.Tools

全龄段友好的C#万能工具库,码数吐司库,包含一些常用的操作类,大都是静态类,加密解密,反射操作,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展、Excel导出等常用封装。诸多功能集一身,代码量不到2MB!

C#MIT Licenselambdareflection
masuit.tools
6.2k1.3k
Neargye/magic_enum

Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code

C++MIT Licensecpluspluscplusplus-17
6.1k561
microsoft/reflect-metadata

Prototype for a Metadata Reflection API for ECMAScript

TypeScriptnpmApache License 2.0metadatadecorator-metadata
rbuckton.github.io/reflect-metadata
3.4k189
rbuckton/reflect-metadata

Prototype for a Metadata Reflection API for ECMAScript

TypeScriptnpmApache License 2.0metadatadecorator-metadata
rbuckton.github.io/reflect-metadata
3.2k184
tiann/FreeReflection

A library that lets you use reflection without any restriction above Android P

C++MIT Licenseandroidreflection
3.2k565
stephenberry/glaze

Extremely fast, in memory, serialization, reflection, and RPC library for C++. JSON, BEVE, BSON, CBOR, CSV, JSONB, MessagePack, TOML, YAML, EETF

C++MIT Licenseapibinary
stephenberry.github.io/glaze/
2.9k256
doctrine/reflection

The Doctrine Reflection project is a simple library used by the various Doctrine projects which adds some additional functionality on top of the reflection API that comes with PHP. It allows you to get the reflection information about classes, methods and properties statically.

PHPPackagistMIT Licensereflection
doctrine-project.org/projects/reflection.html
2.9k18
symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

PHPPackagistMIT Licensephpsymfony
symfony.com/property-access
2.8k26
facet-rs/facet

Rust reflection, serialization, deserialization, pretty printing, etc. — the last proc macro you should need

Rustcrates.ioApache License 2.0deserializationrust
facet.rs
2.6k124
Neargye/nameof

Nameof operator for modern C++, simply obtain the name of a variable, type, function, macro, and enum

C++MIT Licensecpluspluscplusplus-17
2.3k127