开源软件名称(OpenSource Name):rttrorg/rttr开源软件地址(OpenSource Url):https://github.com/rttrorg/rttr开源编程语言(OpenSource Language):C++ 94.1%开源软件介绍(OpenSource Introduction):!New Release - 0.9.6!RTTR
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 UseManual 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 memberstype 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 typestype 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 propertiesMyStruct 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
PortabilityTested and compiled with:
LicenseRTTR 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. InstallationThe 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. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论