Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

C++ Reflection Library

License

NotificationsYou must be signed in to change notification settings

rttrorg/rttr

Repository files navigation

VersionTravis statusAppveyor statusCoverage StatusCII Best PracticesCodacy BadgeDocumentationLicenseDonate

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>usingnamespacerttr;structMyStruct { MyStruct() {};voidfunc(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 ctorconstructor ctor = t.get_constructor();// 2nd way with the constructor classvar = 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; withsingle-,multiple- andvirtual-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 additionalmetadata to all reflection objects
  • possibility to adddefault arguments to methods or constructors
  • adjust registration behaviour throughpolicies
  • 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 theMIT license,so it is free to use in your free or commercial projects.

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

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

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

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE.

Installation

The installation guide can be foundhere.

Get Started:

Take a look at thedocumentation or start with thetutorial.

Donation:

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

paypal


[8]ページ先頭

©2009-2025 Movatter.jp