rttrorg / rttr

C++ Reflection Library
https://www.rttr.org
MIT License
3.11k stars 429 forks source link

Is there a way to automatically set all the properties for a class? #340

Closed dame-time closed 1 year ago

dame-time commented 2 years ago

I'm trying to register multiple components and their fields in order to create a sort of reflection. For now, I'm handling the automatic registration of a component in such a way:

            void registerComponent() {
                rttr::registration::class_<decltype(*this)>(this->toString());
                rttr::type classType = rttr::type::get_by_name(this->toString());
            }

Tho I want to be able to automatically assign to the class registration all the fields, is this possible?

Chaphlagical commented 1 year ago

You can use some tools(like anltr, clang, etc) to parse the C++ source code and gather type info for registeration.

dame-time commented 1 year ago

I achieved my goal by simply accepting that we don't have reflection in C++ for introspection or intercession! Though I managed to do a kind of reflective introspection with this excellent library, making serialization kind of possible.