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

Optimised and simple reflection library for games

License

NotificationsYou must be signed in to change notification settings

vertver/grr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image

Current status of GRR

GRR is avery experimental library. You can use it in your project, but it is at your own risk (I can't guarantee that there are no bugs in this library). However, if you've found a bug and want to contribute, you are welcome to do so. Create an issue on GitHub or PR if you have already developed a fix or feature.


How does it work?

GRR uses multiple techniques to obtain information about structure on compilation time.The first reflection method was described byAnton Polukhin atMeeting C++ 2018. This reflection method works through C++14 hack, which allows to represent a structure asstd::tuple, which allows to access fields of the structure through indexes. The limitation of this method is the lack of field name information and the ability to work only with C-like structure (or otherwise PODs).

The second method was implemented bycbeck88 invisit_struct library, and it works from C++11 and higher. This method of reflection has the same advantages as the first one, with the only difference that we have access to the names of the structure and its fields. The disadvantage of this method is that it is necessary to create the structure through special macros or use a specialVISITABLE_STRUCT macro to define all the fields of the structure.

The goal of GRR is to combine these methods and use their advantages. In addition, GRR has its own analogue of RTTI, which is compatible with compile-time types and is portable between compilers because it uses a limited representation of the type name through thenameof library.


Examples

First of all, very basic example of how to use this library:

#include<grr/grr.hpp>structTestStruct{int test_1;float test_2;    std::string test_3;};intmain(){    std::error_code err;auto context =grr::make_context(err);if (err) {        std::cout << err.message();return -1;    }    grr::add_type<TestStruct>(context);    TestStruct test = {};    test.test_1 =1;       test.test_2 =2.0f;    test.test_3 ="test";grr::visit(context, test, err, [](constauto& field,constchar* name){using CleanType = grr::clean_type<decltype(field)>;ifconstexpr (std::is_same_v<CleanType, std::string>) {            std::cout << name <<":" << field;        }elseifconstexpr (std::is_integral_v<CleanType>) {            std::cout << name <<":" <<std::to_string(field);        }    });return0;}

Other samples will be available in the future atsamples directory.

Requirements and Limitations

GRR requires C++20 support and GRR can only be used only with C-like structures (or PODs) and can't reflect methods of structure.

Acknowledgments

This project uses several C++ libraries as dependencies:PFRvisit_structnameof

License

GRR is licensed under Boost Software License, Version 1.0. Check theLICENSE file for more information.


[8]ページ先頭

©2009-2025 Movatter.jp